| 1 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package YAML::Logic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Safe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = "0.07"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our %OPS = map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | qw(eq ne lt gt < > <= >= == =~ like); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 67 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 67 | my($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 67 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | safe => Safe->new(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | template => Template->new(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | error => "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | %options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 67 | $self->{safe}->permit(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 67 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 259 | ▶ | sub interpolate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interpolate: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 259 | my($self, $input, $vars) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 259 | ▶ | if(ref($input) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # When working on the original, we got weird memory errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # in perl5.8, so just copy the hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 34 | my %dupe = %$input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 34 | my @keyvals = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 34 | for my $entry (each %dupe) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 68 | push @keyvals, $self->interpolate( $entry, $vars ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 34 | return { @keyvals }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 225 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 225 | $input =~ s/(?:\$\{([\w.]+)})/[%- $1 %]/gx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 225 | $input =~ s/(?:\$([\w.]+)) /[%- $1 %]/gx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $self->{template}->process( \$input, $vars, \$out ) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 225 | ▶ | LOGDIE $self->{template}->error(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 225 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 91 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=16 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 91 | my($self, $data, $vars, $not_glob, $boolean_or) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 91 | ▶ | $not_glob = 0 unless defined $not_glob; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 91 | ▶ | $boolean_or = 0 unless defined $boolean_or; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | DEBUG sub { "evaluate: " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Dumper( $data ) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | Dumper( $vars ) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | "not_glob=$not_glob " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | "boolean_or=$boolean_or " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 91 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 91 | ▶ | if( ref($data) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 91 | my @data = @$data; # make a copy, so splice() doesn't destroy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # the original. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 91 | ▶ | while( my($field, $value) = splice @data, 0, 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 115 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $not; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 115 | ▶ | if(! defined $field) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | LOGDIE "Rule variable not defined (value=$value)", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | "(maybe YAML rule: !\$var without quotes?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 115 | ▶ | if($field =~ s/^!//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | $not = !$not_glob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 115 | ▶ | if($field eq "or") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 18 | $res = $self->evaluate($value, $vars, $not, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } elsif( $field eq "and") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | $res = $self->evaluate($value, $vars, $not); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 89 | $field = $self->interpolate($field, $vars); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 89 | $value = $self->interpolate($value, $vars); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 89 | ▶ | if(ref($value) eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 55 | $res = $self->evaluate_single( $field, $value, "eq", $not ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif(ref($value) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 34 | my($op) = keys %$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 34 | ($value) = values %$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 34 | $res = $self->evaluate_single( $field, $value, $op, $not ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 114 | ▶ | if($boolean_or and $res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$boolean_or and $res
MC/DC100%2/2
$boolean_or and $res
$boolean_or
$res
Truth table100%3/3
A and B
A= $boolean_orB= $res
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # It's a boolean OR, so all it takes is one true result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 12 | DEBUG "evaluate: rc=$rc"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ▶ | } elsif(!$boolean_or and !$res) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$boolean_or || $res
MC/DC100%2/2
$boolean_or || $res
$boolean_or
$res
Truth table100%3/3
A || B
A= $boolean_orB= $res
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # It's a boolean AND, so all it takes is one false result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 24 | my $rc = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 24 | DEBUG "evaluate: rc=$rc"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 24 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | LOGDIE "Unknown type: $data"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Return 1 if all ANDed conditions succeeded, and 0 if all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # ORed conditions failed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 54 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 54 | ▶ | $rc = 0 if $boolean_or; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 54 | DEBUG "evaluate: rc=$rc"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 54 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 89 | ▶ | sub evaluate_single { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate_single: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 89 | my($self, $field, $value, $op, $not) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 89 | $op = lc $op ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 89 | ▶ | $op = '=~' if $op eq "like"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 89 | $self->error(""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 89 | ▶ | if(! exists $OPS{ $op }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | LOGDIE "Unknown op: $op"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 89 | $field = '"' . esc($field) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 89 | my $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 89 | ▶ | if($op eq "=~") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | if($value =~ /\?\{/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | LOGDIE "Trapped ?{ in regex."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 19 | $value =~ s#(\\\\|/)#\\$1#g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # If we ever get something like \\/, slap another backslash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # onto the "/" to mask it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 19 | ▶ | $value =~ s#(\\+)/# (length($1) % 2) ? "$1/" : "$1\\/"#ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 19 | $value = qr($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 19 | $cmd = "$field =~ /$value/"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 69 | $value = '"' . esc($value) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 69 | $cmd = "$field $op $value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 88 | INFO "Test: $cmd"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 88 | my $res = $self->{safe}->reval($cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 88 | ▶ | if($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | LOGDIE "Evaling [$cmd] failed: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 88 | ▶ | if(!$res and !$not or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
not $res || $not or $res and $not
$res || $not
$res and $not
MC/DC100%4/4
not $res || $not or $res and $not
$res
$not
$res
$not
Truth table57%4/7
not(A || B) or C and D
A= $resB= $notC= $resD= $not
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $res and $not) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 35 | ▶ | $res = "" if !defined $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 35 | $self->error("Test [$cmd] returned [$res]"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 88 | ▶ | return ($not ? (!$res) : $res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 127 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 127 | my($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 127 | ▶ | if(defined $error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 124 | $self->{error} = $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 127 | return $self->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ############################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 158 | ▶ | sub esc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
esc: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ############################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 158 | my($str, $metas) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 158 | $str =~ s/([\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 158 | ▶ | if(defined $metas) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $metas =~ s/\]/\\]/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $str =~ s/([$metas])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 158 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||