Attribute::Method is relying on a B::Deparse bug to accomplish its work.
What it is doing is a bit hacky, and has never worked properly with fully-qualified variables
named $Foo::self or lexical variables outside the subroutine.
Attached is a patch that adds another hack to make it work just as well in 5.16, but still with the
same problems it has always had.
This new hack is fragile, and may need to be changed for each major Perl version.
diff -Nurp Attribute-Util-1.06-iYcn99-orig/lib/Attribute/Method.pm Attribute-Util-1.06-iYcn99/lib/Attribute/Method.pm
--- Attribute-Util-1.06-iYcn99-orig/lib/Attribute/Method.pm 2009-05-27 04:36:08.000000000 -0700
+++ Attribute-Util-1.06-iYcn99/lib/Attribute/Method.pm 2012-01-24 21:54:26.000000000 -0800
@@ -7,7 +7,8 @@ use B::Deparse;
our $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;
-my $dp = B::Deparse->new('-l');
+my $dp = Attribute::Method::_Deparse->new('-l');
+my $dppack;
my %sigil2ref = (
'$' => \undef,
'@' => [],
@@ -27,6 +28,7 @@ sub import {
sub UNIVERSAL::Method : ATTR(RAWDATA) {
my ( $pkg, $sym, $ref, undef, $args ) = @_;
+ $dppack = $pkg;
my $src = $dp->coderef2text($ref);
if ($args) {
$src =~ s/\{/{\nmy \$self = shift; my ($args) = \@_;\n/;
@@ -39,6 +41,18 @@ sub UNIVERSAL::Method : ATTR(RAWDATA) {
eval qq{ package $pkg; sub $sub_name $src };
}
+package
+ Attribute::Method::_Deparse;
+
+BEGIN { our @ISA = 'B::Deparse' }
+
+sub maybe_qualify {
+ my $ret = SUPER::maybe_qualify{@_};
+ my ($pack,$name) = $ret =~ /(.*)::(.+)/;
+ length $pack && $pack eq $dppack and return $name;
+ $ret;
+}
+
"Rosebud"; # for MARCEL's sake, not 1 -- dankogai
__END__