blib/lib/Amon2/Trigger.pm

filter: Statementstmt 100% 49 / 49 Branchbran 87.5% 7 / 8 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 93.8% 76 / 81 CC 10 SCAR 12.0
CC
10
Cov
95%
get_trigger_code
6.1
add_trigger
4.0
call_trigger
2.0
CRAP 3.3
« blib/lib/Amon2/Util.pm ↑ Summary blib/lib/Amon2/Plugin/Web/FillInFormLite.pm »
1 package Amon2::Trigger;
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use parent qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 our @EXPORT = qw/add_trigger call_trigger get_trigger_code/;
9  
10 8 ▶sub add_trigger {
Subroutine add_trigger: called CC=4 SCAR=13.9
Pod documented
11 8 my ($class, %args) = @_;
12  
13 8 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 2 6 8
14 2 ▶ while (my ($hook, $code) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 2 2 4
15 2 push @{$class->{_trigger}->{$hook}}, $code;
16 }
17 } else {
18 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ while (my ($hook, $code) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 7 6 13
20 7 push @{${"${class}::_trigger"}->{$hook}}, $code;
21 }
22 }
23 }
24  
25 8 ▶sub call_trigger {
Subroutine call_trigger: called CC=2 SCAR=6.9
Pod documented
26 8 my ($class, $hook, @args) = @_;
27 8 my @code = $class->get_trigger_code($hook);
28 8 for my $code (@code) {
29 6 $code->($class, @args);
30 }
31 }
32  
33 12 ▶sub get_trigger_code {
Subroutine get_trigger_code: called CC=6 SCAR=18.0
Pod documented
34 12 my ($class, $hook) = @_;
35 12 my @code;
36 12 ▶ if (Scalar::Util::blessed($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($class)) 12 0 12
37 12 ▶ push @code, @{ $class->{_trigger}->{$hook} || [] };
Condition100%2/2
$class->{'_trigger'}{$hook} || []
l!l
210
MC/DC100%1/1
$class->{'_trigger'}{$hook} || []
$class->{'_trigger'}{$hook}
Truth table100%2/2
A
A= $class->{'_trigger'}{$hook}
Aresult
11
00
38 12 $class = ref $class;
39 }
40 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 12 ▶ my $klass = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
42 12 for (@{mro::get_linear_isa($class)}) {
43 29 ▶ push @code, @{${"${_}::_trigger"}->{$hook} || []};
Condition100%2/2
${"${_}::_trigger";}->{$hook} || []
l!l
821
MC/DC100%1/1
${"${_}::_trigger";}->{$hook} || []
${"${_}::_trigger";}->{$hook}
Truth table100%2/2
A
A= ${"${_}::_trigger";}->{$hook}
Aresult
11
00
44 }
45 12 return @code;
46 }
47  
48 17 1;
49 __END__
« blib/lib/Amon2/Util.pm ↑ Summary blib/lib/Amon2/Plugin/Web/FillInFormLite.pm »