From: Rafael Kitover Date: Mon, 11 Jan 2010 13:59:31 +0000 (+0000) Subject: use_namespaces is now default, still needs the upgrade code X-Git-Tag: 0.04999_14~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f22644d75f6f7bc63bc695c32ad6dd59e7af359b;p=dbsrgits%2FDBIx-Class-Schema-Loader.git use_namespaces is now default, still needs the upgrade code --- diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 5624601..ec708e4 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -19,6 +19,7 @@ __PACKAGE__->mk_group_accessors('inherited', qw/ _loader loader_class naming + use_namespaces /); __PACKAGE__->_loader_args({}); @@ -158,6 +159,7 @@ sub _invoke_loader { 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 @@ sub import { 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 @@ Can be imported into your dump script and called as a function as well: naming('v4'); +=head2 use_namespaces + +=over 4 + +=item Arguments: 1|0 + +=back + +Controls the use_namespaces options for backward compatibility, see +L 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 diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index a2d43ff..25b8f86 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -38,7 +38,6 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ dump_directory dump_overwrite really_erase_my_files - use_namespaces result_namespace resultset_namespace default_resultset_class @@ -62,6 +61,8 @@ __PACKAGE__->mk_group_accessors('simple', qw/ version_to_dump schema_version_to_dump _upgrading_from + _upgrading_from_load_classes + use_namespaces /); =head1 NAME @@ -263,6 +264,9 @@ C list if this option is set. =head2 use_namespaces +This is now the default, to go back to L pass +a C<0>. + Generate result class names suitable for L and call that instead of L. When using this option you can also @@ -412,6 +416,8 @@ sub new { $self->_check_back_compat; + $self->use_namespaces(1) unless defined $self->use_namespaces; + $self; } @@ -442,6 +448,8 @@ EOF $self->naming->{relationships} ||= 'v4'; $self->naming->{monikers} ||= 'v4'; + $self->use_namespaces(0) unless defined $self->use_namespaces; + return; } @@ -452,14 +460,21 @@ EOF 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 @@ EOF $self->schema_version_to_dump($real_ver); + $self->use_namespaces(0) unless defined $self->use_namespaces; + last; } } diff --git a/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod b/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod index 4db5e74..391fafc 100644 --- a/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod +++ b/lib/DBIx/Class/Schema/Loader/Manual/UpgradingFromV4.pod @@ -38,34 +38,45 @@ becomes C instead. =item * +use_namespaces + +Now defaults to on. See L and +L. + +=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 will +be off. -To control this behavior see L. +To control this behavior see L and +L. =head2 Static Schemas When reading a C 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 attribute. +overridden with the C and/or C 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 off. -To upgrade a dynamic schema, set the naming attribute (which is proxied to the -loader) in your C: +To upgrade a dynamic schema, set the C and C attributes +(which is proxied to the loader) in your C: __PACKAGE__->naming('current'); + __PACKAGE__->use_namespaces(1); =head1 AUTHOR diff --git a/t/23dumpmore.t b/t/23dumpmore.t index a50fffc..c27973e 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -63,6 +63,7 @@ sub do_dump_test { 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)); diff --git a/t/25backcompat_v4.t b/t/25backcompat_v4.t index 9823000..bffba74 100644 --- a/t/25backcompat_v4.t +++ b/t/25backcompat_v4.t @@ -335,6 +335,9 @@ END { 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}"); diff --git a/t/40overwrite_modifications.t b/t/40overwrite_modifications.t index fa079f5..13154dd 100644 --- a/t/40overwrite_modifications.t +++ b/t/40overwrite_modifications.t @@ -11,7 +11,8 @@ use File::Temp qw/ tempdir tempfile /; 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 diff --git a/t/backcompat/0.04006/10sqlite_common.t b/t/backcompat/0.04006/10sqlite_common.t index ea98d92..c6d52f3 100644 --- a/t/backcompat/0.04006/10sqlite_common.t +++ b/t/backcompat/0.04006/10sqlite_common.t @@ -21,5 +21,5 @@ my $class = $@ ? 'SQLite2' : 'SQLite'; } END { - unlink './t/sqlite_test'; + unlink './t/sqlite_test' if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT}; } diff --git a/t/backcompat/0.04006/22dump.t b/t/backcompat/0.04006/22dump.t index fb609d2..9a53f7d 100644 --- a/t/backcompat/0.04006/22dump.t +++ b/t/backcompat/0.04006/22dump.t @@ -69,4 +69,4 @@ eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) }; 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}; } diff --git a/t/backcompat/0.04006/23dumpmore.t b/t/backcompat/0.04006/23dumpmore.t index 2d14615..72b08be 100644 --- a/t/backcompat/0.04006/23dumpmore.t +++ b/t/backcompat/0.04006/23dumpmore.t @@ -20,6 +20,9 @@ sub do_dump_test { 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 @@ do_dump_test( done_testing; -END { rmtree($DUMP_PATH, 1, 1); } +END { rmtree($DUMP_PATH, 1, 1) if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT}; } diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index f4af33d..7687cde 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -99,6 +99,7 @@ sub setup_schema { inflect_singular => { fkid => 'fkid_singular' }, moniker_map => \&_monikerize, debug => $debug, + use_namespaces => 0, dump_directory => $DUMP_DIR, );