[Dbix-class] Creating custom ResultSet Class.

Christopher H. Laco claco at chrislaco.com
Fri Apr 27 13:47:59 GMT 2007


Oleg Pronin wrote:
> No, i can't use that. i cannot change user application. This will be just=
 a
> loadable component.
> =

> =

> 2007/4/27, Jess Robinson <castaway at desert-island.me.uk>:
>>
>>
>>
>>
>> On Fri, 27 Apr 2007, Oleg Pronin wrote:
>>
>> > Could you please give more details :)
>> >
>> > 2007/4/27, Jess Robinson <castaway at desert-island.me.uk>:
>> >>
>> >>
>> >>
>> >>
>> >>  On Thu, 26 Apr 2007, Oleg Pronin wrote:
>> >>
>> >> >  Hello!
>> >> >
>> >> >  I want to create custom resultset class that will allow caching (in
>> >> >  memcached) functionality.
>> >> >
>> >> >  For example,
>> >> > @users =3D $rs->search(undef, {order_by =3D> 'rating', rows =3D> 10,
>> memcache
>> >> =3D>
>> >> >  60});
>> >> >
>> >> >  This will give stored in memcached and automatically updated every
>> 60
>> >> >  seconds top10 users list.
>> >> >
>> >> >  To do that i need every resultsource to use my resultset class.
>> >> >  Cookbook says i've got to
>> >> >  $source->resultset_class('My::ResultSet::Class');
>> >> >  But i dont want to write it in every result source!
>> >> >
>> >> >  Is there a good way to set my custom resultset to all registered
>> result
>> >> >  sources?
>> >> >
>> >>
>> >>  Yes, its a perl feature called a "base class" ;)
>> >>
>> >>  Jess
>> >>
>>
>> package My::DBIC::Base;
>> use base 'DBIx::Class';
>>
>> __PACKAGE__->load_components('Core');
>> __PACKAGE__->table('');
>> __PACKAGE__->resultset_class('My::ResultSet');
>>
>> 1;
>>
>> ...
>>
>> package My::TableClass;
>> use base 'My::DBIC::Base';
>>
>> __PACKAGE__->table('mytable');
>>
>> 1;
>>
>> -- standard perl inheritance, nothing more exciting than that.
>>
>> Jess

foreach my $source ($schema->sources) {
    $source->resultset_class('YourResultSetClass');
};

That should work if you only want to alter the behavour of the current
schema, and you can't/don't want to alter the classes for all instances.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070427/4f=
eb82b0/signature.pgp


More information about the Dbix-class mailing list