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

    # 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";



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:

    use Hook::Filter::RulePool qw(get_rule_pool);

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.


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.


Remove all rules from the pool and return $pool. All filtered calls will then be allowed by default since the pool is empty.


Return a list of all the rules registered in the pool, as instances of Hook::Filter::Rule.


Hook::Filter::RulePool implements the singleton pattern. Therefore, do not use new() to instantiate a rule pool, use get_rule_pool instead.


$pool->add_rule() croaks if its argument is not an instance of Hook::Filter::Rule or a string.
new() always croaks. Use get_rule_pool instead.


See Hook::Filter, Hook::Filter::Rule, Hook::Filter::Hooker, Hook::Filter::Plugins::Library.


$Id:,v 1.3 2007/05/23 08:26:15 erwan_lemonnier Exp $


Erwan Lemonnier <>


See Hook::Filter.