Subject: | Override Schema and Result base class [PATCH] |
The attached patch implements result_base_class and schema_base_class options, with docs
and tests. (As discussed on irc.)
Patch is over r5720
Subject: | DBIC-CSL-base-class-override.patch |
Index: t/23dumpmore.t
===================================================================
--- t/23dumpmore.t (revision 5720)
+++ t/23dumpmore.t (working copy)
@@ -234,6 +234,8 @@
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 @@
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$/,
],
Index: lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- lib/DBIx/Class/Schema/Loader/Base.pm (revision 5720)
+++ lib/DBIx/Class/Schema/Loader/Base.pm (working copy)
@@ -39,6 +39,8 @@
result_namespace
resultset_namespace
default_resultset_class
+ schema_base_class
+ result_base_class
db_schema
_tables
@@ -120,6 +122,14 @@
As L</inflect_plural> above, but for singularizing relationship names.
Default behavior is to utilize L<Lingua::EN::Inflect::Number/to_S>.
+=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 @@
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 @@
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 @@
$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);
}