From: Robert Buels Date: Sat, 14 Aug 2010 00:13:35 +0000 (-0700) Subject: passing all these positional arguments into the relbuilder is stupid. let's not. X-Git-Tag: 0.07002~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c7b5f46aba56cb71d6e15ad4034c780bf01e809;p=dbsrgits%2FDBIx-Class-Schema-Loader.git passing all these positional arguments into the relbuilder is stupid. let's not. --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 42e2fa4..1219e91 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -981,38 +981,18 @@ sub _relbuilder { if ($self->naming->{relationships} eq 'v4') { require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040; return $self->{relbuilder} ||= - DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040->new( - $self->schema, - $self->inflect_plural, - $self->inflect_singular, - $self->relationship_attrs, - ); + DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040->new( $self ); } elsif ($self->naming->{relationships} eq 'v5') { require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05; - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05->new ( - $self->schema, - $self->inflect_plural, - $self->inflect_singular, - $self->relationship_attrs, - ); + return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05->new( $self ); } elsif ($self->naming->{relationships} eq 'v6') { require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06; - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06->new ( - $self->schema, - $self->inflect_plural, - $self->inflect_singular, - $self->relationship_attrs, - ); + return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06->new( $self ); } - return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new ( - $self->schema, - $self->inflect_plural, - $self->inflect_singular, - $self->relationship_attrs, - ); + return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new ( $self ); } sub _load_tables { diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index a20fe16..06edf33 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -26,15 +26,7 @@ is module is not (yet) for external use. =head2 new -Arguments: schema_class (scalar), inflect_plural, inflect_singular - -C<$schema_class> should be a schema class name, where the source -classes have already been set up and registered. Column info, primary -key, and unique constraints will be drawn from this schema for all -of the existing source monikers. - -Options inflect_plural and inflect_singular are optional, and are better documented -in L. +Arguments: $base object =head2 generate_code @@ -76,19 +68,32 @@ arguments, like so: =cut + sub new { - my ( $class, $schema, $inflect_pl, $inflect_singular, $rel_attrs ) = @_; + my ( $class, $base ) = @_; + + # from old POD about this constructor: + # C<$schema_class> should be a schema class name, where the source + # classes have already been set up and registered. Column info, + # primary key, and unique constraints will be drawn from this + # schema for all of the existing source monikers. + + # Options inflect_plural and inflect_singular are optional, and + # are better documented in L. my $self = { - schema => $schema, - inflect_plural => $inflect_pl, - inflect_singular => $inflect_singular, - relationship_attrs => $rel_attrs, + base => $base, + schema => $base->schema, + inflect_plural => $base->inflect_plural, + inflect_singular => $base->inflect_singular, + relationship_attrs => $base->relationship_attrs, }; + Scalar::Util::weaken $self->{base}; #< don't leak + # validate the relationship_attrs arg if( defined $self->{relationship_attrs} ) { - ref($self->{relationship_attrs}) eq 'HASH' + ref $self->{relationship_attrs} eq 'HASH' or croak "relationship_attrs must be a hashref"; }