[Bast-commits] r8281 - in branches/DBIx-Class-Schema-Loader/current: lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Loader lib/DBIx/Class/Schema/Loader/Manual t t/backcompat/0.04006 t/lib

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Mon Jan 11 13:59:31 GMT 2010


Author: caelum
Date: 2010-01-11 13:59:31 +0000 (Mon, 11 Jan 2010)
New Revision: 8281

Modified:
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod
   branches/DBIx-Class-Schema-Loader/current/t/23dumpmore.t
   branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
   branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t
   branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/10sqlite_common.t
   branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/22dump.t
   branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/23dumpmore.t
   branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
Log:
use_namespaces is now default, still needs the upgrade code

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 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm	2010-01-11 13:59:31 UTC (rev 8281)
@@ -38,7 +38,6 @@
                                 dump_directory
                                 dump_overwrite
                                 really_erase_my_files
-                                use_namespaces
                                 result_namespace
                                 resultset_namespace
                                 default_resultset_class
@@ -62,6 +61,8 @@
                                 version_to_dump
                                 schema_version_to_dump
                                 _upgrading_from
+                                _upgrading_from_load_classes
+                                use_namespaces
 /);
 
 =head1 NAME
@@ -263,6 +264,9 @@
 
 =head2 use_namespaces
 
+This is now the default, to go back to L<DBIx::Class::Schema/load_classes> pass
+a C<0>.
+
 Generate result class names suitable for
 L<DBIx::Class::Schema/load_namespaces> and call that instead of
 L<DBIx::Class::Schema/load_classes>. When using this option you can also
@@ -412,6 +416,8 @@
 
     $self->_check_back_compat;
 
+    $self->use_namespaces(1) unless defined $self->use_namespaces;
+
     $self;
 }
 
@@ -442,6 +448,8 @@
         $self->naming->{relationships} ||= 'v4';
         $self->naming->{monikers}      ||= 'v4';
 
+        $self->use_namespaces(0) unless defined $self->use_namespaces;
+
         return;
     }
 
@@ -452,14 +460,21 @@
     open(my $fh, '<', $filename)
         or croak "Cannot open '$filename' for reading: $!";
 
+    my $load_classes = 0;
+
     while (<$fh>) {
-        if (/^# Created by DBIx::Class::Schema::Loader v((\d+)\.(\d+))/) {
+        if (/^__PACKAGE__->load_classes;/) {
+            $load_classes = 1;
+        } elsif (/^# Created by DBIx::Class::Schema::Loader v((\d+)\.(\d+))/) {
             my $real_ver = $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 }) {
@@ -484,6 +499,8 @@
 
             $self->schema_version_to_dump($real_ver);
 
+            $self->use_namespaces(0) unless defined $self->use_namespaces;
+
             last;
         }
     }

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod	2010-01-11 13:59:31 UTC (rev 8281)
@@ -38,34 +38,45 @@
 
 =item *
 
+use_namespaces
+
+Now defaults to on. See L<DBIx::Class::Schema::Loader::Base/use_namespaces> and
+L<DBIx::Class::Schema/"load_namespaces">.
+
+=item *
+
 Support for more databases
 
-We now support Microsoft SQL Server and Sybase, and there are also improvements
-to the other backends.
+We now support Microsoft SQL Server and Sybase, and there are also many
+improvements to the other backends.
 
 =back
 
 =head1 Backward Compatibility
 
 In backward compatibility mode, the Loader will use the old relationship names
-and types, and will not singularize monikers for tables.
+and types, will not singularize monikers for tables, and C<use_namespaces> will
+be off.
 
-To control this behavior see L<DBIx::Class::Schema::Loader::Base/naming>.
+To control this behavior see L<DBIx::Class::Schema::Loader::Base/naming> and
+L<DBIx::Class::Schema::Loader::Base/use_namespaces>.
 
 =head2 Static Schemas
 
 When reading a C<Schema.pm> from a static schema generated with an C<0.04>
 version of Loader, backward compatibility mode will default to on, unless
-overridden with the C<naming> attribute.
+overridden with the C<naming> and/or C<use_namespaces> attributes.
 
 =head2 Dynamic Schemas
 
-Dynamic schemas will always by default use C<0.04006> mode.
+Dynamic schemas will always by default use C<0.04006> mode and have
+C<use_namespaces> off.
 
-To upgrade a dynamic schema, set the naming attribute (which is proxied to the
-loader) in your C<Schema.pm>:
+To upgrade a dynamic schema, set the C<naming> and C<use_namespaces> attributes
+(which is proxied to the loader) in your C<Schema.pm>:
 
     __PACKAGE__->naming('current');
