_loader
loader_class
naming
+ use_namespaces
/);
__PACKAGE__->_loader_args({});
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
no strict 'refs';
*{"${cpkg}::naming"} = sub { $self->naming(@_) };
}
+ elsif($opt eq 'use_namespaces') {
+ no strict 'refs';
+ *{"${cpkg}::use_namespaces"} = sub { $self->use_namespaces(@_) };
+ }
}
}
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
dump_directory
dump_overwrite
really_erase_my_files
- use_namespaces
result_namespace
resultset_namespace
default_resultset_class
version_to_dump
schema_version_to_dump
_upgrading_from
+ _upgrading_from_load_classes
+ use_namespaces
/);
=head1 NAME
=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
$self->_check_back_compat;
+ $self->use_namespaces(1) unless defined $self->use_namespaces;
+
$self;
}
$self->naming->{relationships} ||= 'v4';
$self->naming->{monikers} ||= 'v4';
+ $self->use_namespaces(0) unless defined $self->use_namespaces;
+
return;
}
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 }) {
$self->schema_version_to_dump($real_ver);
+ $self->use_namespaces(0) unless defined $self->use_namespaces;
+
last;
}
}
=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
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));
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}");
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
}
END {
- unlink './t/sqlite_test';
+ unlink './t/sqlite_test' if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT};
}
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}; }
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;
done_testing;
-END { rmtree($DUMP_PATH, 1, 1); }
+END { rmtree($DUMP_PATH, 1, 1) if $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT}; }
inflect_singular => { fkid => 'fkid_singular' },
moniker_map => \&_monikerize,
debug => $debug,
+ use_namespaces => 0,
dump_directory => $DUMP_DIR,
);