From: Dagfinn Ilmari Mannsåker Date: Fri, 25 Apr 2008 22:54:54 +0000 (+0000) Subject: Singularise table monikers by default X-Git-Tag: 0.04999_06~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2227094704f3259c2a4450656d8dbd59ac40a08e;hp=b327622ba07a243c4b5e10b0b7dbd17c20d75b34;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Singularise table monikers by default --- diff --git a/Changes b/Changes index 2f1e9cd..cffb452 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader +0.04999_06 Not Yet Released + - Singularise table monikers by default + 0.04999_05 Mon Apr 14, 2008 - Fix limiting table list to the specified schema for DB2 - Default db_schema to the username for DB2 diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 201f8fa..2f25f1b 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -12,6 +12,7 @@ use POSIX qw//; use File::Spec qw//; use Cwd qw//; use Digest::MD5 qw//; +use Lingua::EN::Inflect::Number qw//; require DBIx::Class; our $VERSION = '0.04999_05'; @@ -706,7 +707,8 @@ sub _table2moniker { $moniker = $self->moniker_map->($table); } - $moniker ||= join '', map ucfirst, split /[\W_]+/, lc $table; + $moniker ||= join '', map ucfirst, split /[\W_]+/, + Lingua::EN::Inflect::Number::to_S(lc $table); return $moniker; } diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 93e6e24..c34f368 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -51,7 +51,7 @@ sub _monikerize { sub run_tests { my $self = shift; - plan tests => 3 + 2 * (131 + ($self->{extra}->{count} || 0)); + plan tests => 3 + 2 * (132 + ($self->{extra}->{count} || 0)); $self->create(); @@ -81,7 +81,7 @@ sub setup_schema { my $debug = ($self->{verbose} > 1) ? 1 : 0; my %loader_opts = ( - constraint => qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+$/i, + constraint => qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+s?$/i, relationships => 1, additional_classes => 'TestAdditional', additional_base_classes => 'TestAdditionalBase', @@ -140,8 +140,8 @@ sub test_schema { $classes->{$table_name} = $schema_class . q{::} . $source_name; } - my $moniker1 = $monikers->{loader_test1}; - my $class1 = $classes->{loader_test1}; + my $moniker1 = $monikers->{loader_test1s}; + my $class1 = $classes->{loader_test1s}; my $rsobj1 = $conn->resultset($moniker1); my $moniker2 = $monikers->{loader_test2}; @@ -175,6 +175,8 @@ sub test_schema { } ok($uniq1_test, "Unique constraint"); + is($moniker1, 'LoaderTest1', 'moniker singularisation'); + my %uniq2 = $class2->unique_constraints; my $uniq2_test = 0; foreach my $ucname (keys %uniq2) { @@ -668,16 +670,16 @@ sub create { my $make_auto_inc = $self->{auto_inc_cb} || sub {}; my @statements = ( qq{ - CREATE TABLE loader_test1 ( + CREATE TABLE loader_test1s ( id $self->{auto_inc_pk}, dat VARCHAR(32) NOT NULL UNIQUE ) $self->{innodb} }, - $make_auto_inc->(qw/loader_test1 id/), + $make_auto_inc->(qw/loader_test1s id/), - q{ INSERT INTO loader_test1 (dat) VALUES('foo') }, - q{ INSERT INTO loader_test1 (dat) VALUES('bar') }, - q{ INSERT INTO loader_test1 (dat) VALUES('baz') }, + q{ INSERT INTO loader_test1s (dat) VALUES('foo') }, + q{ INSERT INTO loader_test1s (dat) VALUES('bar') }, + q{ INSERT INTO loader_test1s (dat) VALUES('baz') }, qq{ CREATE TABLE loader_test2 ( @@ -1073,14 +1075,14 @@ sub drop_tables { my $self = shift; my @tables = qw/ - loader_test1 + loader_test1s loader_test2 LOADER_TEST23 LoAdEr_test24 /; my @tables_auto_inc = ( - [ qw/loader_test1 id/ ], + [ qw/loader_test1s id/ ], [ qw/loader_test2 id/ ], );