From: Matt S Trout Date: Sun, 6 May 2012 18:42:19 +0000 (+0000) Subject: fix coderef naming to avoid confusing autoclean X-Git-Tag: v0.091003~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=167455a084389e2c70299e9e29f1ad249faa2c15;p=gitmo%2FMoo.git fix coderef naming to avoid confusing autoclean --- diff --git a/Changes b/Changes index 3b96d52..223c3f5 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + - fix coderef naming to avoid confusing autoclean + 0.091002 - 2012-05-05 - exclude union roles and same-role-as-self from metaclass inflation - inhale Moose roles before checking for composition conflicts diff --git a/lib/Moo.pm b/lib/Moo.pm index 0ba523e..e352f1a 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -17,7 +17,7 @@ sub import { my $class = shift; strictures->import; return if $MAKERS{$target}; # already exported into this package - _install_coderef "${target}::extends" => sub { + _install_coderef "${target}::extends" => "Moo::extends" => sub { _load_module($_) for @_; # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA @{*{_getglob("${target}::ISA")}{ARRAY}} = @_; @@ -27,12 +27,12 @@ sub import { ->register_attribute_specs(%{$old->all_attribute_specs}); } }; - _install_coderef "${target}::with" => sub { + _install_coderef "${target}::with" => "Moo::with" => sub { require Moo::Role; Moo::Role->apply_roles_to_package($target, $_[0]); }; $MAKERS{$target} = {}; - _install_coderef "${target}::has" => sub { + _install_coderef "${target}::has" => "Moo::has" => sub { my ($name, %spec) = @_; $class->_constructor_maker_for($target) ->register_attribute_specs($name, \%spec); @@ -40,7 +40,7 @@ sub import { ->generate_method($target, $name, \%spec); }; foreach my $type (qw(before after around)) { - _install_coderef "${target}::${type}" => sub { + _install_coderef "${target}::${type}" => "Moo::${type}" => sub { require Class::Method::Modifiers; _install_modifier($target, $type, @_); }; diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index 34203a8..68581f0 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -16,7 +16,7 @@ sub import { return if $INFO{$target}; # already exported into this package # get symbol table reference my $stash = do { no strict 'refs'; \%{"${target}::"} }; - _install_coderef "${target}::has" => sub { + _install_coderef "${target}::has" => "Moo::Role::has" => sub { my ($name, %spec) = @_; ($INFO{$target}{accessor_maker} ||= do { require Method::Generate::Accessor; diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index 6db4dac..b45b433 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -67,6 +67,7 @@ sub _install_coderef { } sub _name_coderef { + shift if @_ > 2; can_haz_subname ? Sub::Name::subname(@_) : $_[1]; } diff --git a/xt/moo-roles-into-moose-class.t b/xt/moo-roles-into-moose-class.t index d1d0a6c..ac17d30 100644 --- a/xt/moo-roles-into-moose-class.t +++ b/xt/moo-roles-into-moose-class.t @@ -5,7 +5,8 @@ use Test::More; { package Foo; use Moo::Role; - use namespace::autoclean; + # if we autoclean here there's nothing left and then load_class tries + # to require Foo during Moose application and everything breaks. } { package Bar; @@ -29,6 +30,8 @@ use Test::More; ::is(Baz->can('thing'), Bar->can('thing'), 'Role copies method correctly'); ::ok(Baz->can('attr'), 'Attr accessor correct'); +::ok(!Bar->can('has'), 'Moo::Role sugar removed by autoclean'); +::ok(!Bar->can('with'), 'Role::Tiny sugar removed by autoclean'); ::ok(!Baz->can('has'), 'Sugar not copied'); {