File Coverage

blib/lib/Hook/Modular/Operator.pm
Criterion Covered Total %
statement 21 22 95.4
branch 1 2 50.0
condition n/a
subroutine 7 8 87.5
pod 2 2 100.0
total 31 34 91.1


line stmt bran cond sub pod time code
1 10     10   173 use 5.008;
  10         39  
  10         426  
2 10     10   114 use strict;
  10         21  
  10         337  
3 10     10   77 use warnings;
  10         30  
  10         536  
4              
5             package Hook::Modular::Operator;
6             BEGIN {
7 10     10   450 $Hook::Modular::Operator::VERSION = '1.101050';
8             }
9             # ABSTRACT: Boolean operators for plugins
10 10     10   69 use List::Util qw(reduce);
  10         20  
  10         5191  
11             our %Ops = (
12             AND => [ sub { $_[0] && $_[1] } ],
13             OR => [ sub { $_[0] || $_[1] } ],
14             XOR => [ sub { $_[0] xor $_[1] } ],
15             NAND => [ sub { $_[0] && $_[1] }, 1 ],
16             NOT => [ sub { $_[0] && $_[1] }, 1 ], # alias of NAND
17             NOR => [ sub { $_[0] || $_[1] }, 1 ],
18             );
19              
20             sub is_valid_op {
21 6     6 1 11 shift; # we don't need the class
22 6         9 my $op = shift;
23 6         32 exists $Ops{$op};
24             }
25              
26             sub call {
27 8     8 1 12 shift; # we don't need the class
28 8         19 my ($op, @bool) = @_;
29 8     0   1003 my $bool = reduce { $Ops{$op}->[0]->($a, $b) } @bool;
  0         0  
30 8 50       48 $bool = !$bool if $Ops{$op}->[1];
31 8         46 $bool;
32             }
33             1;
34              
35              
36             __END__