Great!, now it works perfectly , but it is not like the docs on Factory::PerRequest. I can even comment out the '#use base 'Catalyst::Model::Factory::PerRequest'; line and it keeps working. Isn't it strange?
This is what I understand reading my code:
- The basic package config has empty values. But they must be present for the first load of the app, so Catalyst know what it is.
- The sub ACCEPT_CONTEXT return a new object from PWC::Schema every time this model is requested.
- So I am not instantiating anything else but this very class, with just one contextual variable that changes from each request.
Am I right? Is it safe?
package PWC::Model::MYDB;
use strict;
use warnings;
use base 'Catalyst::Model::DBIC::Schema';
#use base 'Catalyst::Model::Factory::PerRequest';
__PACKAGE__->config(
schema_class => 'PWC::Schema',
connect_info => {
dsn => '',
user => '',
password => '',
AutoCommit => q{1},
}
);
sub ACCEPT_CONTEXT {
my($self, $c) = @_;
my $db = $c->engine->env->{THEALIAS}; #From environment variable i
+n Fastcgi/Nginx
my $new = $self->meta->new_object(
schema_class => 'PWC::Schema',
connect_info => {
dsn => 'dbi:mysql:' . $db . ':the_host.com',
user => 'the_user',
password => 'the_password',
AutoCommit => q{1},
}
);
return $new;
}
1;
|