[Bast-commits] r8166 - in branches/DBIx-Class-Schema-Loader/back-compat: . lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Loader lib/DBIx/Class/Schema/Loader/RelBuilder/Compat

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Thu Dec 24 11:03:15 GMT 2009


Author: caelum
Date: 2009-12-24 11:03:15 +0000 (Thu, 24 Dec 2009)
New Revision: 8166

Removed:
   branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Compat/
Modified:
   branches/DBIx-Class-Schema-Loader/back-compat/TODO-BACKCOMPAT
   branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader.pm
   branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm
   branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm
Log:
implemented "naming" accessor, got rid of Loader/Compat/v0_040.pm

Modified: branches/DBIx-Class-Schema-Loader/back-compat/TODO-BACKCOMPAT
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/TODO-BACKCOMPAT	2009-12-24 09:24:08 UTC (rev 8165)
+++ branches/DBIx-Class-Schema-Loader/back-compat/TODO-BACKCOMPAT	2009-12-24 11:03:15 UTC (rev 8166)
@@ -13,9 +13,6 @@
 
 *** backcompat tests
 
-These are still failing:
-* t/backcompat/0.04006/23dumpmore.t
-
 Need a comprehensive backcompat.t
 
 *** Write ::Manual::UpgradingFrom0.04006 POD

Modified: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm	2009-12-24 09:24:08 UTC (rev 8165)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/Base.pm	2009-12-24 11:03:15 UTC (rev 8166)
@@ -49,6 +49,7 @@
                                 classes
                                 monikers
                                 dynamic
