[Bast-commits] r3976 - in trunk/DBIx-Class-Schema-Loader: .
lib/DBIx/Class/Schema/Loader t
ilmari at dev.catalyst.perl.org
ilmari at dev.catalyst.perl.org
Sun Jan 27 05:05:04 GMT 2008
Author: ilmari
Date: 2008-01-27 05:05:04 +0000 (Sun, 27 Jan 2008)
New Revision: 3976
Modified:
trunk/DBIx-Class-Schema-Loader/Changes
trunk/DBIx-Class-Schema-Loader/lib/DBIx/Class/Schema/Loader/Base.pm
trunk/DBIx-Class-Schema-Loader/t/23dumpmore.t
Log:
Add support for load_namespaces-style class layout.
Modified: trunk/DBIx-Class-Schema-Loader/Changes
===================================================================
--- trunk/DBIx-Class-Schema-Loader/Changes 2008-01-25 17:20:38 UTC (rev 3975)
+++ trunk/DBIx-Class-Schema-Loader/Changes 2008-01-27 05:05:04 UTC (rev 3976)
@@ -1,6 +1,7 @@
Revision history for Perl extension DBIx::Class::Schema::Loader
Not yet released
+ - Add support for load_namespaces-style class layout.
- Fix test skip count for main skip_rels block
0.04004 Thu Nov 15, 2007
Modified: trunk/DBIx-Class-Schema-Loader/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- trunk/DBIx-Class-Schema-Loader/lib/DBIx/Class/Schema/Loader/Base.pm 2008-01-25 17:20:38 UTC (rev 3975)
+++ trunk/DBIx-Class-Schema-Loader/lib/DBIx/Class/Schema/Loader/Base.pm 2008-01-27 05:05:04 UTC (rev 3976)
@@ -35,6 +35,10 @@
dump_directory
dump_overwrite
really_erase_my_files
+ use_namespaces
+ result_namespace
+ resultset_namespace
+ default_resultset_class
db_schema
_tables
@@ -141,6 +145,15 @@
C<ResultSetManager> will be automatically added to the above
C<components> list if this option is set.
+=head2 use_namespaces
+
+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
+specify any of the options for C<load_namespaces> (i.e. C<result_namespace>,
+C<resultset_namespace>, C<default_resultset_class>), and they will be added
+to the call (and the generated result class names adjusted appropriately).
+
=head2 dump_directory
This option is designed to be a tool to help you transition from this
@@ -440,9 +453,27 @@
my $schema_text =
qq|package $schema_class;\n\n|
. qq|use strict;\nuse warnings;\n\n|
- . qq|use base 'DBIx::Class::Schema';\n\n|
- . qq|__PACKAGE__->load_classes;\n|;
+ . qq|use base 'DBIx::Class::Schema';\n\n|;
+
+ if ($self->use_namespaces) {
+ $schema_text .= qq|__PACKAGE__->load_namespaces|;
+ my $namespace_options;
+ for my $attr (qw(result_namespace
+ resultset_namespace
+ default_resultset_class)) {
+ if ($self->$attr) {
+ $namespace_options .= qq| $attr => '| . $self->$attr . qq|',\n|
+ }
+ }
+ $schema_text .= qq|(\n$namespace_options)| if $namespace_options;
+ $schema_text .= qq|;\n|;
+ }
+ else {
+ $schema_text .= qq|__PACKAGE__->load_classes;\n|;
+
+ }
+
$self->_write_classfile($schema_class, $schema_text);
foreach my $src_class (sort keys %{$self->{_dump_storage}}) {
@@ -569,7 +600,19 @@
my $schema_class = $self->schema_class;
my $table_moniker = $self->_table2moniker($table);
- my $table_class = $schema_class . q{::} . $table_moniker;
+ my @result_namespace = ($schema_class);
+ if ($self->use_namespaces) {
+ my $result_namespace = $self->result_namespace || 'Result';
+ if ($result_namespace =~ /^\+(.*)/) {
+ # Fully qualified namespace
+ @result_namespace = ($1)
+ }
+ else {
+ # Relative namespace
+ push @result_namespace, $result_namespace;
+ }
+ }
+ my $table_class = join(q{::}, @result_namespace, $table_moniker);
my $table_normalized = lc $table;
$self->classes->{$table} = $table_class;
Modified: trunk/DBIx-Class-Schema-Loader/t/23dumpmore.t
===================================================================
--- trunk/DBIx-Class-Schema-Loader/t/23dumpmore.t 2008-01-25 17:20:38 UTC (rev 3975)
+++ trunk/DBIx-Class-Schema-Loader/t/23dumpmore.t 2008-01-27 05:05:04 UTC (rev 3976)
@@ -7,7 +7,7 @@
$^O eq 'MSWin32'
? plan(skip_all => "ActiveState perl produces additional warnings, and this test uses unix paths")
- : plan(tests => 40);
+ : plan(tests => 82);
my $DUMP_PATH = './t/_dump';
@@ -169,4 +169,96 @@
},
);
+do_dump_test(
+ classname => 'DBICTest::DumpMore::1',
+ options => { use_namespaces => 1 },
+ error => '',
+ warnings => [
+ qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
+ qr/Schema dump completed/,
+ ],
+ regexes => {
+ schema => [
+ qr/package DBICTest::DumpMore::1;/,
+ qr/->load_namespaces/,
+ ],
+ 'Result/Foo' => [
+ qr/package DBICTest::DumpMore::1::Result::Foo;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ 'Result/Bar' => [
+ qr/package DBICTest::DumpMore::1::Result::Bar;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ },
+);
+
+do_dump_test(
+ classname => 'DBICTest::DumpMore::1',
+ options => { use_namespaces => 1,
+ result_namespace => 'Res',
+ resultset_namespace => 'RSet',
+ default_resultset_class => 'RSetBase',
+ },
+ error => '',
+ warnings => [
+ qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
+ qr/Schema dump completed/,
+ ],
+ regexes => {
+ schema => [
+ qr/package DBICTest::DumpMore::1;/,
+ qr/->load_namespaces/,
+ qr/result_namespace => 'Res'/,
+ qr/resultset_namespace => 'RSet'/,
+ qr/default_resultset_class => 'RSetBase'/,
+ ],
+ 'Res/Foo' => [
+ qr/package DBICTest::DumpMore::1::Res::Foo;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ 'Res/Bar' => [
+ qr/package DBICTest::DumpMore::1::Res::Bar;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ },
+);
+
+do_dump_test(
+ classname => 'DBICTest::DumpMore::1',
+ options => { use_namespaces => 1,
+ result_namespace => '+DBICTest::DumpMore::1::Res',
+ resultset_namespace => 'RSet',
+ default_resultset_class => 'RSetBase',
+ },
+ error => '',
+ warnings => [
+ qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
+ qr/Schema dump completed/,
+ ],
+ regexes => {
+ schema => [
+ qr/package DBICTest::DumpMore::1;/,
+ qr/->load_namespaces/,
+ qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/,
+ qr/resultset_namespace => 'RSet'/,
+ qr/default_resultset_class => 'RSetBase'/,
+ ],
+ 'Res/Foo' => [
+ qr/package DBICTest::DumpMore::1::Res::Foo;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ 'Res/Bar' => [
+ qr/package DBICTest::DumpMore::1::Res::Bar;/,
+ qr/->set_primary_key/,
+ qr/1;\n$/,
+ ],
+ },
+);
+
END { rmtree($DUMP_PATH, 1, 1); }
More information about the Bast-commits
mailing list