[Dbix-class] Problem overriding connection method from Schema module

Byron Young Byron.Young at riverbed.com
Fri Aug 21 17:59:46 GMT 2009


Emmanuel Quevillon wrote on 2009-08-21:
> 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;
> 

Hey Emmanuel,

connection() must return the schema object (which will be returned by $self->next::method(@rest)).  In this case it will actually return the driver name string instead, which explains why the interpreter chokes when it tries to call the resultset() method on a string, as in your error below.

> 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.

The Catalyst cookbook section is incorrect - it would be great for you to supply a doc patch to the catalyst list so other people don't run into this as well.

Byron





More information about the DBIx-Class mailing list