From: Tim Bunce Date: Mon, 9 Mar 2009 21:02:02 +0000 (+0000) Subject: Implement result_base_class and schema_base_class options. X-Git-Tag: 0.04006~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9c9c2f2b79ade1740e330c758bfc0d65446c5fd6;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Implement result_base_class and schema_base_class options. --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index fada2be..c6b89dd 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -39,6 +39,8 @@ __PACKAGE__->mk_ro_accessors(qw/ result_namespace resultset_namespace default_resultset_class + schema_base_class + result_base_class db_schema _tables @@ -120,6 +122,14 @@ L. As L above, but for singularizing relationship names. Default behavior is to utilize L. +=head2 schema_base_class + +Base class for your schema classes. Defaults to 'DBIx::Class::Schema'. + +=head2 result_base_class + +Base class for your table classes (aka result classes). Defaults to 'DBIx::Class'. + =head2 additional_base_classes List of additional base classes all of your table classes will use. @@ -445,6 +455,7 @@ sub _dump_to_dir { my $target_dir = $self->dump_directory; my $schema_class = $self->schema_class; + my $schema_base_class = $self->schema_base_class || 'DBIx::Class::Schema'; croak "Must specify target directory for dumping!" if ! $target_dir; @@ -453,7 +464,7 @@ sub _dump_to_dir { 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|use base '$schema_base_class';\n\n|; if ($self->use_namespaces) { @@ -476,11 +487,13 @@ sub _dump_to_dir { $self->_write_classfile($schema_class, $schema_text); + my $result_base_class = $self->result_base_class || 'DBIx::Class'; + foreach my $src_class (sort keys %{$self->{_dump_storage}}) { my $src_text = qq|package $src_class;\n\n| . qq|use strict;\nuse warnings;\n\n| - . qq|use base 'DBIx::Class';\n\n|; + . qq|use base '$result_base_class';\n\n|; $self->_write_classfile($src_class, $src_text); } diff --git a/t/23dumpmore.t b/t/23dumpmore.t index b3b3d14..02bba17 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -234,6 +234,8 @@ do_dump_test( result_namespace => '+DBICTest::DumpMore::1::Res', resultset_namespace => 'RSet', default_resultset_class => 'RSetBase', + result_base_class => 'My::ResultBaseClass', + schema_base_class => 'My::SchemaBaseClass', }, error => '', warnings => [ @@ -247,14 +249,17 @@ do_dump_test( qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/, qr/resultset_namespace => 'RSet'/, qr/default_resultset_class => 'RSetBase'/, + qr/use base 'My::SchemaBaseClass'/, ], 'Res/Foo' => [ qr/package DBICTest::DumpMore::1::Res::Foo;/, + qr/use base 'My::ResultBaseClass'/, qr/->set_primary_key/, qr/1;\n$/, ], 'Res/Bar' => [ qr/package DBICTest::DumpMore::1::Res::Bar;/, + qr/use base 'My::ResultBaseClass'/, qr/->set_primary_key/, qr/1;\n$/, ],