blib/lib/Langertha/Holmgang/Expectation.pm

filter: Statementstmt 54.4% 165 / 303 Branchbran 48.0% 146 / 304 Conditioncond 41.2% 89 / 216 MC/DCmcdc 34.7% 41 / 118 Subroutinesub 60.6% 20 / 33 Podpod 100% 20 / 20 totaltotal 48.3% 481 / 994 CC 239 SCAR 53.0
CC
239
Cov
49%
check_value
472.1
check_value
472.1
same_scalar
61.9
CRAP 200.7
« blib/lib/Langertha/Holmgang/Sim/Linux/Postgres.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Nft.pm »
1 package Langertha::Holmgang::Expectation;
2 # ABSTRACT: The expectations on a value, shared by rules, when conditions and check.expect
3  
4 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 54 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 54 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 54 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 54 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 54 our $VERSION = '0.001';
14  
15 54 our @EXPORT_OK = qw( condition check_value element_match path get flat same_scalar near interp_text filter_value );
16  
17 # the expectations, in the order they are checked; a true constant
18 54 our @MATCHERS = qw( exists absent equals in regex contains excludes length any none before );
19  
20 # keys that qualify a matcher and are no expectation of their own; a true constant
21 54 our @MODIFIERS = qw( tolerance );
22  
23 54 my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 );
24  
25  
26  
27 4911 ▶sub path {
Subroutine path: called CC=3 SCAR=14.2
Pod documented
28 0 ▶ my ( $p, $args ) = @_;
Subroutine path: not called CC=3 SCAR=14.2
Pod documented
29 0 ▶ my @seg = ref $p eq 'ARRAY' ? @$p : split /\./, $p;
Branch: 2 branches
BranchTrueFalseTotal
ref $p eq 'ARRAY' ? : 435 4476 4911
ref $p eq 'ARRAY' ? : 0 0 0
30 0 ▶ croak 'empty path' unless @seg;
Branch: 2 branches
BranchTrueFalseTotal
unless @seg 1 4910 4911
unless @seg 0 0 0
31 0 return map { interp_text( "$_", $args ) } @seg;
32 }
33  
34  
35 3068 ▶sub get {
Subroutine get: called CC=10 SCAR=32.3
Pod documented
36 0 ▶ my ( $d, @seg ) = @_;
Subroutine get: not called CC=10 SCAR=32.3
Pod documented
37 0 for my $k (@seg) {
38 0 ▶ next if defined $d && !ref $d && $k eq 'content'; # file as bare text
Branch: 2 branches
BranchTrueFalseTotal
if defined $d and not ref $d and $k eq "content" 332 6102 6434
if defined $d and not ref $d and $k eq "content" 0 0 0
Condition41%5/12
defined $d and not ref $d and $k eq "content"
!ll&&!rl&&r
61011332
defined $d and not ref $d
!ll&&!rl&&r
06101333
defined $d and not ref $d and $k eq "content"
!ll&&!rl&&r
000
defined $d and not ref $d
!ll&&!rl&&r
000
MC/DC66%2/3
defined $d and not ref $d and $k eq "content"
defined $d not ref $d $k eq "content"
MC/DC0%0/3
defined $d and not ref $d and $k eq "content"
defined $d not ref $d $k eq "content"
Truth table75%3/4
A and not(B) and C
A= defined $dB= not ref $dC= $k eq "content"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $dB= not ref $dC= $k eq "content"
ABCresult
0XX0
10X0
1100
1111
39 0 ▶ if ( ref $d eq 'HASH' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $d eq 'HASH') { } 6098 4 6102
elsif (ref $d eq 'ARRAY') { } 3 1 4
if (ref $d eq 'HASH') { } 0 0 0
elsif (ref $d eq 'ARRAY') { } 0 0 0
40 0 ▶ return (0) unless exists $d->{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $d->{$k} 93 6005 6098
unless exists $d->{$k} 0 0 0
41 0 $d = $d->{$k};
42 }
43 elsif ( ref $d eq 'ARRAY' ) {
44 0 ▶ return (0) unless $k =~ /\A\d+\z/ && $k < @$d;
Branch: 2 branches
BranchTrueFalseTotal
unless $k =~ /\A\d+\z/ and $k < @$d 1 2 3
unless $k =~ /\A\d+\z/ and $k < @$d 0 0 0
Condition33%2/6
$k =~ /\A\d+\z/ and $k < @$d
!ll&&!rl&&r
012
$k =~ /\A\d+\z/ and $k < @$d
!ll&&!rl&&r
000
MC/DC50%1/2
$k =~ /\A\d+\z/ and $k < @$d
$k =~ /\A\d+\z/ $k < @$d
MC/DC0%0/2
$k =~ /\A\d+\z/ and $k < @$d
$k =~ /\A\d+\z/ $k < @$d
Truth table66%2/3
A and B
A= $k =~ /\A\d+\z/B= $k < @$d
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $k =~ /\A\d+\z/B= $k < @$d
ABresult
0X0
100
111
45 0 $d = $d->[$k];
46 }
47 0 else { return (0) }
48 }
49 0 return ( 1, $d );
50 }
51  
52  
53 1074 ▶sub flat {
Subroutine flat: called CC=7 SCAR=26.5
Pod documented
54 0 ▶ my ( $v ) = @_;
Subroutine flat: not called CC=7 SCAR=26.5
Pod documented
55 0 ▶ return undef unless defined $v;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v 1 1073 1074
unless defined $v 0 0 0
56 0 ▶ return join( ',', map { $_ // '' } @$v ) if ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "ARRAY" 2 1071 1073
if ref $v eq "ARRAY" 0 0 0
Condition50%2/4
$_ // ""
l!l
41
$_ // ""
l!l
00
MC/DC100%1/1
$_ // ""
$_
MC/DC0%0/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
Truth table0%0/2
A
A= $_
Aresult
11
00
57 0 ▶ return $v ? 'true' : 'false' if JSON::MaybeXS::is_bool($v);
Branch: 4 branches
BranchTrueFalseTotal
if JSON::MaybeXS::is_bool($v) 1 1070 1071
$v ? : 1 0 1
if JSON::MaybeXS::is_bool($v) 0 0 0
$v ? : 0 0 0
58 0 ▶ return ref $v ? $JSON->encode($v) : "$v";
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? : 1 1069 1070
ref $v ? : 0 0 0
59 }
60  
61  
62 9627 ▶sub interp_text {
Subroutine interp_text: called CC=2 SCAR=9.2
Pod documented
63 0 ▶ my ( $s, $args ) = @_;
Subroutine interp_text: not called CC=2 SCAR=9.2
Pod documented
64 0 ▶ $s =~ s/\{([A-Za-z_][A-Za-z0-9_]*)(?:\|([a-z]+))?\}/flat( filter_value( $args->{$1}, $2 ) ) \/\/ ''/ge;
Condition50%2/4
flat(filter_value($args->{$1}, $2)) // ""
l!l
3651
flat(filter_value($args->{$1}, $2)) // ""
l!l
00
MC/DC100%1/1
flat(filter_value($args->{$1}, $2)) // ""
flat(filter_value($args->{$1}, $2))
MC/DC0%0/1
flat(filter_value($args->{$1}, $2)) // ""
flat(filter_value($args->{$1}, $2))
Truth table100%2/2
A
A= flat(filter_value($args->{$1}, $2))
Aresult
11
00
Truth table0%0/2
A
A= flat(filter_value($args->{$1}, $2))
Aresult
11
00
65 0 return $s;
66 }
67  
68  
69 2029 ▶sub filter_value {
Subroutine filter_value: called CC=9 SCAR=30.1
Pod documented
70 0 ▶ my ( $v, $f ) = @_;
Subroutine filter_value: not called CC=9 SCAR=30.1
Pod documented
71 0 ▶ return $v unless defined $f && defined $v;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $f and defined $v 1639 390 2029
unless defined $f and defined $v 0 0 0
Condition50%3/6
defined $f and defined $v
!ll&&!rl&&r
16372390
defined $f and defined $v
!ll&&!rl&&r
000
MC/DC100%2/2
defined $f and defined $v
defined $f defined $v
MC/DC0%0/2
defined $f and defined $v
defined $f defined $v
Truth table100%3/3
A and B
A= defined $fB= defined $v
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $fB= defined $v
ABresult
0X0
100
111
72 0 ▶ if ( $f eq 'split' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f eq "split") 3 387 390
if ($f eq "split") 0 0 0
73 0 ▶ return [ map { my $x = $_; $x =~ s/\A\s+|\s+\z//g; length $x ? $x : () } ref $v eq 'ARRAY' ? @$v : split /[\s,]+/, "$v" ];
Branch: 4 branches
BranchTrueFalseTotal
length $x ? : 6 1 7
ref $v eq 'ARRAY' ? : 0 3 3
length $x ? : 0 0 0
ref $v eq 'ARRAY' ? : 0 0 0
74 }
75 0 ▶ return int( $v =~ /(-?\d+)/ ? $1 : 0 ) if $f eq 'int';
Branch: 4 branches
BranchTrueFalseTotal
if $f eq "int" 373 14 387
$v =~ /(-?\d+)/ ? : 319 54 373
if $f eq "int" 0 0 0
$v =~ /(-?\d+)/ ? : 0 0 0
76 0 ▶ return lc "$v" if $f eq 'lc';
Branch: 2 branches
BranchTrueFalseTotal
if $f eq "lc" 2 12 14
if $f eq "lc" 0 0 0
77 0 die "dieser Aufruf ist in diesem Szenario nicht vorgesehen.\n";
78 }
79  
80 421 ▶sub _interp_re {
Subroutine _interp_re: called CC=2 SCAR=10.3
81 0 ▶ my ( $re, $args ) = @_;
Subroutine _interp_re: not called CC=2 SCAR=10.3
82 0 ▶ $re =~ s/\{([A-Za-z_][A-Za-z0-9_]*)\}/quotemeta( flat( $args->{$1} ) \/\/ '' )/ge;
Condition25%1/4
flat($args->{$1}) // ""
l!l
60
flat($args->{$1}) // ""
l!l
00
MC/DC0%0/1
flat($args->{$1}) // ""
flat($args->{$1})
MC/DC0%0/1
flat($args->{$1}) // ""
flat($args->{$1})
Truth table50%1/2
A
A= flat($args->{$1})
Aresult
11
00
Truth table0%0/2
A
A= flat($args->{$1})
Aresult
11
00
83 0 return $re;
84 }
85  
86  
87 7633 ▶sub same_scalar {
Subroutine same_scalar: called CC=16 SCAR=41.3
Pod documented
88 0 ▶ my ( $x, $y ) = @_;
Subroutine same_scalar: not called CC=16 SCAR=41.3
Pod documented
89 0 my $bool = grep { JSON::MaybeXS::is_bool($_) } $x, $y;
90 0 ▶ ( $x, $y ) = map { JSON::MaybeXS::is_bool($_) ? ( $_ ? 1 : 0 ) : $_ } $x, $y;
Branch: 4 branches
BranchTrueFalseTotal
JSON::MaybeXS::is_bool($_) ? : 68 15198 15266
$_ ? : 52 16 68
JSON::MaybeXS::is_bool($_) ? : 0 0 0
$_ ? : 0 0 0
91 0 ▶ ( $x, $y ) = map { defined $_ && !ref $_ && /\A(?:true|false)\z/ ? ( $_ eq 'true' ? 1 : 0 ) : $_ } $x, $y if $bool;
Branch: 6 branches
BranchTrueFalseTotal
if $bool 37 7596 7633
defined $_ && !ref($_) && /\A(?:true|false)\z/ ? : 3 71 74
$_ eq 'true' ? : 3 0 3
if $bool 0 0 0
defined $_ && !ref($_) && /\A(?:true|false)\z/ ? : 0 0 0
$_ eq 'true' ? : 0 0 0
Condition25%3/12
defined $_ and not ref $_ and /\A(?:true|false)\z/
!ll&&!rl&&r
0713
defined $_ and not ref $_
!ll&&!rl&&r
0074
defined $_ and not ref $_ and /\A(?:true|false)\z/
!ll&&!rl&&r
000
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC33%1/3
defined $_ and not ref $_ and /\A(?:true|false)\z/
defined $_ not ref $_ /\A(?:true|false)\z/
MC/DC0%0/3
defined $_ and not ref $_ and /\A(?:true|false)\z/
defined $_ not ref $_ /\A(?:true|false)\z/
Truth table50%2/4
A and not(B) and C
A= defined $_B= not ref $_C= /\A(?:true|false)\z/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $_B= not ref $_C= /\A(?:true|false)\z/
ABCresult
0XX0
10X0
1100
1111
92 0 ▶ return 0 if !defined $x || !defined $y || ref $x || ref $y;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $x && defined $y or ref $x or ref $y 178 7455 7633
if not defined $x && defined $y or ref $x or ref $y 0 0 0
Condition44%8/18
not defined $x && defined $y or ref $x or ref $y
l!l&&r!l&&!r
17807455
not defined $x && defined $y or ref $x
l!l&&r!l&&!r
17717455
defined $x && defined $y
!ll&&!rl&&r
17527456
not defined $x && defined $y or ref $x or ref $y
l!l&&r!l&&!r
000
not defined $x && defined $y or ref $x
l!l&&r!l&&!r
000
defined $x && defined $y
!ll&&!rl&&r
000
MC/DC75%3/4
not defined $x && defined $y or ref $x or ref $y
defined $x defined $y ref $x ref $y
MC/DC0%0/4
not defined $x && defined $y or ref $x or ref $y
defined $x defined $y ref $x ref $y
Truth table80%4/5
not(A && B) or C or D
A= defined $xB= defined $yC= ref $xD= ref $y
ABCDresult
0XXX1
10XX1
111X1
11011
11000
Truth table0%0/5
not(A && B) or C or D
A= defined $xB= defined $yC= ref $xD= ref $y
ABCDresult
0XXX1
10XX1
111X1
11011
11000
93 0 my $num = qr/\A-?\d+(?:\.\d+)?\z/;
94 0 ▶ return $x == $y ? 1 : 0 if "$x" =~ $num && "$y" =~ $num;
Branch: 4 branches
BranchTrueFalseTotal
if "$x" =~ /$num/ and "$y" =~ /$num/ 1110 6345 7455
$x == $y ? : 625 485 1110
if "$x" =~ /$num/ and "$y" =~ /$num/ 0 0 0
$x == $y ? : 0 0 0
Condition33%2/6
"$x" =~ /$num/ and "$y" =~ /$num/
!ll&&!rl&&r
634501110
"$x" =~ /$num/ and "$y" =~ /$num/
!ll&&!rl&&r
000
MC/DC50%1/2
"$x" =~ /$num/ and "$y" =~ /$num/
"$x" =~ /$num/ "$y" =~ /$num/
MC/DC0%0/2
"$x" =~ /$num/ and "$y" =~ /$num/
"$x" =~ /$num/ "$y" =~ /$num/
Truth table66%2/3
A and B
A= "$x" =~ /$num/B= "$y" =~ /$num/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= "$x" =~ /$num/B= "$y" =~ /$num/
ABresult
0X0
100
111
95 0 ▶ return "$x" eq "$y" ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
"$x" eq "$y" ? : 2372 3973 6345
"$x" eq "$y" ? : 0 0 0
96 }
97  
98  
99 78 ▶sub near {
Subroutine near: called CC=9 SCAR=29.5
Pod documented
100 0 ▶ my ( $x, $want, $tol ) = @_;
Subroutine near: not called CC=9 SCAR=29.5
Pod documented
101 0 ▶ return 0 if !defined $x || ref $x || !looks_like_number($x) || $x =~ /\A\s|\s\z/;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/ 8 70 78
if not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/ 0 0 0
Condition50%9/18
not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/
l!l&&r!l&&!r
6270
not defined $x or ref $x or not &looks_like_number($x)
l!l&&r!l&&!r
3372
not defined $x or ref $x
l!l&&r!l&&!r
1275
not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/
l!l&&r!l&&!r
000
not defined $x or ref $x or not &looks_like_number($x)
l!l&&r!l&&!r
000
not defined $x or ref $x
l!l&&r!l&&!r
000
MC/DC100%4/4
not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/
not defined $x ref $x not &looks_like_number($x) $x =~ /\A\s|\s\z/
MC/DC0%0/4
not defined $x or ref $x or not &looks_like_number($x) or $x =~ /\A\s|\s\z/
not defined $x ref $x not &looks_like_number($x) $x =~ /\A\s|\s\z/
Truth table100%5/5
not(A) or B or not(C) or D
A= not defined $xB= ref $xC= not &looks_like_number($x)D= $x =~ /\A\s|\s\z/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table0%0/5
not(A) or B or not(C) or D
A= not defined $xB= ref $xC= not &looks_like_number($x)D= $x =~ /\A\s|\s\z/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
102 0 ▶ return 0 unless $x == $x && abs($x) != 9**9**9; # NaN, Inf
Branch: 2 branches
BranchTrueFalseTotal
unless $x == $x and abs $x != "Inf" 2 68 70
unless $x == $x and abs $x != "Inf" 0 0 0
Condition50%3/6
$x == $x and abs $x != "Inf"
!ll&&!rl&&r
1168
$x == $x and abs $x != "Inf"
!ll&&!rl&&r
000
MC/DC100%2/2
$x == $x and abs $x != "Inf"
$x == $x abs $x != "Inf"
MC/DC0%0/2
$x == $x and abs $x != "Inf"
$x == $x abs $x != "Inf"
Truth table100%3/3
A and B
A= $x == $xB= abs $x != "Inf"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $x == $xB= abs $x != "Inf"
ABresult
0X0
100
111
103 0 ▶ my $slack = 1e-9 * ( abs($want) > 1 ? abs($want) : 1 );
Branch: 2 branches
BranchTrueFalseTotal
abs $want > 1 ? : 31 37 68
abs $want > 1 ? : 0 0 0
104 0 ▶ return abs( $x - $want ) <= $tol + $slack ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
abs $x - $want <= $tol + $slack ? : 40 28 68
abs $x - $want <= $tol + $slack ? : 0 0 0
105 }
106  
107 2966 ▶sub _show {
Subroutine _show: called CC=2 SCAR=10.5
108 0 ▶ my ( $v ) = @_;
Subroutine _show: not called CC=2 SCAR=10.5
109 0 my $s = $JSON->encode($v);
110 0 ▶ return length $s > 200 ? substr( $s, 0, 200 ).'…' : $s;
Branch: 2 branches
BranchTrueFalseTotal
length $s > 200 ? : 0 2966 2966
length $s > 200 ? : 0 0 0
111 }
112  
113  
114 113 ▶sub element_match {
Subroutine element_match: called CC=12 SCAR=34.9
Pod documented
115 0 ▶ my ( $el, $m, $args ) = @_;
Subroutine element_match: not called CC=12 SCAR=34.9
Pod documented
116 0 ▶ $args //= {};
Condition50%2/4
$args //= {}
l!l
1094
$args //= {}
l!l
00
MC/DC100%1/1
$args //= {}
$args
MC/DC0%0/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
Truth table0%0/2
A
A= $args
Aresult
11
00
117 0 ▶ if ( !ref $m ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (ref $m) 11 102 113
unless (ref $m) 0 0 0
118 0 my $re = _interp_re( $m, $args );
119 0 ▶ return defined $el && !ref $el && $el =~ /$re/ ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $el && !ref($el) && $el =~ /$re/ ? : 4 7 11
defined $el && !ref($el) && $el =~ /$re/ ? : 0 0 0
Condition41%5/12
defined $el and not ref $el and $el =~ /$re/
!ll&&!rl&&r
164
defined $el and not ref $el
!ll&&!rl&&r
0110
defined $el and not ref $el and $el =~ /$re/
!ll&&!rl&&r
000
defined $el and not ref $el
!ll&&!rl&&r
000
MC/DC66%2/3
defined $el and not ref $el and $el =~ /$re/
defined $el not ref $el $el =~ /$re/
MC/DC0%0/3
defined $el and not ref $el and $el =~ /$re/
defined $el not ref $el $el =~ /$re/
Truth table75%3/4
A and not(B) and C
A= defined $elB= not ref $elC= $el =~ /$re/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $elB= not ref $elC= $el =~ /$re/
ABCresult
0XX0
10X0
1100
1111
120 }
121 0 ▶ return 0 unless ref $el eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $el eq "HASH" 1 101 102
unless ref $el eq "HASH" 0 0 0
122 0 for my $f ( sort keys %$m ) {
123 0 my $spec = $m->{$f};
124 0 ▶ if ( ref $spec eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $spec eq "HASH") 8 98 106
if (ref $spec eq "HASH") 0 0 0
125 0 my ( $ok ) = check_value( exists $el->{$f}, $el->{$f}, $spec, $args );
126 0 ▶ return 0 unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 3 5 8
unless $ok 0 0 0
127 0 next;
128 }
129 0 my $re = _interp_re( $spec, $args );
130 0 my $v = flat( $el->{$f} );
131 0 ▶ return 0 unless defined $v && $v =~ /$re/;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v and $v =~ /$re/ 51 47 98
unless defined $v and $v =~ /$re/ 0 0 0
Condition33%2/6
defined $v and $v =~ /$re/
!ll&&!rl&&r
05147
defined $v and $v =~ /$re/
!ll&&!rl&&r
000
MC/DC50%1/2
defined $v and $v =~ /$re/
defined $v $v =~ /$re/
MC/DC0%0/2
defined $v and $v =~ /$re/
defined $v $v =~ /$re/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /$re/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $vB= $v =~ /$re/
ABresult
0X0
100
111
132 }
133 0 return 1;
134 }
135  
136  
137 3069 ▶sub condition {
Subroutine condition: called CC=2 SCAR=9.2
Pod documented
138 0 ▶ my ( $state, $c, $args ) = @_;
Subroutine condition: not called CC=2 SCAR=9.2
Pod documented
139 0 ▶ $args //= {};
Condition50%2/4
$args //= {}
l!l
173052
$args //= {}
l!l
00
MC/DC100%1/1
$args //= {}
$args
MC/DC0%0/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
Truth table0%0/2
A
A= $args
Aresult
11
00
140 0 my ( $found, $v ) = get( $state, path( $c->{path}, $args ) );
141 0 return check_value( $found, $v, $c, $args );
142 }
143  
144  
145 3075 ▶sub check_value {
Subroutine check_value: called CC=53 SCAR=61.6
Pod documented
146 0 ▶ my ( $found, $v, $c, $args ) = @_;
Subroutine check_value: not called CC=53 SCAR=61.6
Pod documented
147 0 ▶ $args //= {};
Condition50%2/4
$args //= {}
l!l
30741
$args //= {}
l!l
00
MC/DC100%1/1
$args //= {}
$args
MC/DC0%0/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
Truth table0%0/2
A
A= $args
Aresult
11
00
148 0 ▶ if ( exists $c->{absent} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"absent"}) 5 3070 3075
if (exists $c->{"absent"}) 0 0 0
149 0 ▶ my $gone = !$found || !defined $v;
Condition50%3/6
$found && defined $v
!ll&&!rl&&r
122
$found && defined $v
!ll&&!rl&&r
000
MC/DC100%2/2
$found && defined $v
$found defined $v
MC/DC0%0/2
$found && defined $v
$found defined $v
Truth table100%3/3
A && B
A= $foundB= defined $v
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $foundB= defined $v
ABresult
0X0
100
111
150 0 ▶ return ( 0, 'present: '._show($v) ) if $c->{absent} && !$gone;
Branch: 2 branches
BranchTrueFalseTotal
if $c->{"absent"} and not $gone 2 3 5
if $c->{"absent"} and not $gone 0 0 0
Condition33%2/6
$c->{"absent"} and not $gone
!ll&&!rl&&r
032
$c->{"absent"} and not $gone
!ll&&!rl&&r
000
MC/DC50%1/2
$c->{"absent"} and not $gone
$c->{"absent"} not $gone
MC/DC0%0/2
$c->{"absent"} and not $gone
$c->{"absent"} not $gone
Truth table66%2/3
A and not(B)
A= $c->{"absent"}B= not $gone
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $c->{"absent"}B= not $gone
ABresult
0X0
100
111
151 0 ▶ return ( 0, 'missing' ) if !$c->{absent} && $gone;
Branch: 2 branches
BranchTrueFalseTotal
if not $c->{"absent"} and $gone 0 3 3
if not $c->{"absent"} and $gone 0 0 0
Condition16%1/6
not $c->{"absent"} and $gone
!ll&&!rl&&r
300
not $c->{"absent"} and $gone
!ll&&!rl&&r
000
MC/DC0%0/2
not $c->{"absent"} and $gone
not $c->{"absent"} $gone
MC/DC0%0/2
not $c->{"absent"} and $gone
not $c->{"absent"} $gone
Truth table33%1/3
not(A) and B
A= not $c->{"absent"}B= $gone
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $c->{"absent"}B= $gone
ABresult
0X0
100
111
152 }
153 0 ▶ if ( exists $c->{exists} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"exists"}) 14 3059 3073
if (exists $c->{"exists"}) 0 0 0
154 0 ▶ return ( 0, 'missing' ) if $c->{exists} && !$found;
Branch: 2 branches
BranchTrueFalseTotal
if $c->{"exists"} and not $found 3 11 14
if $c->{"exists"} and not $found 0 0 0
Condition50%3/6
$c->{"exists"} and not $found
!ll&&!rl&&r
1103
$c->{"exists"} and not $found
!ll&&!rl&&r
000
MC/DC100%2/2
$c->{"exists"} and not $found
$c->{"exists"} not $found
MC/DC0%0/2
$c->{"exists"} and not $found
$c->{"exists"} not $found
Truth table100%3/3
A and not(B)
A= $c->{"exists"}B= not $found
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $c->{"exists"}B= not $found
ABresult
0X0
100
111
155 0 ▶ return ( 0, 'present: '._show($v) ) if !$c->{exists} && $found;
Branch: 2 branches
BranchTrueFalseTotal
if not $c->{"exists"} and $found 1 10 11
if not $c->{"exists"} and $found 0 0 0
Condition33%2/6
not $c->{"exists"} and $found
!ll&&!rl&&r
1001
not $c->{"exists"} and $found
!ll&&!rl&&r
000
MC/DC50%1/2
not $c->{"exists"} and $found
not $c->{"exists"} $found
MC/DC0%0/2
not $c->{"exists"} and $found
not $c->{"exists"} $found
Truth table66%2/3
not(A) and B
A= not $c->{"exists"}B= $found
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $c->{"exists"}B= $found
ABresult
0X0
100
111
156 }
157 0 my @checks = grep { exists $c->{$_} } qw( equals in regex contains excludes length any none before );
158 0 ▶ return ( 1, $found ? _show($v) : 'not present' ) unless @checks;
Branch: 4 branches
BranchTrueFalseTotal
unless @checks 15 3054 3069
$found ? : 12 3 15
unless @checks 0 0 0
$found ? : 0 0 0
159 0 ▶ return ( 0, 'missing' ) unless $found;
Branch: 2 branches
BranchTrueFalseTotal
unless $found 89 2965 3054
unless $found 0 0 0
160 2461 ▶ my $text = sub {
Subroutine __ANON__: called CC=5 SCAR=22.8
161 0 ▶ my ( $want ) = @_;
Subroutine __ANON__: not called CC=5 SCAR=22.8
162 0 ▶ return !ref $want && ref $v eq 'HASH' && exists $v->{content} && !ref $v->{content} ? $v->{content} : $v;
Branch: 2 branches
BranchTrueFalseTotal
!ref($want) && ref $v eq 'HASH' && exists $v->{'content'} && !ref($v->{'content'}) ? : 5 2456 2461
!ref($want) && ref $v eq 'HASH' && exists $v->{'content'} && !ref($v->{'content'}) ? : 0 0 0
Condition38%7/18
not ref $want and ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
!ll&&!rl&&r
245605
not ref $want and ref $v eq "HASH" and exists $v->{"content"}
!ll&&!rl&&r
245605
not ref $want and ref $v eq "HASH"
!ll&&!rl&&r
124555
not ref $want and ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
!ll&&!rl&&r
000
not ref $want and ref $v eq "HASH" and exists $v->{"content"}
!ll&&!rl&&r
000
not ref $want and ref $v eq "HASH"
!ll&&!rl&&r
000
MC/DC50%2/4
not ref $want and ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
not ref $want ref $v eq "HASH" exists $v->{"content"} not ref $v->{"content"}
MC/DC0%0/4
not ref $want and ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
not ref $want ref $v eq "HASH" exists $v->{"content"} not ref $v->{"content"}
Truth table60%3/5
not(A) and B and C and not(D)
A= not ref $wantB= ref $v eq "HASH"C= exists $v->{"content"}D= not ref $v->{"content"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
not(A) and B and C and not(D)
A= not ref $wantB= ref $v eq "HASH"C= exists $v->{"content"}D= not ref $v->{"content"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
163 0 };
164 0 ▶ if ( exists $c->{equals} && exists $c->{tolerance} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (exists $c->{'equals'} and exists $c->{'tolerance'}) { } 60 2905 2965
elsif (exists $c->{'equals'}) { } 2365 540 2905
if (exists $c->{'equals'} and exists $c->{'tolerance'}) { } 0 0 0
elsif (exists $c->{'equals'}) { } 0 0 0
Condition50%3/6
exists $c->{"equals"} and exists $c->{"tolerance"}
!ll&&!rl&&r
540236560
exists $c->{"equals"} and exists $c->{"tolerance"}
!ll&&!rl&&r
000
MC/DC100%2/2
exists $c->{"equals"} and exists $c->{"tolerance"}
exists $c->{"equals"} exists $c->{"tolerance"}
MC/DC0%0/2
exists $c->{"equals"} and exists $c->{"tolerance"}
exists $c->{"equals"} exists $c->{"tolerance"}
Truth table100%3/3
A and B
A= exists $c->{"equals"}B= exists $c->{"tolerance"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= exists $c->{"equals"}B= exists $c->{"tolerance"}
ABresult
0X0
100
111
165 return ( 0, 'is '._show($v).', not within '.$c->{tolerance}.' of '.$c->{equals} )
166 0 ▶ unless near( $text->( $c->{equals} ), $c->{equals}, $c->{tolerance} );
Branch: 2 branches
BranchTrueFalseTotal
unless near(&$text($c->{"equals"}), $c->{"equals"}, $c->{"tolerance"}) 27 33 60
unless near(&$text($c->{"equals"}), $c->{"equals"}, $c->{"tolerance"}) 0 0 0
167 }
168 elsif ( exists $c->{equals} ) {
169 0 ▶ return ( 0, 'is '._show($v) ) unless same_scalar( $text->( $c->{equals} ), $c->{equals} );
Branch: 2 branches
BranchTrueFalseTotal
unless same_scalar(&$text($c->{"equals"}), $c->{"equals"}) 913 1452 2365
unless same_scalar(&$text($c->{"equals"}), $c->{"equals"}) 0 0 0
170 }
171 0 ▶ if ( exists $c->{in} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"in"}) 18 2007 2025
if (exists $c->{"in"}) 0 0 0
172 0 ▶ return ( 0, 'is '._show($v) ) unless grep { same_scalar( $text->($_), $_ ) } @{ $c->{in} };
Branch: 2 branches
BranchTrueFalseTotal
unless grep {same_scalar(&$text($_), $_);} @{$$c{"in"};} 6 12 18
unless grep {same_scalar(&$text($_), $_);} @{$$c{"in"};} 0 0 0
173 }
174 0 ▶ if ( exists $c->{regex} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"regex"}) 312 1707 2019
if (exists $c->{"regex"}) 0 0 0
175 0 my $re = _interp_re( $c->{regex}, $args );
176 0 ▶ my $t = ref $v eq 'HASH' && exists $v->{content} && !ref $v->{content} ? $v->{content} : $v;
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'HASH' && exists $v->{'content'} && !ref($v->{'content'}) ? : 1 311 312
ref $v eq 'HASH' && exists $v->{'content'} && !ref($v->{'content'}) ? : 0 0 0
Condition33%4/12
ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
!ll&&!rl&&r
31101
ref $v eq "HASH" and exists $v->{"content"}
!ll&&!rl&&r
31101
ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
!ll&&!rl&&r
000
ref $v eq "HASH" and exists $v->{"content"}
!ll&&!rl&&r
000
MC/DC33%1/3
ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
ref $v eq "HASH" exists $v->{"content"} not ref $v->{"content"}
MC/DC0%0/3
ref $v eq "HASH" and exists $v->{"content"} and not ref $v->{"content"}
ref $v eq "HASH" exists $v->{"content"} not ref $v->{"content"}
Truth table50%2/4
A and B and not(C)
A= ref $v eq "HASH"B= exists $v->{"content"}C= not ref $v->{"content"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= ref $v eq "HASH"B= exists $v->{"content"}C= not ref $v->{"content"}
ABCresult
0XX0
10X0
1100
1111
177 0 ▶ return ( 0, 'is '._show($v) ) unless defined $t && !ref $t && $t =~ /$re/;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $t and not ref $t and $t =~ /$re/ 111 201 312
unless defined $t and not ref $t and $t =~ /$re/ 0 0 0
Condition41%5/12
defined $t and not ref $t and $t =~ /$re/
!ll&&!rl&&r
1110201
defined $t and not ref $t
!ll&&!rl&&r
01311
defined $t and not ref $t and $t =~ /$re/
!ll&&!rl&&r
000
defined $t and not ref $t
!ll&&!rl&&r
000
MC/DC66%2/3
defined $t and not ref $t and $t =~ /$re/
defined $t not ref $t $t =~ /$re/
MC/DC0%0/3
defined $t and not ref $t and $t =~ /$re/
defined $t not ref $t $t =~ /$re/
Truth table75%3/4
A and not(B) and C
A= defined $tB= not ref $tC= $t =~ /$re/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $tB= not ref $tC= $t =~ /$re/
ABCresult
0XX0
10X0
1100
1111
178 }
179 0 for my $k (qw( contains excludes )) {
180 0 ▶ next unless exists $c->{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $c->{$k} 3674 108 3782
unless exists $c->{$k} 0 0 0
181 0 ▶ return ( 0, 'not a list: '._show($v) ) unless ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 2 106 108
unless ref $v eq "ARRAY" 0 0 0
182 0 for my $want ( @{ $c->{$k} } ) {
183 0 my $has = grep { same_scalar( $_, $want ) } @$v;
184 0 ▶ return ( 0, $want.' missing in '._show($v) ) if $k eq 'contains' && !$has;
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "contains" and not $has 32 151 183
if $k eq "contains" and not $has 0 0 0
Condition50%3/6
$k eq "contains" and not $has
!ll&&!rl&&r
314832
$k eq "contains" and not $has
!ll&&!rl&&r
000
MC/DC100%2/2
$k eq "contains" and not $has
$k eq "contains" not $has
MC/DC0%0/2
$k eq "contains" and not $has
$k eq "contains" not $has
Truth table100%3/3
A and not(B)
A= $k eq "contains"B= not $has
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $k eq "contains"B= not $has
ABresult
0X0
100
111
185 0 ▶ return ( 0, $want.' present in '._show($v) ) if $k eq 'excludes' && $has;
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "excludes" and $has 1 150 151
if $k eq "excludes" and $has 0 0 0
Condition50%3/6
$k eq "excludes" and $has
!ll&&!rl&&r
14821
$k eq "excludes" and $has
!ll&&!rl&&r
000
MC/DC100%2/2
$k eq "excludes" and $has
$k eq "excludes" $has
MC/DC0%0/2
$k eq "excludes" and $has
$k eq "excludes" $has
Truth table100%3/3
A and B
A= $k eq "excludes"B= $has
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $k eq "excludes"B= $has
ABresult
0X0
100
111
186 }
187 }
188 0 ▶ if ( exists $c->{length} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"length"}) 88 1785 1873
if (exists $c->{"length"}) 0 0 0
189 0 ▶ my $n = ref $v eq 'ARRAY' ? @$v : ref $v eq 'HASH' ? keys %$v : -1;
Branch: 4 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 86 2 88
ref $v eq 'HASH' ? : 1 1 2
ref $v eq 'ARRAY' ? : 0 0 0
ref $v eq 'HASH' ? : 0 0 0
190 0 ▶ return ( 0, $n.' entries' ) unless $n == $c->{length};
Branch: 2 branches
BranchTrueFalseTotal
unless $n == $c->{"length"} 10 78 88
unless $n == $c->{"length"} 0 0 0
191 }
192 0 for my $k (qw( any none before )) {
193 0 ▶ next unless exists $c->{$k};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $c->{$k} 5503 86 5589
unless exists $c->{$k} 0 0 0
194 0 ▶ return ( 0, 'not a list: '._show($v) ) unless ref $v eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 0 86 86
unless ref $v eq "ARRAY" 0 0 0
195 }
196 0 ▶ if ( exists $c->{any} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"any"}) 43 1820 1863
if (exists $c->{"any"}) 0 0 0
197 0 ▶ return ( 0, 'no matching entry in '._show($v) ) unless grep { element_match( $_, $c->{any}, $args ) } @$v;
Branch: 2 branches
BranchTrueFalseTotal
unless grep {element_match($_, $c->{"any"}, $args);} @$v 15 28 43
unless grep {element_match($_, $c->{"any"}, $args);} @$v 0 0 0
198 }
199 0 ▶ if ( exists $c->{none} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"none"}) 37 1811 1848
if (exists $c->{"none"}) 0 0 0
200 0 my ( $hit ) = grep { element_match( $_, $c->{none}, $args ) } @$v;
201 0 ▶ return ( 0, 'unwanted entry: '._show($hit) ) if defined $hit;
Branch: 2 branches
BranchTrueFalseTotal
if defined $hit 10 27 37
if defined $hit 0 0 0
202 }
203 0 ▶ if ( exists $c->{before} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $c->{"before"}) 6 1832 1838
if (exists $c->{"before"}) 0 0 0
204 my ( $first, $second ) = map {
205 0 my $m = $_;
206 0 my ( $i ) = grep { element_match( $v->[$_], $m, $args ) } 0 .. $#$v;
207 0 $i;
208 0 } @{ $c->{before} };
209 0 ▶ return ( 0, 'first entry missing' ) unless defined $first;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $first 1 5 6
unless defined $first 0 0 0
210 0 ▶ return ( 0, 'second entry missing' ) unless defined $second;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $second 1 4 5
unless defined $second 0 0 0
211 0 ▶ return ( 0, 'order: '.$first.' after '.$second ) unless $first < $second;
Branch: 2 branches
BranchTrueFalseTotal
unless $first < $second 2 2 4
unless $first < $second 0 0 0
212 }
213 0 return ( 1, _show($v) );
214 }
215  
216 54 1;
217  
218 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Postgres.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Nft.pm »