fix backcompat tests
Rafael Kitover [Sun, 24 Jul 2011 16:30:17 +0000 (12:30 -0400)]
Updates the RelBuilder classes to take into account that
->_inflect_singular and ->_inflect_plural return a list instead of a
scalar now.

lib/DBIx/Class/Schema/Loader/RelBuilder.pm
lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm
lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_05.pm

index 64d9366..7a48c73 100644 (file)
@@ -41,7 +41,7 @@ is module is not (yet) for external use.
 
 =head2 new
 
-Arguments: $base object
+Arguments: $loader object
 
 =head2 generate_code
 
@@ -100,7 +100,7 @@ arguments, like so:
 =cut
 
 __PACKAGE__->mk_group_accessors('simple', qw/
-    base
+    loader
     schema
     inflect_plural
     inflect_singular
@@ -112,7 +112,7 @@ __PACKAGE__->mk_group_accessors('simple', qw/
 /);
 
 sub new {
-    my ( $class, $base ) = @_;
+    my ($class, $loader) = @_;
 
     # from old POD about this constructor:
     # C<$schema_class> should be a schema class name, where the source
@@ -124,17 +124,17 @@ sub new {
     # are better documented in L<DBIx::Class::Schema::Loader::Base>.
 
     my $self = {
-        base               => $base,
-        schema             => $base->schema,
-        inflect_plural     => $base->inflect_plural,
-        inflect_singular   => $base->inflect_singular,
-        relationship_attrs => $base->relationship_attrs,
-        rel_collision_map  => $base->rel_collision_map,
-        rel_name_map       => $base->rel_name_map,
+        loader             => $loader,
+        schema             => $loader->schema,
+        inflect_plural     => $loader->inflect_plural,
+        inflect_singular   => $loader->inflect_singular,
+        relationship_attrs => $loader->relationship_attrs,
+        rel_collision_map  => $loader->rel_collision_map,
+        rel_name_map       => $loader->rel_name_map,
         _temp_classes      => [],
     };
 
-    weaken $self->{base}; #< don't leak
+    weaken $self->{loader}; #< don't leak
 
     bless $self => $class;
 
@@ -334,9 +334,9 @@ sub _resolve_relname_collision {
 
     return $relname if $relname eq 'id'; # this shouldn't happen, but just in case
 
-    my $table = $self->base->tables->{$moniker};
+    my $table = $self->loader->tables->{$moniker};
 
-    if ($self->base->_is_result_class_method($relname, $table)) {
+    if ($self->loader->_is_result_class_method($relname, $table)) {
         if (my $map = $self->rel_collision_map) {
             for my $re (keys %$map) {
                 if (my @matches = $relname =~ /$re/) {
@@ -346,7 +346,7 @@ sub _resolve_relname_collision {
         }
 
         my $new_relname = $relname;
-        while ($self->base->_is_result_class_method($new_relname, $table)) {
+        while ($self->loader->_is_result_class_method($new_relname, $table)) {
             $new_relname .= '_rel'
         }
 
@@ -642,7 +642,7 @@ sub _relnames_and_method {
     if ($counters->{$remote_moniker} > 1) {
         my $relationship_exists = 0;
 
-        if (-f (my $existing_remote_file = $self->base->get_dump_filename($remote_class))) {
+        if (-f (my $existing_remote_file = $self->loader->get_dump_filename($remote_class))) {
             my $class = "${remote_class}Temporary";
 
             if (not Class::Inspector->loaded($class)) {
index 287bdbf..6bb08cb 100644 (file)
@@ -19,7 +19,7 @@ sub _relnames_and_method {
     my $local_cols  = $rel->{local_columns};
 
     # for single-column case, set the remote relname to just the column name
-    my $remote_relname =
+    my ($remote_relname) =
         scalar keys %{$cond} == 1
             ? $self->_inflect_singular( values %$cond  )
             : $self->_inflect_singular( lc $remote_table );
@@ -30,9 +30,9 @@ sub _relnames_and_method {
     if ($counters->{$remote_moniker} > 1) {
         my $colnames = '_' . join( '_', @$local_cols );
         $remote_relname .= $colnames if keys %$cond > 1;
-        $local_relname = $self->_inflect_plural( lc($local_table) . $colnames );
+        ($local_relname) = $self->_inflect_plural( lc($local_table) . $colnames );
     } else {
-        $local_relname = $self->_inflect_plural(lc $local_table);
+        ($local_relname) = $self->_inflect_plural(lc $local_table);
     }
 
     return ( $local_relname, $remote_relname, 'has_many' );
index 4d388ae..fca23b4 100644 (file)
@@ -44,10 +44,10 @@ sub _relnames_and_method {
         $local_relname = lc($local_table) . $colnames;
 
         $local_relname_uninflected = $local_relname;
-        $local_relname = $self->_inflect_plural( $local_relname );
+        ($local_relname) = $self->_inflect_plural( $local_relname );
     } else {
         $local_relname_uninflected = lc $local_table;
-        $local_relname = $self->_inflect_plural(lc $local_table);
+        ($local_relname) = $self->_inflect_plural(lc $local_table);
     }
 
     my $remote_method = 'has_many';
@@ -57,7 +57,7 @@ sub _relnames_and_method {
     if ($self->_array_eq([ $local_source->primary_columns ], $local_cols) ||
             grep { $self->_array_eq($_->[1], $local_cols) } @$uniqs) {
         $remote_method = 'might_have';
-        $local_relname = $self->_inflect_singular($local_relname_uninflected);
+        ($local_relname) = $self->_inflect_singular($local_relname_uninflected);
     }
 
     return ( $local_relname, $remote_relname, $remote_method );