NAME
Hook::Filter::RulePool - A pool of filter rules
SYNOPSIS
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;
DESCRIPTION
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.
INTERFACE
- my $pool = get_rule_pool();
-
Return the pool containing all known filtering rules.
get_rule_poolis not exported by default so you have to import it explicitly: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
$ruleto the pool and return$pool.$rulemust be an instance ofHook::Filter::Rule, or a string representing valid perl code that evaluates to either true or false. - $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::RulePoolimplements the singleton pattern. Therefore, do not usenew()to instantiate a rule pool, useget_rule_poolinstead.
DIAGNOSTICS
$pool->add_rule()croaks if its argument is not an instance ofHook::Filter::Ruleor a string.new()always croaks. Useget_rule_poolinstead.
SEE ALSO
See Hook::Filter, Hook::Filter::Rule.
VERSION
$Id: RulePool.pm,v 1.2 2007/05/22 15:43:02 erwan_lemonnier Exp $
AUTHOR
Erwan Lemonnier <erwan@cpan.org>
LICENSE
See Hook::Filter.