blib/lib/DTL/Fast/Variable.pm

filter: Statementstmt 91.7% 67 / 73 Branchbran 100% 28 / 28 Conditioncond 80.0% 12 / 15 MC/DCmcdc 70.0% 7 / 10 Subroutinesub 78.5% 11 / 14 Podpod 0.0% 0 / 3 totaltotal 87.4% 125 / 143 SCAR 30.1
CC
20
Cov
92%
new
11.0
render
10.0
__ANON__
2.0
CRAP 20.2
« blib/lib/DTL/Fast/Expression/Operator/Binary/Minus.pm ↑ Summary blib/lib/DTL/Fast/Cache/Compressed.pm »
1 package DTL::Fast::Variable;
2 98 ▶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 98 ▶use parent 'DTL::Fast::Replacer';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 98 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 98 ▶use DTL::Fast::FilterManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 98 ▶use DTL::Fast::Utils qw(as_bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 98 ▶use DTL::Fast::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new
11 {
12 1773 ▶ my( $proto, $variable, %kwargs ) = @_;
Subroutine new: called CC=11 SCAR=24.0
Pod undocumented
13  
14 1773 ▶ $proto = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
017730
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
15
16 1773 $variable =~ s/(^\s+|\s+$)//gsi;
17 1773 my @filters = split /\s*\|+\s*/, $variable;
18
19 1773 my $variable_name = shift @filters;
20
21 1773 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($kwargs{"replacement"} and my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)) 7 1766 1773
Condition100%3/3
$kwargs{"replacement"} and my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)
!ll&&!rl&&r
9887787
MC/DC100%2/2
$kwargs{"replacement"} and my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)
$kwargs{"replacement"} my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)
Truth table100%3/3
A and B
A= $kwargs{"replacement"}B= my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)
ABresult
0X0
100
111
22 $kwargs{'replacement'}
23 and my $replacement = $kwargs{'replacement'}->get_replacement($variable_name)
24 )
25 {
26 7 $variable_name = $replacement->{'original'}; # got stored string
27 }
28
29 1773 my @variable;
30 1773 my $static = 0;
31 1773 my $sign = 1;
32 1773 my $undef = 0;
33
34 1773 ▶ if( $variable_name =~ s/^\-// )
Branch: 1 branch
BranchTrueFalseTotal
if ($variable_name =~ s/^\-//) 2 1771 1773
35 {
36 2 $sign = -1;
37 }
38
39 1773 ▶ if(
Branch: 3 branches
BranchTrueFalseTotal
if ($variable_name =~ /^(?<!\\)(["'])(.*?)(?<!\\)\1$/) { } 299 1474 1773
elsif ($variable_name eq 'undef' or $variable_name eq 'None') { } 67 1407 1474
elsif (&looks_like_number($variable_name)) { } 368 1039 1407
40 $variable_name =~ /^(?<!\\)(["'])(.*?)(?<!\\)\1$/
41 )
42 {
43 299 @variable = ($2);
44 299 $static = 1;
45 299 $sign = 1;
46 }
47 ▶ elsif(
Condition100%3/3
$variable_name eq "undef" or $variable_name eq "None"
l!l&&r!l&&!r
6161407
MC/DC100%2/2
$variable_name eq "undef" or $variable_name eq "None"
$variable_name eq "undef" $variable_name eq "None"
Truth table100%3/3
A or B
A= $variable_name eq "undef"B= $variable_name eq "None"
ABresult
1X1
011
000
48 $variable_name eq 'undef'
49 or $variable_name eq 'None' # python compatibility
50 )
51 {
52 67 $static = 1;
53 67 $sign = 1;
54 67 $undef = 1;
55 67 @variable = (undef);
56 }
57 elsif( looks_like_number($variable_name) )
58 {
59 368 @variable = ($variable_name);
60 368 $static = 1;
61 }
62 else
63 {
64 1039 ▶ if ( $variable_name =~ /[^\w\-\.]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($variable_name =~ /[^\w\-\.]/) 1 1038 1039
65 {
66 1 die $proto->get_parse_error(
67 "variable `$variable_name` contains incorrect symbols (not /alphanumeric/-/_/./ )"
68 , 'Possible reasons' => <<'_EOM_'
69 typo in variable name
70 typo in logical operator `=` instead of `==`, for example
71 _EOM_
72 );
73 }
74 1038 @variable = split /\.+/, $variable_name;
75 }
76
77 my $self = $proto->SUPER::new(
78 'variable' => [@variable]
79 , 'original' => $variable
80 , 'direct_read' => ( scalar @variable == 1 )
81 , 'sign' => $sign
82 , 'undef' => $undef
83 , 'static' => $static
84 1772 , 'filter_manager' => DTL::Fast::FilterManager->new('replacement' => $kwargs{'replacement'})
85 );
86  
87 1772 ▶ if( scalar @filters )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @filters) 463 1309 1772
88 {
89 463 $self->{'filter_manager'}->add_filters(\@filters);
90 }
91  
92 1771 return $self;
93 }
94  
95 1 ▶sub add_filter{ return shift->{'filter_manager'}->add_filter(shift); }
Subroutine add_filter: called CC=1 SCAR=0.0
Pod undocumented
96  
97 sub render
98 {
99 6321 ▶ my( $self, $context, $global_safe ) = @_;
Subroutine render: called CC=10 SCAR=23.0
Pod undocumented
100
101 6321 my $value = undef;
102
103 6321 ▶ if( not $self->{'undef'} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"undef"}) 6203 118 6321
104 {
105 $value = $self->{'static'}
106 ? $self->{'variable'}->[0]
107 : $self->{'direct_read'}
108 ? $context->{'ns'}->[-1]->{$self->{'variable'}->[0]}
109 6203 ▶ : $context->get($self->{'variable'}, $self);
Branch: 2 branches
BranchTrueFalseTotal
$self->{'static'} ? : 1704 4499 6203
$self->{'direct_read'} ? : 4251 248 4499
110
111 6199 ▶ while (ref $value eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "CODE") 1 6199 6200
112 {
113 1 $value = $value->();
114 }
115 }
116
117 6317 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sign"} == -1 and &looks_like_number($value)) 2 6315 6317
Condition66%2/3
$self->{"sign"} == -1 and &looks_like_number($value)
!ll&&!rl&&r
631502
MC/DC50%1/2
$self->{"sign"} == -1 and &looks_like_number($value)
$self->{"sign"} == -1 &looks_like_number($value)
Truth table66%2/3
A and B
A= $self->{"sign"} == -1B= &looks_like_number($value)
ABresult
0X0
100
111
118 $self->{'sign'} == -1
119 and looks_like_number $value
120 )
121 {
122 2 $value = -$value;
123 }
124
125 $value = $self->{'filter_manager'}->filter($value, $context)
126 6317 ▶ if $self->{'filter_manager'}->{'filters_number'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filter_manager"}{"filters_number"} 467 5850 6317
127
128 return (
129 not $global_safe
130 6311 ▶ and not $self->{'filter_manager'}->{'safe'}
Branch: 1 branch
BranchTrueFalseTotal
!($global_safe || $self->{'filter_manager'}{'safe'}) ? : 2297 4014 6311
Condition100%3/3
$global_safe || $self->{'filter_manager'}{'safe'}
l!l&&r!l&&!r
3951632297
MC/DC100%2/2
$global_safe || $self->{'filter_manager'}{'safe'}
$global_safe $self->{'filter_manager'}{'safe'}
Truth table100%3/3
A || B
A= $global_safeB= $self->{'filter_manager'}{'safe'}
ABresult
1X1
011
000
131 )
132 ? DTL::Fast::html_protect($value)
133 : $value;
134 }
135  
136 our $BOOL_PROCESSORS = {
137 'SCALAR' => sub
138 {
139 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 0 return $$value;
141 }
142 , 'HASH' => sub
143 {
144 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 0 return scalar keys(%$value);
146 }
147 , 'ARRAY' => sub
148 {
149 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 0 return scalar @$value;
151 }
152 98 };
153  
154 98 1;
« blib/lib/DTL/Fast/Expression/Operator/Binary/Minus.pm ↑ Summary blib/lib/DTL/Fast/Cache/Compressed.pm »