use warnings; use strict; package FooAttr; use Devel::Peek qw(Dump); use B qw(); our @Subs; sub MODIFY_CODE_ATTRIBUTES { my ($pkg, $cref, @attrs) = @_; # Sucks in perl 5.10. Dump($cref); my @bad; for my $attr (@attrs){ if ($attr eq 'FOO') { push @Subs, $cref; } else { push @bad, $attr; } } return @bad; } # Add "FooAttr" to @UNIVERSAL::ISA at *compile-time*. # Otherwise Bar won't find MODIFY_CODE_ATTRIBUTES. BEGIN { push @UNIVERSAL::ISA, __PACKAGE__; } package Bar; use Devel::Peek qw(Dump); # This calls FooAttr::MODIFY_CODE_ATTRIBUTES at *compile-time*. sub baz :FOO {} # Keep in mind this is at runtime. Let's examine the same coderefs! for my $cr (@FooAttr::Subs) { Dump($cr); # This is what Sub::Identify[/Information] does but it # can also use C code to avoid the B module. my $gv = B::svref_2object($cr)->GV; printf "%s::%s\n", $gv->STASH->NAME, $gv->NAME; }