[Bast-commits] r8282 - in branches/DBIx-Class-Schema-Loader/current: . lib/DBIx/Class/Schema/Loader t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Mon Jan 11 21:23:38 GMT 2010


Author: caelum
Date: 2010-01-11 21:23:38 +0000 (Mon, 11 Jan 2010)
New Revision: 8282

Removed:
   branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT
Modified:
   branches/DBIx-Class-Schema-Loader/current/Changes
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
   branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
Log:
more use_namespaces upgrade stuff, fix _table_filter

Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-11 13:59:31 UTC (rev 8281)
+++ branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-11 21:23:38 UTC (rev 8282)
@@ -1,5 +1,6 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - filter out un-selectable tables/views
         - fix NUMERIC/DECIMAL size column_info for postgres
         - now mentions skip_load_external feature in comments (jhannah)
         - moniker_map POD correction (jhannah)

Deleted: branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT	2010-01-11 13:59:31 UTC (rev 8281)
+++ branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT	2010-01-11 21:23:38 UTC (rev 8282)
@@ -1,13 +0,0 @@
-SL Backcompat Plan:
-
-* make use_namespaces the default, and upgrade to it properly
-
-*** Catalyst Helper
-
-* Add 'upgrade=1' option that upgrades from both old S::L and old helper,
-  whichever or both.
-* Warn when old helper output or 0.04000 S::L output is detected, that refers to
-  the upgrade option.
-
-Release dev S::L, announce to catalyst, dbic lists and #catalyst that testing of
-backcompat mode is needed, wait 2-3 weeks, then release 0.05000.

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm	2010-01-11 13:59:31 UTC (rev 8281)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm	2010-01-11 21:23:38 UTC (rev 8282)
@@ -437,6 +437,8 @@
 Set the 'naming' attribute or the SCHEMA_LOADER_BACKCOMPAT environment variable
 to disable this warning.
 
+Also consider setting 'use_namespaces => 1' if/when upgrading.
+
 See perldoc DBIx::Class::Schema::Loader::Manual::UpgradingFromV4 for more
 details.
 EOF
@@ -448,7 +450,12 @@
         $self->naming->{relationships} ||= 'v4';
         $self->naming->{monikers}      ||= 'v4';
 
-        $self->use_namespaces(0) unless defined $self->use_namespaces;
+        if ($self->use_namespaces) {
+            $self->_upgrading_from_load_classes(1);
+        }
+        else {
+            $self->use_namespaces(0);
+        }
 
         return;
     }
