X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoo%2FRole.pm;fp=lib%2FMoo%2FRole.pm;h=6d1b96aec860c5fda524bbab06bce78dae086f4b;hb=fa93bfb29cca2d07be28c8459e1626a59a80245c;hp=0377dd712cde5f4e57935a8ca5823e4aaa6b220d;hpb=bfe18b3563f95fcf48e463112850f046b47c6938;p=gitmo%2FMoo.git 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});