package Attribute::Scary; use Attribute::Handlers; our %lookup; sub import { # put $self into the calling package my $caller = caller() . "::self"; *{$caller} = \$$caller; # well this is somewhat pointless $caller = caller(); *{"$caller\::spacey 0"} = sub { "Bob" }; *{"$caller\::spacey 1"} = sub { "Hello, Bob!\n" }; } sub UNIVERSAL::Method :ATTR(CODE) { my ($package, $symbol, $referent) = @_; my $name = "$package\::" . *{$symbol}{NAME}; $lookup{$name} = $referent; eval " no warnings 'redefine'; *$name = sub { package $package; local \$self = shift; &{\$Attribute::Scary::lookup{'$name'}}; } "; } 1;