|
NAMESub::WrapPackages - add pre- and post-execution wrappers around all the subroutines in packages or around individual subsSYNOPSISuse Sub::WrapPackages packages => [qw(Foo Bar Baz::*)], # wrap all subs in Foo and Bar # and any Baz::* packages subs => [qw(Barf::a, Barf::b)], # wrap these two subs as well wrap_inherited => 1, # and wrap any methods # inherited by Foo, Bar, or # Baz::* except => qr/::w[oi]bble$/, # but don't wrap any sub called # wibble or wobble pre => sub { print "called $_[0] with params ". join(', ', @_[1..$#_])."\n"; }, post => sub { print "$_[0] returned $_[1]\n"; }; COMPATIBILITYWhile this module does broadly the same job as the 1.x versions did, the interface may have changed incompatibly. Sorry. Hopefully it'll be more maintainable and slightly less crazily magical. Also, caller() should now work properly, ignoring wrappings.DESCRIPTIONThis module installs pre- and post- execution subroutines for the subroutines or packages you specify. The pre-execution subroutine is passed the wrapped subroutine's name and all its arguments. The post-execution subroutine is passed the wrapped sub's name and its results.The return values from the pre- and post- subs are ignored, and they are called in the same context (void, scalar or list) as the calling code asked for. Normal usage is to pass a bunch of parameters when the module is used. However, you can also call Sub::WrapPackages::wrapsubs with the same parameters. PARAMETERSEither pass parameters on loading the module, as above, or pass them to ...the wrapsubs subroutine
BUGSAUTOLOAD and DESTROY are not treated as being special. I'm not sure whether they should be or not.If you use wrap_inherited but classes change their inheritance tree at run-time, then very bad things will happen. VERY BAD THINGS. So don't do that. You shouldn't be doing that anyway. Mind you, you shouldn't be doing the things that this module does either. BAD PROGRAMMER, NO BIKKIT! Bug reports should be made on Github or by email. FEEDBACKI like to know who's using my code. All comments, including constructive criticism, are welcome. Please email me.SOURCE CODE REPOSITORY<git://github.com/DrHyde/perl-modules-Sub-WrapPackages.git>COPYRIGHT and LICENCECopyright 2003-2009 David Cantrell <david@cantrell.org.uk>This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. THANKS TOThanks to Tom Hukins for sending in a test case for the situation when a class and a subclass are both defined in the same file, and for prompting me to support inherited methods;to Dagfinn Ilmari Mannsaker for help with the craziness for fiddling with modules that haven't yet been loaded; to Lee Johnson for reporting a bug caused by perl 5.10's constant.pm being Far Too Clever, and providing a patch and test; to Adam Trickett who thought this was a jolly good idea; to Ed Summers, whose code for figgering out what functions a package contains I borrowed out of Acme::Voodoo; and to Yanick Champoux for numerous readability improvements.
Visit the GSP FreeBSD Man Page Interface. |