Plagger/Rules.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 45 CC 4 SCAR 23.0
CC
4
Cov
0%
dispatch
20.0
new
2.0
id
2.0
CRAP 10.0
1 package Plagger::Rules;
2 use strict;
3 use Plagger::Operator;
4  
5 sub new {
6 my($class, $op, @rules) = @_;
7 Plagger::Operator->is_valid_op(uc($op))
8 or Plagger->context->error("operator $op not supported");
9  
10 bless {
11 op => uc($op),
12 rules => [ map Plagger::Rule->new($_), @rules ],
13 }, $class;
14 }
15  
16 sub dispatch {
17 my($self, $plugin, $hook, $args) = @_;
18  
19 return 1 unless $plugin->dispatch_rule_on($hook);
20  
21 my @bool;
22 for my $rule (@{ $self->{rules} }) {
23 push @bool, ($rule->dispatch($args) ? 1 : 0);
24 }
25  
26 # can't find rules for this phase: execute it
27 return 1 unless @bool;
28  
29 Plagger::Operator->call($self->{op}, @bool);
30 }
31  
32 sub id {
33 my $self = shift;
34 join '|', map $_->id, @{$self->{rules}};
35 }
36  
37 sub as_title {
38 my $self = shift;
39 join " $self->{op} ", map $_->as_title, @{$self->{rules}};
40 }
41  
42 1;