From: Peter Rabbitson Date: Wed, 8 Sep 2010 15:25:51 +0000 (+0200) Subject: Handle use_moose => 1 to use_moose => 0 errors gracefully X-Git-Tag: 0.07002~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22eddddaf5e0796ee27d7eccb7be813609b906f9;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Handle use_moose => 1 to use_moose => 0 errors gracefully --- diff --git a/Changes b/Changes index 66b4f1f..62b7e5e 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Properly detect a schema loaded with use_moose on subsequent reloads + - Die with a sensible message when a schema loaded with + use_moose => 1 is reloaded with use_moose => 0 - Switch to MRO::Compat - Fix oracle common tests failure / lc(undef) warnings - Bump Moose/Moosex::NonMoose optional dependencies to fixed-up diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 6927b29..7a9d307 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1316,6 +1316,10 @@ sub _write_classfile { $custom_content .= $self->_default_custom_content; } } + elsif (defined $self->use_moose && $old_gen) { + croak 'It is not possible to "downgrade" a schema that was loaded with use_moose => 1 to use_moose => 0, due to differing custom content' + if $old_gen =~ /use \s+ MooseX?\b/x; + } $custom_content = $self->_rewrite_old_classnames($custom_content); diff --git a/t/26dump_use_moose.t b/t/26dump_use_moose.t index 1310455..a794182 100644 --- a/t/26dump_use_moose.t +++ b/t/26dump_use_moose.t @@ -49,6 +49,7 @@ $t->cleanup; $t->dump_test( classname => 'DBICTest::DumpMore::1', options => { + use_moose => 0, result_base_class => 'My::ResultBaseClass', schema_base_class => 'My::SchemaBaseClass', }, @@ -101,7 +102,7 @@ $t->dump_test( $t->cleanup; -# now add the Moose custom content to unapgraded schema, and make sure it is not repeated +# check with a fresh non-moose schema that Moose custom content added to unapgraded schema, and make sure it is not repeated $t->dump_test( classname => 'DBICTest::DumpMore::1', options => { @@ -164,4 +165,19 @@ for my $supply_use_moose (1, 0) { ); } +# check that a moose schema can *not* be downgraded + +$t->dump_test ( + classname => 'DBICTest::DumpMore::1', + options => { + use_moose => 0, + result_base_class => 'My::ResultBaseClass', + schema_base_class => 'My::SchemaBaseClass', + }, + warnings => [ + qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, + ], + error => qr/\QIt is not possible to "downgrade" a schema that was loaded with use_moose => 1\E/, +); + done_testing;