@@ -465,16 +472,31 @@
     while (<$fh>) {
         if (/^__PACKAGE__->load_classes;/) {
             $load_classes = 1;
-        } elsif (/^# Created by DBIx::Class::Schema::Loader v((\d+)\.(\d+))/) {
-            my $real_ver = $1;
+        } elsif (my ($real_ver) =
+                /^# Created by DBIx::Class::Schema::Loader v(\d+\.\d+)/) {
 
+            if ($load_classes && (not defined $self->use_namespaces)) {
+                warn <<"EOF"  unless $ENV{SCHEMA_LOADER_BACKCOMPAT};
+
+'load_classes;' static schema detected, turning off use_namespaces.
+
+Set the 'use_namespaces' attribute or the SCHEMA_LOADER_BACKCOMPAT environment
+variable to disable this warning.
+
+See perldoc DBIx::Class::Schema::Loader::Manual::UpgradingFromV4 for more
+details.
+EOF
+                $self->use_namespaces(0);
+            }
+            elsif ($load_classes && $self->use_namespaces) {
+                $self->use_namespaces(1);
+                $self->_upgrading_from_load_classes(1);
+            }
+
             # XXX when we go past .0 this will need fixing
             my ($v) = $real_ver =~ /([1-9])/;
             $v = "v$v";
 
-            $self->_upgrading_from_load_classes($load_classes)
-                unless defined $self->use_namespaces;
-
             last if $v eq CURRENT_V || $real_ver =~ /^0\.\d\d999/;
 
             if (not %{ $self->naming }) {
@@ -1079,9 +1101,15 @@
     }
     my $table_class = join(q{::}, @result_namespace, $table_moniker);
 
-    if (my $upgrading_v = $self->_upgrading_from) {
-        local $self->naming->{monikers} = $upgrading_v;
+    if ((my $upgrading_v = $self->_upgrading_from)
+            || $self->_upgrading_from_load_classes) {
+        local $self->naming->{monikers} = $upgrading_v
+            if $upgrading_v;
 
+        my @result_namespace = @result_namespace;
+        @result_namespace = ($schema_class)
+            if $self->_upgrading_from_load_classes;
+
         my $old_class = join(q{::}, @result_namespace,
             $self->_table2moniker($table));
 

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm	2010-01-11 13:59:31 UTC (rev 8281)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm	2010-01-11 21:23:38 UTC (rev 8282)
@@ -109,8 +109,10 @@
     my @filtered_tables;
 
     for my $table (@tables) {
-        my $sth = $self->_sth_for($table, undef, \'1 = 0');
-        eval { $sth->execute };
+        eval {
+            my $sth = $self->_sth_for($table, undef, \'1 = 0');
+            $sth->execute;
+        };
         if (not $@) {
             push @filtered_tables, $table;
         }

Modified: branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-11 13:59:31 UTC (rev 8281)
+++ branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-11 21:23:38 UTC (rev 8282)
@@ -114,6 +114,66 @@
     pop @INC;
 }
 
+# test upgraded dynamic schema with use_namespaces with external content loaded
+{
+    my $temp_dir = tempdir;
+    push @INC, $temp_dir;
+
+    my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
+    make_path $external_result_dir;
+
+    # make external content for Result that will be singularized
+    IO::File->new(">$external_result_dir/Quuxs.pm")->print(<<"EOF");
+package ${SCHEMA_CLASS}::Quuxs;
+sub a_method { 'hlagh' }
+
+__PACKAGE__->has_one('bazrel', 'DBIXCSL_Test::Schema::Bazs',
+    { 'foreign.baz_num' => 'self.baz_id' });
+
+1;
+EOF
+
+    # make external content for Result that will NOT be singularized
+    IO::File->new(">$external_result_dir/Bar.pm")->print(<<"EOF");
+package ${SCHEMA_CLASS}::Bar;
+
+__PACKAGE__->has_one('foorel', 'DBIXCSL_Test::Schema::Foos',
+    { 'foreign.fooid' => 'self.foo_id' });
+
+1;
+EOF
+
+    my $res = run_loader(naming => 'current', use_namespaces => 1);
+    my $schema = $res->{schema};
+
+    is scalar @{ $res->{warnings} }, 2,
+'correct nummber of warnings for upgraded dynamic schema with external ' .
+'content for unsingularized Result with use_namespaces.';
+
+    my $warning = $res->{warnings}[0];
+    like $warning, qr/Detected external content/i,
+        'detected external content warning';
+
+    lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'hlagh' }
+'external custom content for unsingularized Result was loaded by upgraded ' .
+'dynamic Schema';
+
+    lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel,
+        $res->{classes}{bazs} }
+        'unsingularized class names in external content are translated';
+
+    lives_and { isa_ok $schema->resultset('Bar')->find(1)->foorel,
+        $res->{classes}{foos} }
+'unsingularized class names in external content from unchanged Result class ' .
+'names are translated';
+
+    run_v5_tests($res);
+
+    rmtree $temp_dir;
+    pop @INC;
+}
+
+
 # test upgraded static schema with external content loaded
 {
     my $temp_dir = tempdir;
@@ -365,7 +425,8 @@
     foreach my $source_name ($schema->sources) {
         my $table_name = $schema->source($source_name)->from;
         $monikers{$table_name} = $source_name;
-        $classes{$table_name}  = "${SCHEMA_CLASS}::${source_name}";
+        $classes{$table_name}  = "${SCHEMA_CLASS}::" . (
+            $loader_opts{use_namespaces} ? 'Result::' : '') . $source_name;
     }
 
     return {




More information about the Bast-commits mailing list