From: Matt S Trout Date: Sun, 6 Nov 2011 20:38:41 +0000 (+0000) Subject: fix bug where constants containing a reference weren't handled correctly X-Git-Tag: v0.009012~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2f57f81a03d838deea37db1d3ba2ea6c3083d070;p=gitmo%2FMoo.git fix bug where constants containing a reference weren't handled correctly --- diff --git a/Changes b/Changes index 28021c1..5a79991 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,6 @@ + - fix bug where constants containing a reference weren't handled correctly + (ref(\[]) is 'REF' not 'SCALAR') + 0.009011 - 2011-10-03 - add support for DEMOLISH - add support for BUILDARGS diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index 11f5778..45d8b03 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -43,12 +43,12 @@ sub import { die "Only one role supported at a time by with" if @_ > 1; $me->apply_role_to_package($target, $_[0]); }; - # grab all *non-constant* (ref eq 'SCALAR') subs present + # grab all *non-constant* (ref eq 'SCALAR'/'REF') 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 # is used later) @{$INFO{$target}{not_methods}={}}{ - '', map { *$_{CODE}||() } grep !(ref eq 'SCALAR'), values %$stash + '', map { *$_{CODE}||() } grep !(ref =~ /^(?:SCALAR|REF)$/), values %$stash } = (); # a role does itself $APPLIED_TO{$target} = { $target => undef }; @@ -177,7 +177,7 @@ sub _concrete_methods_of { my $code = *{$stash->{$_}}{CODE}; # rely on the '' key we added in import for "no code here" exists $not_methods->{$code||''} ? () : ($_ => $code) - } grep !(ref($stash->{$_}) eq 'SCALAR'), keys %$stash + } grep !(ref($stash->{$_}) =~ /^(?:SCALAR|REF)$/), keys %$stash }; }; } @@ -201,7 +201,7 @@ sub _install_methods { # determine already extant methods of target my %has_methods; @has_methods{grep - +((ref($stash->{$_}) eq 'SCALAR') || (*{$stash->{$_}}{CODE})), + +((ref($stash->{$_}) =~ /^(?:SCALAR|REF)$/) || (*{$stash->{$_}}{CODE})), keys %$stash } = (); diff --git a/t/role-tiny.t b/t/role-tiny.t index 69ee7ef..7bbe99c 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -19,6 +19,9 @@ BEGIN { BEGIN { package MyClass; + use constant SIMPLE => 'simple'; + use constant REF_CONST => [ 'ref_const' ]; + sub req1 { } sub req2 { } sub foo { 'class foo' }