Sub::WrapPackages

Add pre- and post-execution wrappers around all the subroutines in packages or around individual subs
Download

Sub::WrapPackages Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • David Cantrell
  • Publisher web site:
  • http://search.cpan.org/~dcantrell/

Sub::WrapPackages Tags


Sub::WrapPackages Description

Add pre- and post-execution wrappers around all the subroutines in packages or around individual subs Sub::WrapPackages is a Perl module to add pre- and post-execution wrappers around all the subroutines in packages or around individual subs.SYNOPSIS use Sub::WrapPackages ( packages => , # wrap all Foo::* and Bar::* subs => , # wrap these two subs as well wrap_inherited => 1, # and wrap any methods # inherited by Foo and Bar pre => sub { print "called $_ with params ". join(', ', @_)." "; }, post => sub { print "$_ returned $_ "; },This is mostly a wrapper around Damian Conway's Hook::LexWrap module. Please go and read the docs for that module now. The differences are:no exporting We don't export a wrap() function, instead preferring to do all the magic when you use this module. We just wrap named subroutines, no references. I didn't need that functionality so although it's probably available if you look at the source I haven't tested it. Patches welcome!the subs and packages arrayrefs In the synopsis above, you will see two named parameters, subs and packages. Any subroutine mentioned in subs will be wrapped. Any packages mentioned in packages will have all their subroutines wrapped.wrap_inherited In conjunction with the packages arrayref, this wraps all calls to inherited methods made through those packages. If you call those methods directly in the superclass then they are not affected.parameters passed to your subs I threw Damian's ideas out of the window. Instead, your pre-wrapper will be passed the wrapped subroutine's name, and all the parameters to be passed to it. Who knows what will happen if you modify those params, I don't need that so haven't tested it. Patches welcome! The post-wrapper will be passed the wrapped subroutine's name, and a single parameter for the return value(s) as in Damian's module. Figuring out the difference between returning an array and returning a reference to an array is left as an exercise for the interested reader. Requirements: · Perl


Sub::WrapPackages Related Software