[Dbix-class] How to inject more then one ResultSetClass in one ResultSet?

Jonas Alves jonas.alves at gmail.com
Tue Oct 30 12:17:12 GMT 2007


Hi,

I want my dbic components to be able to extend the ResultSet by adding
base classes when they are loaded.

For example if I have the following packages defined:

package MyDBIC::ResultSet::Foo;
use base qw/DBIx::Class::ResultSet/;

sub foo { warn "foo\n" }
1;

package MyDBIC::ResultSet::Bar;
use base qw/DBIx::Class::ResultSet/;

sub bar { warn "bar\n" }
1;

package MyDBIC::Foo;
use base qw/DBIx::Class/;
# add MyDBIC::ResultSet::Foo to @ResultSetClass::ISA
1;

package MyDBIC::Bar;
use base qw/DBIx::Class/;
# add MyDBIC::ResultSet::Bar to @ResultSetClass::ISA
1;

And then I do this:

# Schema/User.pm
package Schema::User;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/ +MyDBIC::Foo +MyDBIC::Bar Core /);

1;

# user.pl
my $schema = Schema->connect;
$schema->resultset('User')->foo;
$schema->resultset('User')->bar;

How do I make it work? What I want to know is if there is an easy way
to Inject the resultsets in the current ResultSet class.

Thanks,
-- 
Jonas



More information about the DBIx-Class mailing list