From: Rafael Kitover Date: Sat, 29 Oct 2011 08:26:33 +0000 (-0400) Subject: fix some naming version checks X-Git-Tag: 0.07011~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fa7becae8a917861cd28833059ed65109f20221;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix some naming version checks Previous code didn't take into account that naming->{key} can be set to something other than vX. Fix a call to ->_to_identifier in the monikerization code. t/23dumpmore.t passes again. --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 3b74da4..b95ed42 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -970,7 +970,7 @@ sub new { if ($self->naming) { foreach my $key (qw/relationships monikers column_accessors/) { - $self->naming->{$key} = $CURRENT_V if $self->naming->{$key} eq 'current'; + $self->naming->{$key} = $CURRENT_V if ($self->naming->{$key}||'') eq 'current'; } } $self->{naming} ||= {}; @@ -2347,10 +2347,25 @@ sub tables { return values %{$self->_tables}; } +sub _get_naming_v { + my ($self, $naming_key) = @_; + + my $v; + + if (($self->naming->{$naming_key}||'') =~ /^v(\d+)\z/) { + $v = $1; + } + else { + ($v) = $CURRENT_V =~ /^v(\d+)\z/; + } + + return $v; +} + sub _to_identifier { my ($self, $naming_key, $name, $sep_char) = @_; - my ($v) = ($self->naming->{$naming_key}||$CURRENT_V) =~ /^v(\d+)\z/; + my $v = $self->_get_naming_v($naming_key); my $to_identifier = $self->naming->{force_ascii} ? \&String::ToIdentifier::EN::to_identifier @@ -2363,7 +2378,7 @@ sub _to_identifier { sub _default_table2moniker { my ($self, $table) = @_; - my ($v) = ($self->naming->{monikers}||$CURRENT_V) =~ /^v(\d+)\z/; + my $v = $self->_get_naming_v('monikers'); my @name_parts = map $table->$_, @{ $self->moniker_parts }; @@ -2375,7 +2390,7 @@ sub _default_table2moniker { my $part = $name_parts[$i]; if ($i != $name_idx || $v >= 8) { - $part = $self->_to_identifier->('monikers', $part, '_'); + $part = $self->_to_identifier('monikers', $part, '_'); } if ($i == $name_idx && $v == 5) {