From: Rafael Kitover Date: Tue, 11 May 2010 22:05:06 +0000 (-0400) Subject: handle digits when splitting by case transition X-Git-Tag: 0.07000~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3ea13a83557a591d55a5cf1dc5081d2e0679f38;p=dbsrgits%2FDBIx-Class-Schema-Loader.git handle digits when splitting by case transition --- diff --git a/Makefile.PL b/Makefile.PL index 80264a4..36bd0cc 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -32,6 +32,7 @@ requires 'namespace::autoclean' => 0; requires 'Data::Dumper::Concise' => '1.200'; requires 'Scope::Guard' => 0; requires 'List::MoreUtils' => 0; +requires 'Exporter' => '5.63'; install_script 'script/dbicdump'; diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 8ec3e7f..659017b 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -20,6 +20,7 @@ use Class::Inspector (); use Data::Dumper::Concise; use Scalar::Util 'looks_like_number'; use File::Slurp 'slurp'; +use DBIx::Class::Schema::Loader::Constants 'BY_CASE_TRANSITION'; require DBIx::Class; our $VERSION = '0.07000'; @@ -1482,7 +1483,7 @@ sub _resolve_col_accessor_collisions { sub _make_column_accessor_name { my ($self, $column_name) = @_; - return join '_', map lc, split /(?<=[[:lower:]])[\W_]*(?=[[:upper:]])|[\W_]+/, $column_name; + return join '_', map lc, split BY_CASE_TRANSITION, $column_name; } # Set up metadata (cols, pks, etc) @@ -1601,7 +1602,7 @@ sub _default_table2moniker { return join '', map ucfirst, split /\W+/, $inflected; } - my @words = map lc, split /(?<=[[:lower:]])[\W_]*(?=[[:upper:]])|[\W_]+/, $table; + my @words = map lc, split BY_CASE_TRANSITION, $table; my $as_phrase = join ' ', @words; my $inflected = Lingua::EN::Inflect::Phrase::to_S($as_phrase); diff --git a/lib/DBIx/Class/Schema/Loader/Constants.pm b/lib/DBIx/Class/Schema/Loader/Constants.pm new file mode 100644 index 0000000..a1d9af2 --- /dev/null +++ b/lib/DBIx/Class/Schema/Loader/Constants.pm @@ -0,0 +1,13 @@ +package # hide from PAUSE + DBIx::Class::Schema::Loader::Constants; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT_OK = qw/BY_CASE_TRANSITION/; + +use constant BY_CASE_TRANSITION => + qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/; + +1; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 7611f75..7847c77 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -5,6 +5,7 @@ use warnings; use Class::C3; use Carp::Clan qw/^DBIx::Class/; use Lingua::EN::Inflect::Phrase (); +use DBIx::Class::Schema::Loader::Constants 'BY_CASE_TRANSITION'; our $VERSION = '0.07000'; @@ -215,7 +216,7 @@ sub _remote_attrs { sub _normalize_name { my ($self, $name) = @_; - my @words = split /(?<=[[:lower:]])[\W_]*(?=[[:upper:]])|[\W_]+/, $name; + my @words = split BY_CASE_TRANSITION, $name; return join '_', map lc, @words; }