I am using CGI::Application on mod_perl with DBIx::Class and I'd like to have something like new define a new dbic schema on instantiation. So far I haven't been able to get it to work. The closest thing I have come to is a superclass that has a connect() method that returns a new object, but I would rather it be already be connected and instantiated.
I would really appreciate any thoughts at all.
Thanks!
Note: Ok, so obviously no help yet, but, in the meantime I made an accessor that lazily instantiates the DBIx::Class, so that might be a little bit better. Check it:
sub schema {
my $self = shift;
unless ($self->{schema}) {
$self->{schema} = ACD::Model->connect(@{$self->cfg->{$ENV{MODE}}->{connect_params}});
}
return $self->{schema};
}
and then of course to use it you'd do something like:
$self->schema->resultset('Foo')->find(1234);
I don't have a single answer, but http://lists.scsys.co.uk/pipermail/dbix-class/2006-June/001690.html is probably worth a read, so you understand how DBIC manages connections.