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_pool
is 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
$rule
to the pool and return$pool
.$rule
must 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::RulePool
implements the singleton pattern. Therefore, do not usenew()
to instantiate a rule pool, useget_rule_pool
instead.
DIAGNOSTICS
$pool->add_rule()
croaks if its argument is not an instance ofHook::Filter::Rule
or a string.new()
always croaks. Useget_rule_pool
instead.
SEE ALSO
See Hook::Filter, Hook::Filter::Rule, Hook::Filter::Hooker, Hook::Filter::Plugins::Library.
VERSION
$Id: RulePool.pm,v 1.3 2007/05/23 08:26:15 erwan_lemonnier Exp $
AUTHOR
Erwan Lemonnier <erwan@cpan.org>
LICENSE
See Hook::Filter.