From: Rafael Kitover Date: Sun, 23 Oct 2011 01:39:35 +0000 (-0400) Subject: fully implement naming=v8 and force_ascii X-Git-Tag: 0.07011~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=df35916c8f26ed90aaec76305935d13507348b17;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fully implement naming=v8 and force_ascii Use String::ToIdentifier::EN or ::Unicode on column accessors and relationship accessors as well as monikers, for the experimental v8 naming mode. --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 75165bf..0af7c1d 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -189,8 +189,8 @@ How to name column accessors in Result classes. =item force_ascii For L mode and later, uses L instead of -L to force monikers and other identifiers -such as relationship names to ASCII. +L to force monikers and other identifiers to +ASCII. =back @@ -243,9 +243,10 @@ breaking any of your code. The default mode is L, to get L mode, you have to specify it in L explictly until C<0.08> comes out. -L are created using L or -L if L is set; this is only significant -for table names with non-C<\w> characters such as C<.>. +L and L are created using +L or L if +L is set; this is only significant for names with non-C<\w> +characters such as C<.>. For relationships, belongs_to accessors are made from column names by stripping postfixes other than C<_id> as well, just C, C<_?ref>, C<_?cd>, C<_?code> @@ -2164,8 +2165,10 @@ sub _run_user_map { sub _default_column_accessor_name { my ( $self, $column_name ) = @_; - my $accessor_name = $column_name; - $accessor_name =~ s/\W+/_/g; + my $accessor_name = $self->_to_identifier('column_accessors', $column_name, '_'); + + $accessor_name =~ s/\W+/_/g; # only if naming < v8, otherwise to_identifier + # takes care of it if ((($self->naming->{column_accessors}||'') =~ /(\d+)/ && $1 < 7) || (not $self->preserve_case)) { # older naming just lc'd the col accessor and that's all. @@ -2324,6 +2327,18 @@ sub tables { return values %{$self->_tables}; } +sub _to_identifier { + my ($self, $naming_key, $name, $sep_char) = @_; + + my ($v) = ($self->naming->{$naming_key}||$CURRENT_V) =~ /^v(\d+)\z/; + + my $to_identifier = $self->naming->{force_ascii} ? + \&String::ToIdentifier::EN::to_identifier + : \&String::ToIdentifier::EN::Unicode::to_identifier; + + return $v >= 8 ? $to_identifier->($name, $sep_char) : $name; +} + # Make a moniker from a table sub _default_table2moniker { my ($self, $table) = @_; @@ -2334,17 +2349,13 @@ sub _default_table2moniker { my $name_idx = firstidx { $_ eq 'name' } @{ $self->moniker_parts }; - my $to_identifier = $self->naming->{force_ascii} ? - \&String::ToIdentifier::EN::to_identifier - : \&String::ToIdentifier::EN::Unicode::to_identifier; - my @all_parts; foreach my $i (0 .. $#name_parts) { my $part = $name_parts[$i]; - if ($i != $name_idx || $v > 7) { - $part = $to_identifier->($part, '_'); + if ($i != $name_idx || $v >= 8) { + $part = $self->_to_identifier->('monikers', $part, '_'); } if ($i == $name_idx && $v == 5) { diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index f4d65b6..9d89f49 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -304,7 +304,9 @@ sub _remote_attrs { sub _sanitize_name { my ($self, $name) = @_; - $name =~ s/\W+/_/g; + $name = $self->loader->_to_identifier('relationships', $name, '_'); + + $name =~ s/\W+/_/g; # if naming >= 8 to_identifier takes care of it return $name; }