From: Chris Weyl Date: Sun, 2 Oct 2011 02:38:52 +0000 (-0700) Subject: namespace::autoclean to MooseX::MarkAsMethods X-Git-Tag: 0.07011~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d265d7f4d1ccb93bc022fb11bda57e97b30f80f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git namespace::autoclean to MooseX::MarkAsMethods Use MooseX::MarkAsMethods with autoclean => 1 instead of namespace::autoclean for the use_moose option, to protect operator overloads. Add an only_autoclean option to use namespace::autoclean as before. --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index b95ed42..e7b81be 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -59,6 +59,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ result_base_class result_roles use_moose + only_autoclean overwrite_modifications relationship_attrs @@ -740,11 +741,27 @@ __PACKAGE__->table >> calls, and to some other things like Oracle sequences. =head2 use_moose Creates Schema and Result classes that use L, L and -L. The default content after the md5 sum also makes the -classes immutable. +L (or L, see below). The default +content after the md5 sum also makes the classes immutable. It is safe to upgrade your existing Schema to this option. +=head2 only_autoclean + +By default, we use L to remove imported functions from +your generated classes. It uses L to do this, after +telling your object's metaclass that any Ls in your class are +methods, which will cause namespace::autoclean to spare them from removal. + +This prevents the "Hey, where'd my overloads go?!" effect. + +If you don't care about overloads, enabling this option falls back to just using +L itself. + +If none of the above made any sense, or you don't have some pressing need to +only use L, leaving this set to the default is +recommended. + =head2 col_collision_map This option controls how accessors for column names which collide with perl @@ -1649,8 +1666,15 @@ sub _dump_to_dir { . qq|# Created by DBIx::Class::Schema::Loader\n| . qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|; + my $autoclean + = $self->only_autoclean + ? 'namespace::autoclean' + : 'MooseX::MarkAsMethods autoclean => 1' + ; + if ($self->use_moose) { - $schema_text.= qq|use Moose;\nuse namespace::autoclean;\nextends '$schema_base_class';\n\n|; + + $schema_text.= qq|use Moose;\nuse $autoclean;\nextends '$schema_base_class';\n\n|; } else { $schema_text .= qq|use strict;\nuse warnings;\n\nuse base '$schema_base_class';\n\n|; @@ -1708,7 +1732,7 @@ sub _dump_to_dir { unless $result_base_class eq 'DBIx::Class::Core'; if ($self->use_moose) { - $src_text.= qq|use Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;|; + $src_text.= qq|use Moose;\nuse MooseX::NonMoose;\nuse $autoclean;|; # these options 'use base' which is compile time if (@{ $self->left_base_classes } || @{ $self->additional_base_classes }) { diff --git a/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm b/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm index 5f47f79..fad6d6d 100644 --- a/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm @@ -22,7 +22,7 @@ my $reqs = { req => { 'Moose' => '1.12', 'MooseX::NonMoose' => '0.16', - 'namespace::autoclean' => '0.09', + 'MooseX::MarkAsMethods' => '0.13', }, pod => { title => 'use_moose', diff --git a/t/26dump_use_moose.t b/t/26dump_use_moose.t index fe98553..d247050 100644 --- a/t/26dump_use_moose.t +++ b/t/26dump_use_moose.t @@ -26,17 +26,17 @@ $t->dump_test( }, regexes => { schema => [ - qr/\nuse Moose;\nuse namespace::autoclean;\nextends 'My::SchemaBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::SchemaBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable\(inline_constructor => 0\);\n1;(?!\n1;\n)\n.*/, ], Foo => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/=head1 L ROLES APPLIED\n\n=over 4\n\n=item \* L\n\n=item \* L\n\n=back\n\n=cut\n\n/, qr/\nwith 'TestRole', 'TestRole2';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, ], Bar => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/=head1 L ROLES APPLIED\n\n=over 4\n\n=item \* L\n\n=item \* L\n\n=back\n\n=cut\n\n/, qr/\nwith 'TestRole', 'TestRole2';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, @@ -46,6 +46,25 @@ $t->dump_test( $t->cleanup; +# check protect_overloads works as expected +$t->dump_test( + classname => 'DBICTest::DumpMore::1', + options => { + use_moose => 1, + only_autoclean => 1, + }, + regexes => { + schema => [ + qr/\nuse namespace::autoclean;\n/, + ], + Foo => [ + qr/\nuse namespace::autoclean;\n/, + ], + }, +); + +$t->cleanup; + # now upgrade a fresh non-moose schema to use_moose=1 $t->dump_test( classname => 'DBICTest::DumpMore::1', @@ -79,16 +98,16 @@ $t->dump_test( }, regexes => { schema => [ - qr/\nuse Moose;\nuse namespace::autoclean;\nextends 'My::SchemaBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::SchemaBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable\(inline_constructor => 0\);\n1;(?!\n1;\n)\n.*/, ], Foo => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, qr/# XXX This is my custom content XXX/, ], Bar => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, ], }, @@ -131,15 +150,15 @@ for my $supply_use_moose (1, 0) { }, regexes => { schema => [ - qr/\nuse Moose;\nuse namespace::autoclean;\nextends 'My::SchemaBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::SchemaBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable\(inline_constructor => 0\);\n1;(?!\n1;\n)\n.*/, ], Foo => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, ], Bar => [ - qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends 'My::ResultBaseClass';\n\n/, + qr/\nuse Moose;\nuse MooseX::NonMoose;\nuse MooseX::MarkAsMethods autoclean => 1;\nextends 'My::ResultBaseClass';\n\n/, qr/\n__PACKAGE__->meta->make_immutable;\n1;(?!\n1;\n)\n.*/, ], },