http://www.perlmonks.org?node_id=378953


in reply to Package level scope callbacks.

The only thing I can think of (and it's not pretty) is to do something like
BEGIN{ %SomePackage::copy:: = %SomePackage::; %SomePackage:: = (); # actually, you should probably only move the subs # and leave the variables etc where they are. } package SomePackage; sub AUTOLOAD { # in here check caller() to see if you're crossing # package boundaries and then call the pre-function # wrappers and then call the real function, paying # attention to wantarry etc then call the post-function # then return the data }
slow, ugly, complicated but it should do what you want.