Hook::Filter::RulePool - A pool of filter rules
use Hook::Filter::RulePool qw(get_rule_pool); my $pool = get_rule_pool(); # add a rule that is always true $pool->add_rule("1"); # add a more complex rule $pool->add_rule("arg(0) =~ /bob/ && from =~ /my_module/"); if ($pool->eval_rules) { # call is allowed } foreach my $rule ($pool->get_rules) { print "pool has rule [$rule]\n"; } $pool->flush_rules;
Hook::Filter::RulePool contains all the filtering rules that should be eval-ed each time a filtered subroutine is called.
Using Hook::Filter::RulePool, you can modify the filtering rules at runtime. You can flush all rules or inject new ones.
my $pool = get_rule_pool();
Return the pool containing all known filtering rules. get_rule_pool is not exported by default so you have to import it explicitly:
get_rule_pool
use Hook::Filter::RulePool qw(get_rule_pool);
$pool->eval_rules()
Evaluate all the rules in the pool. If one evaluates to true, return true. If one of them dies/croaks/confesses, return true. If none evaluates to true, return false. If the pool contained no rules, return true.
$pool->add_rule($rule)
Add the rule $rule to the pool and return $pool. $rule must be an instance of Hook::Filter::Rule, or a string representing valid perl code that evaluates to either true or false.
$rule
$pool
Hook::Filter::Rule
$pool->flush_rules()
Remove all rules from the pool and return $pool. All filtered calls will then be allowed by default since the pool is empty.
$pool->get_rules()
Return a list of all the rules registered in the pool, as instances of Hook::Filter::Rule.
new()
Hook::Filter::RulePool implements the singleton pattern. Therefore, do not use new() to instantiate a rule pool, use get_rule_pool instead.
Hook::Filter::RulePool
$pool->add_rule()
See Hook::Filter, Hook::Filter::Rule, Hook::Filter::Hooker, Hook::Filter::Plugins::Library.
$Id: RulePool.pm,v 1.3 2007/05/23 08:26:15 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.