From: skaufman Date: Sun, 29 Jun 2014 02:33:27 +0000 (-0400) Subject: Better (and much more precise) explanation of Moose/Moo subclassing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=15c43cfda0da684d4def3556e9dad76c6bdf56f3;p=dbsrgits%2FDBIx-Class-Historic.git Better (and much more precise) explanation of Moose/Moo subclassing --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 0e0aa63..5483b0b 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -207,10 +207,19 @@ See L on how DBIC can discover and automatically attach L-specific L classes. -=head3 ResultSet subclassing with Moose +=head3 ResultSet subclassing with Moose and similar constructor-providers -If you want to make your custom ResultSet classes with L, use a template -similar to: +Using L or L in your ResultSet classes is usually overkill, but +if your ResultSets contain a lot of business logic (e.g. C, +C, etc) or if you just prefer to organize your code with Moo(se) +roles you may find it useful. + +If you want to build your custom ResultSet classes with L, you need +to use the following template in order to interface the L-provided +L, +with the L. The +L is necessary due to the +unusual signature of the DBIC constructor C<< ->new($source, \%args) >>. package MyApp::Schema::ResultSet::User; @@ -227,12 +236,24 @@ similar to: 1; The L is necessary so that the L constructor does not -clash with the regular ResultSet constructor. Alternatively, you can use: +overwrite the DBIC constructor. Alternatively, you can skip +L and instead do: __PACKAGE__->meta->make_immutable(inline_constructor => 0); -The L is necessary because the -signature of the ResultSet C is C<< ->new($source, \%args) >>. +Writing custom ResultSet classes with L, is similar, although Moo doesn't +require an equivalent to MooseX::NonMoose since that's built in to Moo. + + use Moo; + extends 'DBIx::Class::ResultSet'; + + sub BUILDARGS { $_[2] } + + sub FOREIGNBUILDARGS { $_[2] } + + ...your code... + + 1; =head1 METHODS