Philippe Verdret > HookPrePostCall-1.2 > Hook::PrePostCall

Download:
HookPrePostCall-1.2.tar.gz

Dependencies

Annotate this POD

Related Modules

Apache::SmallProf
Devel::SmallProf
Scalar::Util
more...
By perlmonks.org
View/Report Bugs
Module Version: 1.2   Source  

NAME ^

Hook::PrePostCall - Add actions before and after a routine (alpha 1.2)

SYNOPSIS ^

  require 5.000;
  use Hook::PrePostCall;

  sub try {
    print STDERR "in try: @_\n";
    @_;
  }

  PrePostCall->new(
             'try',
             sub {
               print STDERR "pre: @_\n";
               # process the @_ content...if you want
               @_;              # defines the 'try' arguments
             },
             sub {
               print STDERR "post: @_\n";
               # process the @_ content...if you want
               @_;              # defines what the 'try' returns
             }
            );
  print try(10), "\n";

DESCRIPTION ^

new() creates a new object of the Hook::PrePostCall class. Arguments of the new method are:

1. the name of the primary routine you want to "overload",

2. an anonymous routine to call before the primary routine,

3. an anonumous routine to call after the primary routine.

If the name of the primary subroutine has not an explicit package prefix, it is assumed to be the name of a subroutine in the current package of the caller of the new() method.

The pre routine acts as a filter of the primary routine arguments. The post routine acts as a filter of what the primary returns.

new() can be used as a class or an object method. When used as an object method the derived definition is built from the initial definition of the primary routine.

derived() Returns the overloaded routine.

pre() Returns or set the pre action part.

post() Returns or set the post action part.

primary() Returns the primary routine.

restore() Retore initial definition of the primary routine.

AUTHOR ^

Philippe Verdret, pverdret@sonovision-itep.fr

syntax highlighting: