package Foo; use strict; use Attribute::Handlers; sub import { my $pkg = (caller)[0]; eval <<"_code_"; sub ${pkg}::Sorted :ATTR { print "all sorted" } _code_ } 1; #### #!/usr/bin/perl use strict; use warnings; use Foo; $\="\n"; my $tst2 :Sorted; print "done\n" #### package Foo; use strict; use Attribute::Handlers; sub import { my $src_pkg=__PACKAGE__; my $dest_pkg = (caller)[0]; my $import = "sub ${dest_pkg}::Sorted :ATTR { goto \&${src_pkg}::Sorted }"; eval $import; } sub Sorted { print "all sorted" } 1;