passing all these positional arguments into the relbuilder is stupid. let's not.
Robert Buels [Sat, 14 Aug 2010 00:13:35 +0000 (17:13 -0700)]
lib/DBIx/Class/Schema/Loader/Base.pm
lib/DBIx/Class/Schema/Loader/RelBuilder.pm

index 42e2fa4..1219e91 100644 (file)
@@ -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 {
index a20fe16..06edf33 100644 (file)
@@ -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<DBIx::Class::Schema::Loader::Base>.
+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<DBIx::Class::Schema::Loader::Base>.
 
     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";
     }