From: Matt S Trout Date: Wed, 6 Feb 2013 00:34:55 +0000 (+0000) Subject: fixup exporting to be sane and consistent X-Git-Tag: v1.000008~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa93bfb29cca2d07be28c8459e1626a59a80245c;p=gitmo%2FMoo.git fixup exporting to be sane and consistent --- diff --git a/Changes b/Changes index 5a35527..fbe859a 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + - Re-export on 'use Moo' after 'no Moo' + - Export meta() into roles (but mark as non-method to avoid composing it) - Don't generate an accessor for rw attributes if reader+writer both set - Support builder => sub {} ala MooseX::AttributeShortcuts - Fix 'no Moo;' to preserve non-sub package variables diff --git a/lib/Moo.pm b/lib/Moo.pm index acf7c65..e947e31 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -25,8 +25,7 @@ sub import { if ($Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{is_role}) { die "Cannot import Moo into a role"; } - return if $MAKERS{$target}; # already exported into this package - $MAKERS{$target} = { is_class => 1 }; + $MAKERS{$target} ||= {}; _install_tracked $target => extends => sub { $class->_set_superclasses($target, @_); $class->_maybe_reset_handlemoose($target); @@ -59,6 +58,8 @@ sub import { return; }; } + return if $MAKERS{$target}{is_class}; # already exported into this package + $MAKERS{$target}{is_class} = 1; { no strict 'refs'; @{"${target}::ISA"} = do { diff --git a/lib/Moo/Object.pm b/lib/Moo/Object.pm index 421e7aa..5012f79 100644 --- a/lib/Moo/Object.pm +++ b/lib/Moo/Object.pm @@ -69,6 +69,7 @@ sub does { goto &Role::Tiny::does_role; } +# duplicated in Moo::Role sub meta { require Moo::HandleMoose::FakeMetaClass; my $class = ref($_[0])||$_[0]; diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index 0377dd7..6d1b96a 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -23,8 +23,7 @@ sub import { if ($Moo::MAKERS{$target} and $Moo::MAKERS{$target}{is_class}) { die "Cannot import Moo::Role into a Moo class"; } - return if $INFO{$target}; # already exported into this package - $INFO{$target} = { is_role => 1 }; + $INFO{$target} ||= {}; # get symbol table reference my $stash = do { no strict 'refs'; \%{"${target}::"} }; _install_tracked $target => has => sub { @@ -56,6 +55,9 @@ sub import { $me->apply_roles_to_package($target, @_); $me->_maybe_reset_handlemoose($target); }; + return if $INFO{$target}{is_role}; # already exported into this package + $INFO{$target}{is_role} = 1; + *{_getglob("${target}::meta")} = $me->can('meta'); # grab all *non-constant* (stash slot is not a scalarref) subs present # in the symbol table and store their refaddrs (no need to forcibly # inflate constant subs into real subs) - also add '' to here (this @@ -70,6 +72,13 @@ sub import { } } +# duplicate from Moo::Object +sub meta { + require Moo::HandleMoose::FakeMetaClass; + my $class = ref($_[0])||$_[0]; + bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass'); +} + sub unimport { my $target = caller; _unimport_coderefs($target, $INFO{$target}); diff --git a/t/use-after-no.t b/t/use-after-no.t index 5ced7df..5f10e28 100644 --- a/t/use-after-no.t +++ b/t/use-after-no.t @@ -21,17 +21,17 @@ ok eval q{ ok eval q{ package Roller; - use Moo; + use Moo::Role; has foo => ( is => 'ro' ); - no Moo; + no Moo::Role; - use Moo; + use Moo::Role; has foo2 => ( is => 'ro' ); - no Moo; + no Moo::Role; 1; }, "subs imported on 'use Moo::Role;' after 'no Moo::Role;'"