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
}
$pool->flush_rules;
DESCRIPTION
Hook::Filter::RulePool contains all the filtering rules eval-ed when 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 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.$rule
must be an instance of Hook::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. All filtered calls will then be allowed by default.
- $pool->get_rules()
-
Return a list of all the rules registered in the pool, as strings.
- new()
-
Hook::Filter::RulePool follows the singleton pattern. Therefore, do not use
new()
to instantiate a rule pool, useget_rule_pool
instead.
DIAGNOSTICS
SEE ALSO
See Hook::Filter, Hook::Filter::Rule.
VERSION
$Id: RulePool.pm,v 1.1 2007/05/16 13:31:36 erwan_lemonnier Exp $
AUTHOR
Erwan Lemonnier <erwan@cpan.org>
LICENSE
See Hook::Filter.