NAME

Sub::Versive - Subroutine pre- and post-handlers

SYNOPSIS

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.

DESCRIPTION

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.

EXPORT

None by default, all three functions available.

AUTHOR

Simon Cozens, simon@cpan.org