« 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$kwargs{"replacement"} and my $replacement = $kwargs{"replacement"}->get_replacement($variable_name)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 2 | $sign = -1; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1773 | ▶ | if( | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6199 | ▶ | while (ref $value eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | 1 | $value = $value->(); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 6317 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"sign"} == -1 and &looks_like_number($value)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | return ( | ||||||||||||||||||||||||||||
| 129 | not $global_safe | ||||||||||||||||||||||||||||
| 130 | 6311 | ▶ | and not $self->{'filter_manager'}->{'safe'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$global_safe || $self->{'filter_manager'}{'safe'}
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'}
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||