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=01bed9ce7e414e27063236ca01f16522feee9dc5;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..359d692 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -207,10 +207,31 @@ 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 +you may find it useful if your ResultSets contain a lot of business logic +(e.g. C, C, etc) or if you just prefer to organize +your code via roles. + +In order to write custom ResultSet classes with L you need to use the +following template. The L is necessary due to the +unusual signature of the L C<< ->new($source, \%args) >>. + + use Moo; + extends 'DBIx::Class::ResultSet'; + sub BUILDARGS { $_[2] } # ::RS::new() expects my ($class, $rsrc, $args) = @_ + + ...your code... + + 1; + +If you want to build your custom ResultSet classes with L, you need +a similar, though a little more elaborate template in order to interface the +inlining of the L-provided +L, +with the DBIC one. package MyApp::Schema::ResultSet::User; @@ -218,7 +239,7 @@ similar to: use MooseX::NonMoose; extends 'DBIx::Class::ResultSet'; - sub BUILDARGS { $_[2] } + sub BUILDARGS { $_[2] } # ::RS::new() expects my ($class, $rsrc, $args) = @_ ...your code... @@ -227,13 +248,12 @@ similar to: 1; The L is necessary so that the L constructor does not -clash with the regular ResultSet constructor. Alternatively, you can use: +entirely overwrite the DBIC one (in contrast L does this automatically). +Alternatively, you can skip L and get by with just L +instead by doing: __PACKAGE__->meta->make_immutable(inline_constructor => 0); -The L is necessary because the -signature of the ResultSet C is C<< ->new($source, \%args) >>. - =head1 METHODS =head2 new