Sub::Versive - Subroutine pre- and post-handlers
use Sub::Versive qw(append_to_sub prepend_to_sub builtinify); sub foo { print "Hi there\n"; } append_to_sub { print "Doing foo() now"; } &foo; prepend_to_sub { print "Finished"; } &foo; prepend_to_sub { print "Yes, it's stackable"; } &foo; prepend_to_sub { $@="Hijacked!"; do_something_else() } builtinify &foo; package bar; foo(); # Still works.
The synopsis pretty much tells you all you need to know. You can add pre- and post-actions to subroutines, stack them, have them force a return, and make a subroutine available from everywhere.
I'm sorry, incidentally, that this needs 5.6.1 and above, especially since 5.6.1 isn't released right now. This is because of the prototyping behaviour. If you want to make it work with 5.6.0, zap the prototypes and pass subroutine references instead of subroutine names. I just vastly prefer the syntax, that's all. You'll still need Devel::Peek from 5.6.0, though.
Devel::Peek
None by default, all three functions available.
Simon Cozens, simon@cpan.org
simon@cpan.org
To install Sub::Versive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Versive
CPAN shell
perl -MCPAN -e shell install Sub::Versive
For more information on module installation, please visit the detailed CPAN module installation guide.