- BUGS AND LIMITATIONS
- SEE ALSO
Hook::Filter::Hooker - Wrap subroutines in a firewalling closure
This module is used internaly by Hook::Filter to generate an anonymous sub that is wrapped around each filtered subroutine and either forwards the call to the subroutine or block it and spoofs return values (undef or an empty list depending on context).
use Hook::Filter::Hooker; my $hooker = new Hook::Filter::Hooker(); $hooker->filter_sub("My::Package"); # mylog is declared in the current package $hooker->filter_sub("mylog");
Hook::Filter::Hooker exports no functions by default. But the following functions can be explicitly imported upon using
Add a filter around the subroutine
$subname. $subname must either be a fully qualified function name, or the name of a function located in the current package.
All calls to
$subnamewill thereafter be redirected to a wrapper closure that will evaluate all the rules registered in
Hook::Filter::RulePoolusing the method
eval()on the pool. If
eval()returns true, the call is forwarded, otherwise it is blocked.
The following class functions are to be used by modules under
Hook::Filter::Plugins:: that implement specific test functions for use in filter rules.
Any use of these functions in a different context than inside a plugin implementation is guaranteed to return only garbage.
Hook::Filter::Plugins::Library for a usage example.
Return the name of the package calling the filtered subroutine.
Return the name of the file calling the filtered subroutine.
Return the line number at which the filtered subroutine was called.
Return the complete name (package+name) of the subroutine calling the filtered subroutine. If the subroutine was called directly from the main namespace, return an empty string.
Return the complete name of the filtered subroutine for which the rules are being eval-ed.
Return the list of arguments that would be passed to the filtered subroutine.
$hook->filter_sub($pkg,$func)croaks when passed invalid arguments.
- The closure wrapping all filtered subroutines emits a perl warning when a rule dies upon being eval-ed.
See Hook::Filter, Hook::Filter::Rule, Hook::Filter::RulePool, Hook::Filter::Plugins::Library.
$Id: Hooker.pm,v 1.8 2007/05/24 14:58:09 erwan_lemonnier Exp $