[Dbix-class] Create Components that operate on ResultSets
Matt S Trout
dbix-class at trout.me.uk
Fri Oct 20 23:48:50 CEST 2006
John Napiorkowski wrote:
> Hi,
>
> I have a generic resultset class that is not at all
> specific to a particular table. I use it for getting
> query parameters and filtering a resultset by page
> number, max results and so forth. Right now I load it
> in each Schema that uses it like so:
>
> __PACKAGE__->resultset_class('DBIx::Class::ResultSetByQuery');
>
> But I'm trying to figure out a way to include it in
> all my Schemas by default. All my Schemas inherit
> from a base.pm schema for loading components, but if I
> put the __PACKAGE__->resultset_class in that I get the
> following error:
>
> Can't locate object method "result_source_instance"
> via package "membership::Schema::base" at
> /usr/lib/perl5/site_perl/5.8.5/DBIx/Class/ResultSourceProxy.pm
> line 10.
>
> I'd like to make this a more generic component since I
> figure other people might be able to use it. But I
> can't find out how to make it a componant that loads
> via __PACKAGE__->load_components(). I can't seem to
> figure out how to create a resultset component. Can
> anyone point me toward a good example of this? Seems
> most of the components are oriented toward operating
> on rows.
Wrap sub table() to set the resultset_class afterwards?
Something like
sub table {
my $class = shift;
$class->next::method(@_);
my $source = $class->result_source_instance;
if ($source->resultset_class eq 'DBIx::Class::ResultSet') {
$source->resultset_class('My::Custom::ResultSet');
}
}
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list