Hook::Filter::Plugin::Library - Usefull functions for writing filter rules
A library of functions usefull when writing filter rules. Those functions should be used inside Hook::Filter rules, and nowhere else.
Hook::Filter
Exemples of rules using test functions from Hook::Filter::Plugin::Location:
Hook::Filter::Plugin::Location
# allow all subroutine calls made from inside function 'do_this' from package 'main' from =~ /main::do:this/ # the opposite from !~ /main::do:this/ # the called subroutine matches a given name subname =~ /foobar/ # the 2nd argument of passed to the subroutine is a string matching 'bob' defined arg(1) && arg(1) =~ /bob/
The following functions are only exported into Hook::Filter::Rule and shall only be used inside filter rules.
Hook::Filter::Rule
from
Return the fully qualified name of the caller of the filtered subroutine.
Example:
use Hook::Filter hook => 'foo'; use Hook::Filter::RulePool qw(get_rule_pool); sub foo {} sub bar1 { foo; } sub bar2 { foo; } # add a rule to allow only calls to foo from within bar1 and bar2: get_rule_pool->add_rule("from =~ /bar\d$/"); foo(); # foo is not called bar1(); # foo is called bar2(); # foo is called
subname
Return the fully qualified name of the filtered subroutine being called.
use Hook::Filter hook => [ 'foo', 'bar' ]; use Hook::Filter::RulePool qw(get_rule_pool); sub foo {}; sub bar {}; # add a rule to allow only calls to foo: get_rule_pool->add_rule("subname eq 'main::foo'"); foo(); # foo is called bar(); # bar is not called
arg($pos)
Return the argument at position $pos in the list of arguments to be passed to the filtered subroutine.
$pos
use Hook::Filter hook => 'debug'; sub debug { print $_[1]."\n" if ($_[0] <= $VERBOSITY); } # allow calls to debug only if the text matches the name 'bob' get_rule_pool->add_rule("arg(1) =~ /bob/"); debug(1,"bob did that"); # debug is called debug(3,"david thinks this"); # debug is not called
Like all plugins under Hook::Filter::Plugins, Hook::Filter::Plugins::Library implements the class method register():
Hook::Filter::Plugins
Hook::Filter::Plugins::Library
register()
Return the names of the test functions implemented in Hook::Filter::Plugins::Location. Used internally by Hook::Filter::Rule.
Hook::Filter::Plugins::Location
No diagnostics. Any bug in those test functions would cause a warning emitted by Hook::Filter::Rule::eval().
Hook::Filter::Rule::eval()
See Hook::Filter
See Hook::Filter, Hook::Filter::Rule, Hook::Filter::RulePool, Hook::Filter::Hooker.
$Id: Library.pm,v 1.4 2007/05/24 14:52:37 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.