+    __PACKAGE__->use_namespaces(1);
 
 =head1 AUTHOR
 

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm	2010-01-11 13:59:31 UTC (rev 8281)
@@ -19,6 +19,7 @@
                                 _loader
                                 loader_class
                                 naming
+                                use_namespaces
 /);
 __PACKAGE__->_loader_args({});
 
@@ -158,6 +159,7 @@
     weaken($args->{schema}) if ref $self;
     $args->{dump_directory} ||= $self->dump_to_dir;
     $args->{naming} = $self->naming if $self->naming;
+    $args->{use_namespaces} = $self->use_namespaces if $self->use_namespaces;
 
     # XXX this only works for relative storage_type, like ::DBI ...
     my $impl = $self->loader_class
@@ -310,6 +312,10 @@
             no strict 'refs';
             *{"${cpkg}::naming"} = sub { $self->naming(@_) };
         }
+        elsif($opt eq 'use_namespaces') {
+            no strict 'refs';
+            *{"${cpkg}::use_namespaces"} = sub { $self->use_namespaces(@_) };
+        }
     }
 }
 
@@ -404,6 +410,25 @@
 
     naming('v4');
 
+=head2 use_namespaces
+
+=over 4
+
+=item Arguments: 1|0
+
+=back
+
+Controls the use_namespaces options for backward compatibility, see
+L<DBIx::Class::Schema::Loader::Base/use_namespaces> for details.
+
+To upgrade a dynamic schema, use:
+
+    __PACKAGE__->use_namespaces(1);
+
+Can be imported into your dump script and called as a function as well:
+
+    use_namespaces(1);
+
 =head1 KNOWN ISSUES
 
 =head2 Multiple Database Schemas

Modified: branches/DBIx-Class-Schema-Loader/current/t/23dumpmore.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/23dumpmore.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/23dumpmore.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -63,6 +63,7 @@
     my %tdata = @_;
     
     $tdata{options}{dump_directory} = $DUMP_PATH;
+    $tdata{options}{use_namespaces} ||= 0;
 
     for my $dumper (\&dump_directly, \&dump_dbicdump) {
         test_dumps(\%tdata, $dumper->(%tdata));

Modified: branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -335,6 +335,9 @@
 sub run_loader {
     my %loader_opts = @_;
 
+    $loader_opts{use_namespaces} = 0
+        unless exists $loader_opts{use_namespaces};
+
     eval {
         foreach my $source_name ($SCHEMA_CLASS->clone->sources) {
             Class::Unload->unload("${SCHEMA_CLASS}::${source_name}");

Modified: branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/40overwrite_modifications.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -11,7 +11,8 @@
 use DBIx::Class::Schema::Loader;
 
 my $tempdir = tempdir( CLEANUP => 1 );
-my $foopm = File::Spec->catfile( $tempdir, qw| DBICTest Schema Overwrite_modifications Foo.pm |);
+my $foopm = File::Spec->catfile( $tempdir,
+    qw| DBICTest Schema Overwrite_modifications Result Foo.pm |);
 dump_schema();
 
 # check that we dumped

Modified: branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/10sqlite_common.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/10sqlite_common.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/10sqlite_common.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -21,5 +21,5 @@
 }
 
 END {
-    unlink './t/sqlite_test';
+    unlink './t/sqlite_test' if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT};
 }

Modified: branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/22dump.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/22dump.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/22dump.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -69,4 +69,4 @@
 ok(!$@, 'no death with dump_directory set (overwrite2)')
     or diag "Dump failed: $@";
 
-END { rmtree($dump_path, 1, 1); }
+END { rmtree($dump_path, 1, 1) if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT}; }

Modified: branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/23dumpmore.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/23dumpmore.t	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/23dumpmore.t	2010-01-11 13:59:31 UTC (rev 8281)
@@ -20,6 +20,9 @@
 
     no strict 'refs';
     @{$schema_class . '::ISA'} = ('DBIx::Class::Schema::Loader');
+
+    $tdata{options}{use_namespaces} ||= 0;
+
     $schema_class->loader_options(dump_directory => $DUMP_PATH, %{$tdata{options}});
 
     my @warns;
@@ -270,4 +273,4 @@
 
 done_testing;
 
-END { rmtree($DUMP_PATH, 1, 1); }
+END { rmtree($DUMP_PATH, 1, 1) if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT}; }

Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2010-01-11 08:52:08 UTC (rev 8280)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm	2010-01-11 13:59:31 UTC (rev 8281)
@@ -99,6 +99,7 @@
         inflect_singular        => { fkid => 'fkid_singular' },
         moniker_map             => \&_monikerize,
         debug                   => $debug,
+        use_namespaces          => 0,
         dump_directory          => $DUMP_DIR,
     );
 




More information about the Bast-commits mailing list