rename _relnames_and_methods to _relnames_and_method in RelBuilder
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / RelBuilder.pm
index de0e9e8..092ed5c 100644 (file)
@@ -6,7 +6,7 @@ use Class::C3;
 use Carp::Clan qw/^DBIx::Class/;
 use Lingua::EN::Inflect::Number ();
 
-our $VERSION = '0.05002';
+our $VERSION = '0.05003';
 
 =head1 NAME
 
@@ -100,6 +100,8 @@ sub new {
 sub _inflect_plural {
     my ($self, $relname) = @_;
 
+    return '' if !defined $relname || $relname eq '';
+
     if( ref $self->{inflect_plural} eq 'HASH' ) {
         return $self->{inflect_plural}->{$relname}
             if exists $self->{inflect_plural}->{$relname};
@@ -116,6 +118,8 @@ sub _inflect_plural {
 sub _inflect_singular {
     my ($self, $relname) = @_;
 
+    return '' if !defined $relname || $relname eq '';
+
     if( ref $self->{inflect_singular} eq 'HASH' ) {
         return $self->{inflect_singular}->{$relname}
             if exists $self->{inflect_singular}->{$relname};
@@ -224,7 +228,7 @@ sub generate_code {
         }
 
         my ( $local_relname, $remote_relname, $remote_method ) =
-            $self->_relnames_and_methods( $local_moniker, $rel, \%cond,  $uniqs, \%counters );
+            $self->_relnames_and_method( $local_moniker, $rel, \%cond,  $uniqs, \%counters );
 
         push(@{$all_code->{$local_class}},
             { method => 'belongs_to',
@@ -256,7 +260,7 @@ sub generate_code {
     return $all_code;
 }
 
-sub _relnames_and_methods {
+sub _relnames_and_method {
     my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
 
     my $remote_moniker = $rel->{remote_source};
@@ -270,20 +274,17 @@ sub _relnames_and_methods {
     # If more than one rel between this pair of tables, use the local
     # col names to distinguish
     my $local_relname;
+    my $old_multirel_name; #< TODO: remove me
     if ( $counters->{$remote_moniker} > 1) {
         my $colnames = q{_} . join(q{_}, @$local_cols);
         $remote_relname .= $colnames if keys %$cond > 1;
 
-        my $old_relname =       #< TODO: remove me after 0.05003 release
         $local_relname = lc($local_table) . $colnames;
-        my $stripped_id = $local_relname =~ s/_id$//; #< strip off any trailing _id
+        $local_relname =~ s/_id$//
+            #< TODO: remove me
+            and $old_multirel_name = $self->_inflect_plural( lc($local_table) . $colnames );
         $local_relname = $self->_inflect_plural( $local_relname );
 
-        # TODO: remove me after 0.05003 release
-        $old_relname = $self->_inflect_plural( $old_relname );
-        warn __PACKAGE__." $VERSION: warning, stripping trailing _id from ${remote_class} relation '$old_relname', renaming to '$local_relname'.  This behavior is new as of 0.05003.\n"
-            if $stripped_id;
-
     } else {
         $local_relname = $self->_inflect_plural(lc $local_table);
     }
@@ -296,8 +297,14 @@ sub _relnames_and_methods {
             grep { _array_eq($_->[1], $local_cols) } @$uniqs) {
         $remote_method = 'might_have';
         $local_relname = $self->_inflect_singular($local_relname);
+        #< TODO: remove me
+        $old_multirel_name = $self->_inflect_singular($old_multirel_name);
     }
 
+    # TODO: remove me after 0.05003 release
+    $old_multirel_name
+        and warn __PACKAGE__." $VERSION: warning, stripping trailing _id from ${remote_class} relation '$old_multirel_name', renaming to '$local_relname'.  This behavior is new as of 0.05003.\n";
+
     return ( $local_relname, $remote_relname, $remote_method );
 }