From: Rafael Kitover Date: Tue, 16 Mar 2010 16:37:04 +0000 (-0400) Subject: better inflection using Lingua::EN::Inflect::Phrase X-Git-Tag: 0.06000~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39b22ca9783c9799ebdf636c34e835709b228234;p=dbsrgits%2FDBIx-Class-Schema-Loader.git better inflection using Lingua::EN::Inflect::Phrase --- diff --git a/Changes b/Changes index ec5ecad..4ed0395 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - better inflection using Lingua::EN::Inflect::Phrase - cascade_delete and cascade_copy are turned off for has_many/might_have by default, and belongs_to has on_delete => 'CASCADE' and on_update => 'CASCADE' by default, overridable via relationship_attrs diff --git a/Makefile.PL b/Makefile.PL index 3c58ba1..80264a4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,6 +16,7 @@ requires 'File::Spec' => 0; requires 'Scalar::Util' => 0; requires 'Data::Dump' => '1.06'; requires 'Lingua::EN::Inflect::Number' => '1.1'; +requires 'Lingua::EN::Inflect::Phrase' => '0.02'; requires 'Text::Balanced' => 0; requires 'Digest::MD5' => '2.36'; requires 'Class::Accessor::Grouped' => '0.09002'; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 359c9a7..cdeea7f 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::Number (); +use Lingua::EN::Inflect::Phrase (); our $VERSION = '0.05003'; @@ -138,7 +139,7 @@ sub _to_PL { my ($self, $name) = @_; $name =~ s/_/ /g; - my $plural = Lingua::EN::Inflect::Number::to_PL($name); + my $plural = Lingua::EN::Inflect::Phrase::to_PL($name); $plural =~ s/ /_/g; return $plural; @@ -153,7 +154,11 @@ sub _old_to_PL { sub _to_S { my ($self, $name) = @_; - return Lingua::EN::Inflect::Number::to_S($name); + $name =~ s/_/ /g; + my $singular = Lingua::EN::Inflect::Phrase::to_S($name); + $singular =~ s/ /_/g; + + return $singular; } sub _default_relationship_attrs { +{ diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm index cc2653c..4eebaf6 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm @@ -3,6 +3,7 @@ package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040; use strict; use warnings; use Class::C3; +use Lingua::EN::Inflect::Number (); use base 'DBIx::Class::Schema::Loader::RelBuilder'; @@ -14,6 +15,12 @@ sub _to_PL { return Lingua::EN::Inflect::Number::to_PL($name); } +sub _to_S { + my ($self, $name) = @_; + + return Lingua::EN::Inflect::Number::to_S($name); +} + sub _relnames_and_method { my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;