+                                naming
                              /);
 
 __PACKAGE__->mk_accessors(qw/
@@ -97,8 +98,22 @@
 
 The option also takes a hashref:
 
-    naming => { relationships => 'v5', results => 'v4' }
+    naming => { relationships => 'v5', monikers => 'v4' }
 
+The keys are:
+
+=over 4
+
+=item relationships
+
+How to name relationship accessors.
+
+=item monikers
+
+How to name Result classes.
+
+=back
+
 The values can be:
 
 =over 4
@@ -331,6 +346,14 @@
     $self->version_to_dump($DBIx::Class::Schema::Loader::VERSION);
     $self->schema_version_to_dump($DBIx::Class::Schema::Loader::VERSION);
 
+    if (not ref $self->naming && defined $self->naming) {
+        my $naming_ver = $self->naming;;
+        $self->{naming} = {
+            relationships => $naming_ver,
+            monikers => $naming_ver,
+        };
+    }
+
     $self->_check_back_compat;
 
     $self;
@@ -339,21 +362,14 @@
 sub _check_back_compat {
     my ($self) = @_;
 
-# dynamic schemas will always be in 0.04006 mode
+# dynamic schemas will always be in 0.04006 mode, unless overridden
     if ($self->dynamic) {
-        no strict 'refs';
-        my $class = ref $self || $self;
-        require DBIx::Class::Schema::Loader::Compat::v0_040;
+# just in case, though no one is likely to dump a dynamic schema
+        $self->schema_version_to_dump('0.04006');
 
-        @{"${class}::ISA"} = map {
-            $_ eq 'DBIx::Class::Schema::Loader::Base' ?
-                'DBIx::Class::Schema::Loader::Compat::v0_040' :
-                $_
-        } @{"${class}::ISA"};
+        $self->naming->{relationships} ||= 'v4';
+        $self->naming->{monikers}      ||= 'v4';
 
-        Class::C3::reinitialize;
-# just in case, though no one is likely to dump a dynamic schema
-        $self->schema_version_to_dump('0.04006');
         return;
     }
 
@@ -367,24 +383,16 @@
     while (<$fh>) {
         if (/^# Created by DBIx::Class::Schema::Loader v((\d+)\.(\d+))/) {
             my $real_ver = $1;
-            my $ver      = "v${2}_${3}";
-            while (1) {
-                my $compat_class = "DBIx::Class::Schema::Loader::Compat::${ver}";
-                if ($self->load_optional_class($compat_class)) {
-                    no strict 'refs';
-                    my $class = ref $self || $self;
 
-                    @{"${class}::ISA"} = map {
-                        $_ eq 'DBIx::Class::Schema::Loader::Base' ?
-                            $compat_class : $_
-                    } @{"${class}::ISA"};
+            $self->schema_version_to_dump($real_ver);
 
-                    Class::C3::reinitialize;
-                    $self->schema_version_to_dump($real_ver);
-                    last;
-                }
-                $ver =~ s/\d\z// or last;
-            }
+            # XXX when we go past .0 this will need fixing
+            my ($v) = $real_ver =~ /([1-9])/;
+            $v = "v$v";
+
+            $self->naming->{relationships} ||= $v;
+            $self->naming->{monikers}      ||= $v;
+
             last;
         }
     }
@@ -510,6 +518,14 @@
 
     return if $self->{skip_relationships};
 
+    if ($self->naming->{relationships} eq 'v4') {
+        require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
+        return $self->{relbuilder} ||=
+            DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040->new(
+                $self->schema, $self->inflect_plural, $self->inflect_singular
+            );
+    }
+
     $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new(
         $self->schema, $self->inflect_plural, $self->inflect_singular
     );
@@ -947,6 +963,10 @@
 sub _default_table2moniker {
     my ($self, $table) = @_;
 
+    if ($self->naming->{monikers} eq 'v4') {
+        return join '', map ucfirst, split /[\W_]+/, lc $table;
+    }
+
     return join '', map ucfirst, split /[\W_]+/,
         Lingua::EN::Inflect::Number::to_S(lc $table);
 }

Modified: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm	2009-12-24 09:24:08 UTC (rev 8165)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm	2009-12-24 11:03:15 UTC (rev 8166)
@@ -39,6 +39,6 @@
 
 =head1 DESCRIPTION
 
-Loaded by L<DBIx::Class::Schema::Loader::Compat::v0_040>.
+See L<DBIx::Class::Schema::Loader::Base/naming>.
 
 =cut

Modified: branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader.pm	2009-12-24 09:24:08 UTC (rev 8165)
+++ branches/DBIx-Class-Schema-Loader/back-compat/lib/DBIx/Class/Schema/Loader.pm	2009-12-24 11:03:15 UTC (rev 8166)
@@ -13,7 +13,9 @@
 our $VERSION = '0.04999_12';
 
 __PACKAGE__->mk_classaccessor('_loader_args' => {});
-__PACKAGE__->mk_classaccessors(qw/dump_to_dir _loader_invoked _loader loader_class/);
+__PACKAGE__->mk_classaccessors(qw/
+    dump_to_dir _loader_invoked _loader loader_class naming
+/);
 
 =head1 NAME
 
@@ -150,6 +152,7 @@
     $args->{schema_class} = $class;
     weaken($args->{schema}) if ref $self;
     $args->{dump_directory} ||= $self->dump_to_dir;
+    $args->{naming} = $self->naming;
 
     # XXX this only works for relative storage_type, like ::DBI ...
     my $impl = $self->loader_class
@@ -285,16 +288,23 @@
 
 sub import {
     my $self = shift;
+
     return if !@_;
+
+    my $cpkg = (caller)[0];
+
     foreach my $opt (@_) {
         if($opt =~ m{^dump_to_dir:(.*)$}) {
             $self->dump_to_dir($1)
         }
         elsif($opt eq 'make_schema_at') {
             no strict 'refs';
-            my $cpkg = (caller)[0];
             *{"${cpkg}::make_schema_at"} = \&make_schema_at;
         }
+        elsif($opt eq 'naming') {
+            no strict 'refs';
+            *{"${cpkg}::naming"} = sub { $self->naming(@_) };
+        }
     }
 }
 
@@ -370,7 +380,25 @@
 
 sub rescan { my $self = shift; $self->_loader->rescan($self) }
 
+=head2 naming
 
+=over 4
+
+=item Arguments: \%opts | $ver
+
+=back
+
+Controls the naming options for backward compatibility, see
+L<DBIx::Class::Schema::Loader::Base/naming> for details.
+
+To upgrade a dynamic schema, use:
+
+    __PACKAGE__->naming('current');
+
+Can be imported into your dump script and called as a function as well:
+
+    naming('v4');
+
 =head1 KNOWN ISSUES
 
 =head2 Multiple Database Schemas




More information about the Bast-commits mailing list