[Dbix-class] Problem overriding connection method from Schema module
Emmanuel Quevillon
tuco at pasteur.fr
Fri Aug 21 08:59:48 GMT 2009
Hi,
I encounter a problem using my Schema::MyAppDB.pm module, especially
outside Catalyst application.
What I've done, I've overridden my connection method to get some
more infos about the database, especially driver name.
Here is my Schema::MyAppDB.pm module:
package Schema::MyAppDB;
use strict;
use warnings;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes;
#Our specific method
__PACKAGE__->mk_group_accessors('simple' => qw/driver_name/);
sub connection {
my ($self, @rest) = @_;
$self->next::method(@rest);
$self->driver_name($self->handler()->{Driver}->{Name});
}
# You can replace this text with custom content, and it will be
preserved on regeneration
1;
Using this module as it is into my Catalyst application works just fine.
As soon as I want to use it outside Catalyst, in a perl script for
example, e.g. :
#!/usr/bin/perl
use strict;
use Schema::MyAppDB;
my $schema =
Schema::MyAppDB->connect('dib:Pg:dbname=test','test','pass');
my $a = $schema->resultset("Public");
....
I get the following error
Can't locate object method "resultset" via package "Pg" (perhaps you
forgot to load "Pg"?) at ./test.pl line 7.
To get it working properly, I have to comment the entire
'connection' method previously overridden in Schema::MyAppDB.pm module.
So is this behaviour normal? What should I do not to always
comment/uncomment my connection method?
Note: I get the overriding method connection from this Catalyst Manual
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/Cookbook.pod#Create_accessors_to_preload_static_data_once_per_server_instance
Thanks for any hint
Regards
--
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------
More information about the DBIx-Class
mailing list