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 Hook::Filter::Hooker:
Hook::Filter::Hooker
$hooker->filter_sub($subname)
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.
$subname
All calls to $subname will thereafter be redirected to a wrapper closure that will evaluate all the rules registered in Hook::Filter::RulePool using the method eval() on the pool. If eval() returns true, the call is forwarded, otherwise it is blocked.
Hook::Filter::RulePool
eval()
The following class functions are to be used by modules under Hook::Filter::Plugins:: that implement specific test functions for use in filter rules.
Hook::Filter::Plugins::
Any use of these functions in a different context than inside a plugin implementation is guaranteed to return only garbage.
See Hook::Filter::Plugins::Library for a usage example.
Hook::Filter::Plugins::Library
get_caller_package()
Return the name of the package calling the filtered subroutine.
get_caller_file()
Return the name of the file calling the filtered subroutine.
get_caller_line()
Return the line number at which the filtered subroutine was called.
get_caller_subname()
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.
get_subname()
Return the complete name of the filtered subroutine for which the rules are being eval-ed.
get_arguments()
Return the list of arguments that would be passed to the filtered subroutine.
$hook->filter_sub($pkg,$func)
See Hook::Filter
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 $
Erwan Lemonnier <erwan@cpan.org>.
<erwan@cpan.org>
See Hook::Filter.
To install Hook::Filter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hook::Filter
CPAN shell
perl -MCPAN -e shell install Hook::Filter
For more information on module installation, please visit the detailed CPAN module installation guide.