Simon Cozens > Sub-Versive-0.01 > Sub::Versive

Download:
Sub-Versive-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.01   Source  

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

syntax highlighting: