blib/lib/DTL/Fast/Filter/Add.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 77.2% 17 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 81.8% 72 / 88 SCAR 27.5
CC
15
Cov
85%
filter
13.8
parse_parameters
3.2
BEGIN
1.0
CRAP 15.7
« blib/lib/DTL/Fast/Expression/Operator/Binary/Mul.pm ↑ Summary blib/lib/DTL/Fast/Filter/Unorderedlist.pm »
1 package DTL::Fast::Filter::Add;
2 2 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 $DTL::Fast::FILTER_HANDLERS{'add'} = __PACKAGE__;
6  
7 2 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #@Override
10 sub parse_parameters
11 {
12 12 ▶ my $self = shift;
Subroutine parse_parameters: called CC=3 SCAR=11.6
Pod undocumented
13
14 die $self->get_parse_error("no single arguments passed to the add ".__PACKAGE__)
15 if(
16 ref $self->{'parameter'} ne 'ARRAY'
17 12 ▶ or not scalar @{$self->{'parameter'}}
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"parameter"} ne "ARRAY" or not scalar @{$self->{"parameter"};} 0 12 12
Condition33%1/3
ref $self->{"parameter"} ne "ARRAY" or not scalar @{$self->{"parameter"};}
l!l&&r!l&&!r
0012
MC/DC0%0/2
ref $self->{"parameter"} ne "ARRAY" or not scalar @{$self->{"parameter"};}
ref $self->{"parameter"} ne "ARRAY" not scalar @{$self->{"parameter"};}
Truth table33%1/3
A or not(B)
A= ref $self->{"parameter"} ne "ARRAY"B= not scalar @{$self->{"parameter"};}
ABresult
1X1
011
000
18 );
19
20 12 $self->{'parameters'} = [@{$self->{'parameter'}}];
21  
22 12 return $self;
23 }
24  
25 #@Override
26 sub filter
27 {
28 11 ▶ my ($self, $filter_manager, $value, $context) = @_;
Subroutine filter: called CC=13 SCAR=26.3
Pod undocumented
29
30 11 my $result = $value;
31 11 my $value_type = ref $value;
32
33 11 ▶ if( $value_type eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if ($value_type eq 'HASH') { } 1 10 11
elsif ($value_type eq 'ARRAY') { } 5 5 10
elsif ($value_type) { } 0 5 5
34 {
35 1 $result = {%$value};
36 }
37 elsif( $value_type eq 'ARRAY' )
38 {
39 5 $result = [@$value];
40 }
41 elsif( $value_type ) # @todo here we can implement ->add interface
42 {
43 0 die $self->get_render_error("don't know how to add anything to $value_type");
44 }
45
46 11 foreach my $parameter (@{$self->{'parameters'}})
47 {
48 11 my $argument = $parameter->render($context);
49
50 11 my $result_type = ref $result;
51 11 my $argument_type = ref $argument;
52
53 11 ▶ if( $result_type eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if ($result_type eq 'HASH') { } 1 10 11
elsif ($result_type eq 'ARRAY') { } 5 5 10
elsif (&looks_like_number($result) and &looks_like_number($argument)) { } 1 4 5
54 {
55 1 ▶ if( $argument_type eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if ($argument_type eq 'ARRAY') { } 1 0 1
elsif ($argument_type eq 'HASH') { } 0 0 0
56 {
57 1 %$result = (%$result, @$argument);
58 }
59 elsif( $argument_type eq 'HASH' )
60 {
61 0 %$result = (%$result, %$argument);
62 }
63 else
64 {
65 0 die $self->get_render_error("it's not possible to add a single value to a hash");
66 }
67 }
68 elsif( $result_type eq 'ARRAY' )
69 {
70 5 ▶ if( $argument_type eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if ($argument_type eq 'ARRAY') { } 1 4 5
elsif ($argument_type eq 'HASH') { } 1 3 4
71 {
72 1 push @$result, @$argument;
73 }
74 elsif( $argument_type eq 'HASH' )
75 {
76 1 push @$result, (%$argument);
77 }
78 else
79 {
80 3 push @$result, $argument;
81 }
82 }
83 ▶ elsif( looks_like_number($result) and looks_like_number($argument) )
Condition66%2/3
&looks_like_number($result) and &looks_like_number($argument)
!ll&&!rl&&r
401
MC/DC50%1/2
&looks_like_number($result) and &looks_like_number($argument)
&looks_like_number($result) &looks_like_number($argument)
Truth table66%2/3
A and B
A= &looks_like_number($result)B= &looks_like_number($argument)
ABresult
0X0
100
111
84 {
85 1 $result += $argument;
86 }
87 else
88 {
89 4 $result .= $argument;
90 }
91 }
92
93 10 return $result;
94 }
95  
96 2 1;
« blib/lib/DTL/Fast/Expression/Operator/Binary/Mul.pm ↑ Summary blib/lib/DTL/Fast/Filter/Unorderedlist.pm »