blib/lib/Langertha/Holmgang/World.pm

filter: Statementstmt 74.2% 285 / 384 Branchbran 57.8% 148 / 256 Conditioncond 43.3% 72 / 166 MC/DCmcdc 25.8% 23 / 89 Subroutinesub 78.2% 36 / 46 Podpod 100% 10 / 10 totaltotal 60.3% 574 / 951 CC 304 SCAR 37.3
CC
304
Cov
63%
_observed_command
185.5
_observed_command
185.5
_apply
38.6
CRAP 41.5
« blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Postfix.pm »
1 package Langertha::Holmgang::World;
2 # ABSTRACT: The simulated world of a case — state, tool dispatch, handlers, end-state diff
3  
4 41 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 41 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 41 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use Langertha::Holmgang::Expectation qw( condition element_match path get flat filter_value interp_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 41 ▶use Langertha::Holmgang::Shell ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 41 ▶use Langertha::Holmgang::Shell::Filter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 41 ▶use Langertha::Holmgang::Simulators;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 41 ▶use Langertha::Holmgang::Target ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 41 ▶use Langertha::Holmgang::Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 41 ▶use Langertha::Holmgang::ToolSchema qw( schema_errors );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 41 our $VERSION = '0.001';
18  
19 # the state changes of a handler's apply, in format 2; a true constant
20 41 our @OPS = qw( set push insert delete remove move );
21  
22 41 my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 );
23  
24 # what the model gets for a simulator that fails in Perl, and how such a text looks
25 # (" at FILE line N.", as die without "\n" ends); a line only counts when FILE is a
26 # source file of this process (_own_file) — simulated log text with Perl-style lines
27 # of invented paths is output the case asks for (ADR 0004)
28 41 my $FAULT = 'Fehler: interner Fehler beim Ausführen des Aufrufs.';
29 41 my $PERL_ERROR = qr/^((.*?$Langertha::Holmgang::Target::LOCATION\.)[ \t]*)$/m;
30  
31  
32 41 has state => (
33 is => 'ro',
34 writer => '_set_state',
35 required => 1,
36 );
37  
38  
39 has tools => (
40 is => 'ro',
41 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 41 );
43  
44  
45 has observe => (
46 is => 'ro',
47 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 41 );
49  
50  
51 41 has simulators => (
52 is => 'ro',
53 lazy => 1,
54 builder => '_build_simulators',
55 );
56 12 ▶sub _build_simulators { Langertha::Holmgang::Simulators->new }
Subroutine _build_simulators: called CC=1 SCAR=0.0
57  
58  
59 2208 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
60 2208 my ( $orig, $class, @args ) = @_;
61 2208 my $a = $class->$orig(@args);
62 2208 ▶ $a->{state} = $class->clone( $a->{state} // {} );
Condition50%1/2
$a->{"state"} // {}
l!l
22080
MC/DC0%0/1
$a->{"state"} // {}
$a->{"state"}
Truth table50%1/2
A
A= $a->{"state"}
Aresult
11
00
63 2208 ▶ $a->{tools} //= [];
Condition50%1/2
$a->{"tools"} //= []
l!l
22080
MC/DC0%0/1
$a->{"tools"} //= []
$a->{"tools"}
Truth table50%1/2
A
A= $a->{"tools"}
Aresult
11
00
64 2208 ▶ $a->{observe} //= [];
Condition100%2/2
$a->{"observe"} //= []
l!l
219018
MC/DC100%1/1
$a->{"observe"} //= []
$a->{"observe"}
Truth table100%2/2
A
A= $a->{"observe"}
Aresult
11
00
65 2208 return $a;
66 41 };
67  
68  
69 4876 ▶sub clone {
Subroutine clone: called CC=1 SCAR=1.2
Pod documented
70 0 ▶ my ( $self, $d ) = @_;
Subroutine clone: not called CC=1 SCAR=1.2
Pod documented
71 0 return $JSON->decode( $JSON->encode($d) );
72 }
73  
74  
75 1156 ▶sub offer {
Subroutine offer: called CC=1 SCAR=1.2
Pod documented
76 0 ▶ my ( $self ) = @_;
Subroutine offer: not called CC=1 SCAR=1.2
Pod documented
77 0 return [ map { { name => $_->{name}, description => $_->{description}, parameters => $_->{parameters} } } @{ $self->tools } ];
78 }
79  
80  
81 2287 ▶sub call {
Subroutine call: called CC=11 SCAR=35.4
Pod documented
82 0 ▶ my ( $self, $name, $raw ) = @_;
Subroutine call: not called CC=11 SCAR=35.4
Pod documented
83 0 ▶ my ( $tool ) = grep { $_->{name} eq ( $name // '' ) } @{ $self->tools };
Condition25%1/4
$name // ""
l!l
45260
$name // ""
l!l
00
MC/DC0%0/1
$name // ""
$name
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $name
Aresult
11
00
84 0 ▶ return ( "Fehler: unbekanntes Werkzeug '".( $name // '' )."'.", {}, 0 ) unless $tool;
Branch: 2 branches
BranchTrueFalseTotal
unless $tool 2 2285 2287
unless $tool 0 0 0
Condition25%1/4
$name // ""
l!l
20
$name // ""
l!l
00
MC/DC0%0/1
$name // ""
$name
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $name
Aresult
11
00
85  
86 0 my $args = {};
87 0 ▶ if ( ref $raw eq 'HASH' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $raw eq 'HASH') { } 2283 2 2285
elsif (defined $raw and length $raw) { } 2 0 2
if (ref $raw eq 'HASH') { } 0 0 0
elsif (defined $raw and length $raw) { } 0 0 0
88 0 $args = $raw;
89 }
90 ▶ elsif ( defined $raw && length $raw ) {
Condition16%1/6
defined $raw and length $raw
!ll&&!rl&&r
002
defined $raw and length $raw
!ll&&!rl&&r
000
MC/DC0%0/2
defined $raw and length $raw
defined $raw length $raw
MC/DC0%0/2
defined $raw and length $raw
defined $raw length $raw
Truth table33%1/3
A and B
A= defined $rawB= length $raw
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $rawB= length $raw
ABresult
0X0
100
111
91 0 my $text = $raw;
92 0 ▶ utf8::decode($text) unless utf8::is_utf8($text);
Branch: 2 branches
BranchTrueFalseTotal
unless utf8::is_utf8($text) 2 0 2
unless utf8::is_utf8($text) 0 0 0
93 0 $args = eval { $JSON->decode($text) };
94 0 ▶ return ( 'Fehler: Argumente sind kein JSON-Objekt.', {}, 0 ) unless ref $args eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $args eq "HASH" 1 1 2
unless ref $args eq "HASH" 0 0 0
95 }
96 0 ▶ if ( my @e = schema_errors( $args, $tool->{parameters} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my(@e) = schema_errors($args, $tool->{"parameters"})) 5 2279 2284
if (my(@e) = schema_errors($args, $tool->{"parameters"})) 0 0 0
97 0 return ( 'Fehler: Argumente passen nicht zum Schema: '.join( '; ', @e ), $args, 0 );
98 }
99 0 ▶ return $self->_simulate( $tool, $args ) if defined $tool->{simulator};
Branch: 2 branches
BranchTrueFalseTotal
if defined $tool->{"simulator"} 412 1867 2279
if defined $tool->{"simulator"} 0 0 0
100 0 return $self->_handle( $tool, $args );
101 }
102  
103 412 ▶sub _simulate {
Subroutine _simulate: called CC=5 SCAR=20.9
104 0 ▶ my ( $self, $tool, $args ) = @_;
Subroutine _simulate: not called CC=5 SCAR=20.9
105 0 my $sim = $tool->{simulator};
106 0 my $sims = $self->simulators;
107 0 ▶ if ( $sim eq 'run_command' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sim eq "run_command") 155 257 412
if ($sim eq "run_command") 0 0 0
108 0 my @r = $self->_observed_command($args);
109 0 ▶ return @r if @r;
Branch: 2 branches
BranchTrueFalseTotal
if @r 15 140 155
if @r 0 0 0
110 }
111 0 my $next = $self->clone( $self->state );
112 397 ▶ my ( $died, $out, $ok, $gap ) = _guarded( sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
113 0 ▶ $sim eq 'write_file' ? $sims->write_file( $next, @{$args}{qw( host path content )} )
Branch: 2 branches
BranchTrueFalseTotal
$sim eq 'run_command' ? : 140 136 276
$sim eq 'run_command' ? : 0 0 0
114 0 : $sim eq 'run_command' ? $sims->run_command( $next, @{$args}{qw( host command )} )
115 0 ▶ : $sims->tool_call( $next, $sim, $tool->{name}, $args );
Subroutine __ANON__: not called CC=3 SCAR=14.2
Branch: 2 branches
BranchTrueFalseTotal
$sim eq 'write_file' ? : 121 276 397
$sim eq 'write_file' ? : 0 0 0
116 0 } );
117 0 ▶ $self->_set_state($next) unless $died;
Branch: 2 branches
BranchTrueFalseTotal
unless $died 395 2 397
unless $died 0 0 0
118 0 ▶ return ( $out, $args, $ok ? 1 : 0, $gap );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 386 11 397
$ok ? : 0 0 0
119 }
120  
121 # a file this process runs from: a loaded module (%INC) or the script; only these
122 # paths are a host leak (never touches the file system)
123 8 ▶sub _own_file {
Subroutine _own_file: called CC=3 SCAR=15.3
124 0 ▶ my ( $file ) = @_;
Subroutine _own_file: not called CC=3 SCAR=15.3
125 0 ▶ return $file eq $0 || scalar grep { defined && $_ eq $file } values %INC;
Condition40%4/10
$file eq $0 || scalar grep({defined $_ and $_ eq $file;} values %INC)
l!l
35
defined $_ && $_ eq $file
!ll&&!rl&&r
016131
$file eq $0 || scalar grep({defined $_ and $_ eq $file;} values %INC)
l!l
00
defined $_ && $_ eq $file
!ll&&!rl&&r
000
MC/DC100%1/1
$file eq $0 || scalar grep({defined $_ and $_ eq $file;} values %INC)
$file eq $0
MC/DC50%1/2
defined $_ && $_ eq $file
defined $_ $_ eq $file
MC/DC0%0/1
$file eq $0 || scalar grep({defined $_ and $_ eq $file;} values %INC)
$file eq $0
MC/DC0%0/2
defined $_ && $_ eq $file
defined $_ $_ eq $file
Truth table100%2/2
A
A= $file eq $0
Aresult
11
00
Truth table66%2/3
A && B
A= defined $_B= $_ eq $file
ABresult
0X0
100
111
Truth table0%0/2
A
A= $file eq $0
Aresult
11
00
Truth table0%0/3
A && B
A= defined $_B= $_ eq $file
ABresult
0X0
100
111
126 }
127  
128 # runs a simulator call; ( died, output, ok, gap ) with a Perl error of the simulator —
129 # its die, or such a text in its output — turned into $FAULT and the original into the gap
130 407 ▶sub _guarded {
Subroutine _guarded: called CC=6 SCAR=24.9
131 0 ▶ my ( $code ) = @_;
Subroutine _guarded: not called CC=6 SCAR=24.9
132 0 my ( $out, $ok, $gap );
133 0 ▶ unless ( eval { ( $out, $ok, $gap ) = $code->(); 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (eval { do { () = &$code(); 1 } }) 2 405 407
unless (eval { do { () = &$code(); 1 } }) 0 0 0
134 0 my $err = $@ =~ s/\s+\z//r;
135 0 return ( 1, $FAULT, 0, join( '; ', grep { defined } $gap, 'simulator error: '.$err ) );
136 }
137 0 my @faults;
138 0 ▶ $out =~ s/$PERL_ERROR/_own_file($3) ? do { push @faults, $2; $FAULT } : $1/ge if defined $out && !ref $out;
Branch: 4 branches
BranchTrueFalseTotal
if defined $out and not ref $out 405 0 405
_own_file($3) ? : 4 4 8
if defined $out and not ref $out 0 0 0
_own_file($3) ? : 0 0 0
Condition16%1/6
defined $out and not ref $out
!ll&&!rl&&r
00405
defined $out and not ref $out
!ll&&!rl&&r
000
MC/DC0%0/2
defined $out and not ref $out
defined $out not ref $out
MC/DC0%0/2
defined $out and not ref $out
defined $out not ref $out
Truth table33%1/3
A and not(B)
A= defined $outB= not ref $out
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $outB= not ref $out
ABresult
0X0
100
111
139 0 ▶ return ( 0, $out, $ok, $gap ) unless @faults;
Branch: 2 branches
BranchTrueFalseTotal
unless @faults 401 4 405
unless @faults 0 0 0
140 0 return ( 0, $out, 0, join( '; ', grep { defined } $gap, map { 'simulator error: '.$_ } @faults ) );
141 }
142  
143 # run_command with observations: a single command an observation answers, or a chain on
144 # a linux device of which at least one link is observed; else the empty list
145 155 ▶sub _observed_command {
Subroutine _observed_command: called CC=28 SCAR=52.2
146 0 ▶ my ( $self, $args ) = @_;
Subroutine _observed_command: not called CC=28 SCAR=52.2
147 0 ▶ return unless @{ $self->observe };
Branch: 2 branches
BranchTrueFalseTotal
unless @{$self->observe;} 128 27 155
unless @{$self->observe;} 0 0 0
148 0 my $host = $args->{host};
149 0 ▶ my $dev = defined $host && !ref $host ? $self->state->{$host} : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $host && !ref($host) ? : 27 0 27
defined $host && !ref($host) ? : 0 0 0
Condition16%1/6
defined $host and not ref $host
!ll&&!rl&&r
0027
defined $host and not ref $host
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and not ref $host
defined $host not ref $host
MC/DC0%0/2
defined $host and not ref $host
defined $host not ref $host
Truth table33%1/3
A and not(B)
A= defined $hostB= not ref $host
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $hostB= not ref $host
ABresult
0X0
100
111
150 # a chain on a linux shell (a && b; c): observations per link — first, so that a pattern
151 # without an end anchor does not answer the whole chain
152 my @chain = ref $dev eq 'HASH' && ( $dev->{type} // '' ) eq 'linux' && defined $args->{command} && !ref $args->{command}
153 0 ▶ ? Langertha::Holmgang::Shell::split_chain( $args->{command} ) : ();
Branch: 2 branches
BranchTrueFalseTotal
ref $dev eq 'HASH' && ($dev->{'type'} // '') eq 'linux' && defined $args->{'command'} && !ref($args->{'command'}) ? : 25 2 27
ref $dev eq 'HASH' && ($dev->{'type'} // '') eq 'linux' && defined $args->{'command'} && !ref($args->{'command'}) ? : 0 0 0
Condition31%7/22
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"} and not ref $args->{"command"}
!ll&&!rl&&r
2025
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"}
!ll&&!rl&&r
2025
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
!ll&&!rl&&r
2025
$dev->{"type"} // ""
l!l
250
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"} and not ref $args->{"command"}
!ll&&!rl&&r
000
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"}
!ll&&!rl&&r
000
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux"
!ll&&!rl&&r
000
$dev->{"type"} // ""
l!l
00
MC/DC25%1/4
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"} and not ref $args->{"command"}
ref $dev eq "HASH" $dev->{"type"} defined $args->{"command"} not ref $args->{"command"}
MC/DC0%0/4
ref $dev eq "HASH" and ($dev->{"type"} // "") eq "linux" and defined $args->{"command"} and not ref $args->{"command"}
ref $dev eq "HASH" $dev->{"type"} defined $args->{"command"} not ref $args->{"command"}
Truth table40%2/5
A and B and C and not(D)
A= ref $dev eq "HASH"B= $dev->{"type"}C= defined $args->{"command"}D= not ref $args->{"command"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and not(D)
A= ref $dev eq "HASH"B= $dev->{"type"}C= defined $args->{"command"}D= not ref $args->{"command"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
154 0 ▶ if ( @chain <= 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@chain <= 1) 20 7 27
if (@chain <= 1) 0 0 0
155 0 my ( $obs, $obs_ok ) = $self->_observe($args);
156 0 ▶ return defined $obs ? ( $obs, $args, $obs_ok ) : ();
Branch: 2 branches
BranchTrueFalseTotal
defined $obs ? : 8 12 20
defined $obs ? : 0 0 0
157 }
158 0 ▶ return unless grep { defined( ( $self->_observe( { %$args, command => $_->[1] } ) )[0] ) } @chain;
Branch: 2 branches
BranchTrueFalseTotal
unless grep {defined(($self->_observe({%$args, "command", $_->[1]}))[0]);} @chain 0 7 7
unless grep {defined(($self->_observe({%$args, "command", $_->[1]}))[0]);} @chain 0 0 0
159 0 my ( @out, @gaps );
160 0 my $ok = 1;
161 0 for my $g ( @chain ) {
162 0 my ( $op, $cmd ) = @$g;
163 0 ▶ next if $op eq '&&' && !$ok || $op eq '||' && $ok;
Branch: 2 branches
BranchTrueFalseTotal
if $op eq "&&" and not $ok or $op eq "||" and $ok 1 17 18
if $op eq "&&" and not $ok or $op eq "||" and $ok 0 0 0
Condition38%7/18
$op eq "&&" and not $ok or $op eq "||" and $ok
l!l&&r!l&&!r
1017
$op eq "&&" and not $ok
!ll&&!rl&&r
1611
$op eq "||" and $ok
!ll&&!rl&&r
1520
$op eq "&&" and not $ok or $op eq "||" and $ok
l!l&&r!l&&!r
000
$op eq "&&" and not $ok
!ll&&!rl&&r
000
$op eq "||" and $ok
!ll&&!rl&&r
000
MC/DC50%2/4
$op eq "&&" and not $ok or $op eq "||" and $ok
$op eq "&&" not $ok $op eq "||" $ok
MC/DC0%0/4
$op eq "&&" and not $ok or $op eq "||" and $ok
$op eq "&&" not $ok $op eq "||" $ok
Truth table57%4/7
A and not(B) or C and D
A= $op eq "&&"B= not $okC= $op eq "||"D= $ok
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
Truth table0%0/7
A and not(B) or C and D
A= $op eq "&&"B= not $okC= $op eq "||"D= $ok
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
164 0 my ( $o, $o_ok ) = $self->_observe( { %$args, command => $cmd } );
165 0 ▶ if ( defined $o ) { push @out, $o if length $o; $ok = $o_ok; next }
Branch: 4 branches
BranchTrueFalseTotal
if (defined $o) 7 10 17
if length $o 6 1 7
if (defined $o) 0 0 0
if length $o 0 0 0
166 0 my $next = $self->clone( $self->state );
167 # status of the previous link as $? (a trace the simulator takes out again)
168 0 ▶ $next->{$host}{_rc} = $ok ? 0 : 1 if ref $next->{$host} eq 'HASH';
Branch: 4 branches
BranchTrueFalseTotal
if ref $next->{$host} eq "HASH" 10 0 10
$ok ? : 6 4 10
if ref $next->{$host} eq "HASH" 0 0 0
$ok ? : 0 0 0
169 0 ▶ my ( $died, $t, $k, $gap ) = _guarded( sub { $self->simulators->run_command( $next, $host, $cmd ) } );
Subroutine __ANON__: called CC=1 SCAR=0.4
170 0 ▶ delete $next->{$host}{_rc} if ref $next->{$host} eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $next->{$host} eq "HASH" 10 0 10
if ref $next->{$host} eq "HASH" 0 0 0
171 0 ▶ $self->_set_state($next) unless $died;
Branch: 2 branches
BranchTrueFalseTotal
unless $died 10 0 10
unless $died 0 0 0
172 0 ▶ push @out, $t if defined $t && length $t;
Branch: 2 branches
BranchTrueFalseTotal
if defined $t and length $t 8 2 10
if defined $t and length $t 0 0 0
Condition33%2/6
defined $t and length $t
!ll&&!rl&&r
028
defined $t and length $t
!ll&&!rl&&r
000
MC/DC50%1/2
defined $t and length $t
defined $t length $t
MC/DC0%0/2
defined $t and length $t
defined $t length $t
Truth table66%2/3
A and B
A= defined $tB= length $t
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $tB= length $t
ABresult
0X0
100
111
173 0 ▶ push @gaps, $gap if defined $gap;
Branch: 2 branches
BranchTrueFalseTotal
if defined $gap 0 10 10
if defined $gap 0 0 0
174 0 ▶ $ok = $k ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$k ? : 9 1 10
$k ? : 0 0 0
175 }
176 0 ▶ return ( join( "\n", @out ), $args, $ok, @gaps ? join( '; ', @gaps ) : undef );
Branch: 2 branches
BranchTrueFalseTotal
@gaps ? : 0 7 7
@gaps ? : 0 0 0
177 }
178  
179 # the first fitting observation for these arguments (rendered, pipe filters applied) and
180 # whether the command succeeds; ( undef, 0 ) when none fits
181 55 ▶sub _observe {
Subroutine _observe: called CC=4 SCAR=13.9
182 55 my ( $self, $args ) = @_;
183 55 for my $h ( @{ $self->observe } ) {
184 72 ▶ my $with = $self->_fits( $h, $args ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $with = $self->_fits($h, $args) or next 22 50 72
185 22 my $out = $self->_pipe_filters( $self->_render( $h->{output}, $with ), $args->{command} );
186 22 ▶ return ( $out, $h->{error} ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$h->{'error'} ? : 9 13 22
187 }
188 33 return ( undef, 0 );
189 }
190  
191 1867 ▶sub _handle {
Subroutine _handle: called CC=9 SCAR=22.0
192 1867 my ( $self, $tool, $args ) = @_;
193 1867 ▶ for my $h ( @{ $tool->{handlers} || [] } ) {
Condition50%1/2
$tool->{'handlers'} || []
l!l
18670
MC/DC0%0/1
$tool->{'handlers'} || []
$tool->{'handlers'}
Truth table50%1/2
A
A= $tool->{'handlers'}
Aresult
11
00
194 1869 ▶ my $with = $self->_fits( $h, $args ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $with = $self->_fits($h, $args) or next 1864 5 1869
195 1864 ▶ my @apply = @{ $h->{apply} || [] };
Condition100%2/2
$h->{'apply'} || []
l!l
183826
MC/DC100%1/1
$h->{'apply'} || []
$h->{'apply'}
Truth table100%2/2
A
A= $h->{'apply'}
Aresult
11
00
196 1864 ▶ my $next = @apply ? $self->clone( $self->state ) : $self->state;
Branch: 1 branch
BranchTrueFalseTotal
@apply ? : 1838 26 1864
197 1864 for my $op ( @apply ) {
198 1839 my $err = $self->_apply( $next, $op, $with );
199 1839 ▶ return ( 'Fehler: '.$err, $args, 0 ) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 8 1831 1839
200 }
201 1856 $self->_set_state($next);
202 1856 ▶ return ( $self->_render( $h->{output}, $with ), $args, $h->{error} ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$h->{'error'} ? : 2 1854 1856
203 }
204 3 return ( 'Fehler: dieser Aufruf ist in diesem Szenario nicht vorgesehen.', $args, 0 );
205 }
206  
207 # match and when of a handler or an observation: the arguments with the named captures,
208 # or undef; a when that cannot be evaluated (an unknown filter in its path, only past
209 # lint) does not hold -- never a die out of call (k39)
210 1941 ▶sub _fits {
Subroutine _fits: called CC=5 SCAR=16.1
211 1941 my ( $self, $h, $args ) = @_;
212 1941 ▶ my $cap = $self->_args_match( $h->{match}, $args ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cap = $self->_args_match($h->{"match"}, $args) or return 1891 50 1941
213 1891 my $with = { %$args, %$cap };
214 1891 ▶ for my $w ( @{ $h->{when} || [] } ) {
Condition100%2/2
$h->{'when'} || []
l!l
141877
MC/DC100%1/1
$h->{'when'} || []
$h->{'when'}
Truth table100%2/2
A
A= $h->{'when'}
Aresult
11
00
215 14 my $holds = eval { ( condition( $self->state, $w, $with ) )[0] };
216 14 ▶ return unless $holds;
Branch: 1 branch
BranchTrueFalseTotal
unless $holds 5 9 14
217 }
218 1886 return $with;
219 }
220  
221 1878 ▶sub _render {
Subroutine _render: called CC=1 SCAR=0.0
222 1878 my ( $self, $tmpl, $args ) = @_;
223 1878 return Langertha::Holmgang::Template::render( $tmpl, $self->state, $args, $self->simulators );
224 }
225  
226 # filters behind a pipe (| grep, | head …) on the output of an observation
227 22 ▶sub _pipe_filters {
Subroutine _pipe_filters: called CC=13 SCAR=27.0
228 22 my ( $self, $out, $command ) = @_;
229 22 ▶ return $out unless defined $command && $command =~ /\|/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command and $command =~ /\|/ 20 2 22
Condition66%2/3
defined $command and $command =~ /\|/
!ll&&!rl&&r
0202
MC/DC50%1/2
defined $command and $command =~ /\|/
defined $command $command =~ /\|/
Truth table66%2/3
A and B
A= defined $commandB= $command =~ /\|/
ABresult
0X0
100
111
230 2 ▶ my @w = eval { Langertha::Holmgang::Shell::shell_words($command) } or return $out;
Branch: 1 branch
BranchTrueFalseTotal
my(@w) = eval { do { Langertha::Holmgang::Shell::shell_words($command) } } or return $out 2 0 2
231 2 my @stages = ( [] );
232 2 for ( @w ) {
233 10 ▶ if ( ref $_ && $_->{op} eq '|' ) { push @stages, [] }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ and $_->{'op'} eq '|') { } 2 8 10
elsif (not ref $_) { } 8 0 8
Condition66%2/3
ref $_ and $_->{"op"} eq "|"
!ll&&!rl&&r
802
MC/DC50%1/2
ref $_ and $_->{"op"} eq "|"
ref $_ $_->{"op"} eq "|"
Truth table66%2/3
A and B
A= ref $_B= $_->{"op"} eq "|"
ABresult
0X0
100
111
234 8 elsif ( !ref $_ ) { push @{ $stages[-1] }, $_ }
235 }
236 2 shift @stages;
237 2 for my $st ( @stages ) {
238 2 ▶ shift @$st while @$st && $st->[0] eq 'sudo';
Branch: 1 branch
BranchTrueFalseTotal
@$st and $st->[0] eq "sudo" and do { shift @$st } 0 2 2
Condition33%1/3
@$st and $st->[0] eq "sudo"
!ll&&!rl&&r
020
MC/DC0%0/2
@$st and $st->[0] eq "sudo"
@$st $st->[0] eq "sudo"
Truth table33%1/3
A and B
A= @$stB= $st->[0] eq "sudo"
ABresult
0X0
100
111
239 2 ▶ next unless @$st;
Branch: 1 branch
BranchTrueFalseTotal
unless @$st 0 2 2
240 2 my ( $t ) = Langertha::Holmgang::Shell::Filter::filter_output( $out, $st );
241 2 ▶ $out = $t if defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t 2 0 2
242 }
243 2 return $out;
244 }
245  
246 # the patterns per argument: a hash of the named captures (true, maybe empty) or undef
247 1941 ▶sub _args_match {
Subroutine _args_match: called CC=5 SCAR=16.1
248 1941 my ( $self, $m, $args ) = @_;
249 1941 my %cap;
250 1941 ▶ for my $k ( sort keys %{ $m || {} } ) {
Condition100%2/2
$m || {}
l!l
5771364
MC/DC100%1/1
$m || {}
$m
Truth table100%2/2
A
A= $m
Aresult
11
00
251 601 my $v = flat( $args->{$k} );
252 601 ▶ return undef unless defined $v && $v =~ /$m->{$k}/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and $v =~ /$m->{$k}/ 50 551 601
Condition66%2/3
defined $v and $v =~ /$m->{$k}/
!ll&&!rl&&r
050551
MC/DC50%1/2
defined $v and $v =~ /$m->{$k}/
defined $v $v =~ /$m->{$k}/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /$m->{$k}/
ABresult
0X0
100
111
253 551 %cap = ( %cap, %+ );
254 }
255 1891 return \%cap;
256 }
257  
258  
259 1900 ▶sub value {
Subroutine value: called CC=7 SCAR=21.0
Pod documented
260 1900 my ( $self, $t, $args ) = @_;
261 1900 ▶ return { map { $_ => $self->value( $t->{$_}, $args ) } keys %$t } if ref $t eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $t eq "HASH" 32 1868 1900
262 0 ▶ return [ map { $self->value( $_, $args ) } @$t ] if ref $t eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $t eq "ARRAY" 0 1868 1868
263 1868 ▶ return $t if !defined $t || ref $t;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $t or ref $t 0 1868 1868
Condition33%1/3
not defined $t or ref $t
l!l&&r!l&&!r
001868
MC/DC0%0/2
not defined $t or ref $t
not defined $t ref $t
Truth table33%1/3
not(A) or B
A= not defined $tB= ref $t
ABresult
1X1
011
000
264 1868 ▶ return filter_value( $args->{$1}, $2 ) if $t =~ /\A\{([A-Za-z_][A-Za-z0-9_]*)(?:\|([a-z]+))?\}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /\A\{([A-Za-z_][A-Za-z0-9_]*)(?:\|([a-z]+))?\}\z/ 1595 273 1868
265 273 ▶ return $t =~ /\{[A-Za-z_]/ ? interp_text( $t, $args ) : $t;
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\{[A-Za-z_]/ ? : 0 273 273
266 }
267  
268 # the container at a path without its last segment; hashes on the way are created
269 1839 ▶sub _parent {
Subroutine _parent: called CC=7 SCAR=27.8
270 1839 my ( $self, $d, @seg ) = @_;
271 1839 my $last = pop @seg;
272 1839 for my $k ( @seg ) {
273 1214 ▶ if ( ref $d eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $d eq 'HASH') { } 1214 0 1214
elsif (ref $d eq 'ARRAY' and $k =~ /\A\d+\z/ and $k < @$d) { } 0 0 0
274 1214 ▶ $d->{$k} //= {};
Condition50%1/2
$d->{$k} //= {}
l!l
12140
MC/DC0%0/1
$d->{$k} //= {}
$d->{$k}
Truth table50%1/2
A
A= $d->{$k}
Aresult
11
00
275 1214 $d = $d->{$k};
276 }
277 ▶ elsif ( ref $d eq 'ARRAY' && $k =~ /\A\d+\z/ && $k < @$d ) {
Condition0%0/6
ref $d eq "ARRAY" and $k =~ /\A\d+\z/ and $k < @$d
!ll&&!rl&&r
000
ref $d eq "ARRAY" and $k =~ /\A\d+\z/
!ll&&!rl&&r
000
MC/DC0%0/3
ref $d eq "ARRAY" and $k =~ /\A\d+\z/ and $k < @$d
ref $d eq "ARRAY" $k =~ /\A\d+\z/ $k < @$d
Truth table0%0/4
A and B and C
A= ref $d eq "ARRAY"B= $k =~ /\A\d+\z/C= $k < @$d
ABCresult
0XX0
10X0
1100
1111
278 0 $d = $d->[$k];
279 }
280 0 else { return ( undef, $last ) }
281 }
282 1839 return ( $d, $last );
283 }
284  
285 44 ▶sub _list_at {
Subroutine _list_at: called CC=8 SCAR=27.1
286 44 my ( $self, $state, $seg, $create ) = @_;
287 44 my ( $p, $last ) = $self->_parent( $state, @$seg );
288 44 ▶ return undef unless ref $p;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 0 44 44
289 44 ▶ if ( ref $p eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p eq "HASH") 44 0 44
290 44 ▶ $p->{$last} = [] if $create && !defined $p->{$last};
Branch: 1 branch
BranchTrueFalseTotal
if $create and not defined $p->{$last} 0 44 44
Condition66%2/3
$create and not defined $p->{$last}
!ll&&!rl&&r
4400
MC/DC0%0/2
$create and not defined $p->{$last}
$create not defined $p->{$last}
Truth table66%2/3
A and not(B)
A= $createB= not defined $p->{$last}
ABresult
0X0
100
111
291 44 ▶ return ref $p->{$last} eq 'ARRAY' ? $p->{$last} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $p->{$last} eq 'ARRAY' ? : 44 0 44
292 }
293 0 ▶ return $last =~ /\A\d+\z/ && ref $p->[$last] eq 'ARRAY' ? $p->[$last] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$last =~ /\A\d+\z/ && ref $p->[$last] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
$last =~ /\A\d+\z/ and ref $p->[$last] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$last =~ /\A\d+\z/ and ref $p->[$last] eq "ARRAY"
$last =~ /\A\d+\z/ ref $p->[$last] eq "ARRAY"
Truth table0%0/3
A and B
A= $last =~ /\A\d+\z/B= ref $p->[$last] eq "ARRAY"
ABresult
0X0
100
111
294 }
295  
296 3 ▶sub _index {
Subroutine _index: called CC=6 SCAR=19.6
297 3 my ( $self, $v, $list, $what, $allow_end ) = @_;
298 3 ▶ my $max = @$list - ( $allow_end ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$allow_end ? : 1 2 3
299 3 ▶ die $what." '".( $v // '' )."' ist keine Nummer\n" unless defined $v && "$v" =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and "$v" =~ /\A\d+\z/ 0 3 3
Condition20%1/5
defined $v and "$v" =~ /\A\d+\z/
!ll&&!rl&&r
003
$v // ""
l!l
00
MC/DC0%0/2
defined $v and "$v" =~ /\A\d+\z/
defined $v "$v" =~ /\A\d+\z/
MC/DC0%0/1
$v // ""
$v
Truth table33%1/3
A and B
A= defined $vB= "$v" =~ /\A\d+\z/
ABresult
0X0
100
111
Truth table0%0/2
A
A= $v
Aresult
11
00
300 3 ▶ die $what.' '.$v.' gibt es nicht (0 bis '.$max.")\n" if $v > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $v > $max 1 2 3
301 2 return 0 + $v;
302 }
303  
304 # one change of a handler's apply, as format 2 writes it ({ set => PATH, value => … });
305 # returns undef or the error text for the model
306 1839 ▶sub _apply {
Subroutine _apply: called CC=21 SCAR=36.5
307 1839 my ( $self, $state, $op, $args ) = @_;
308 1839 my ( $kind ) = grep { exists $op->{$_} } @OPS;
309 1839 my $err;
310 1839 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { die 'unbekannte Aenderung ' . join(",", sort(keys %$op)) . "\n" unless defined $kind; my(@seg) = path($op->{$kind}, $args); if ($kind eq "set") { () = $self->_parent($state, @seg); die "Pfad nicht vorhanden\n" unless ref $p; if (ref $p eq "HASH") { $p->{$last} = $self->value($op->{"value"}, $args); } else { $$p[$self->_index($last, $p, "Eintrag")] = $self->value($op->{"value"}, $args); } ; } elsif ($kind eq "push") { my $l = $self->_list_at($state, \@seg, 1) or die "keine Liste\n"; push @$l, $self->value($op->{"value"}, $args); } elsif ($kind eq "insert") { my $l = $self->_list_at($state, \@seg, 1) or die "keine Liste\n"; my $at = $self->_index($self->value($op->{"at"}, $args), $l, "Position", 1); splice @$l, $at, 0, $self->value($op->{"value"}, $args); } elsif ($kind eq "delete") { () = $self->_parent($state, @seg); die "nicht vorhanden\n" unless ref $p eq "HASH" and exists $p->{$last} or ref $p eq "ARRAY" and $last =~ /\A\d+\z/ and $last < @$p; if (ref $p eq "HASH") { delete $p->{$last}; } else { splice @$p, $last, 1; } ; } elsif ($kind eq "remove") { my $l = $self->_list_at($state, \@seg, 0) or die "keine Liste\n"; my(@keep) = grep({not element_match($_, $op->{"where"}, $args);} @$l); die "kein passender Eintrag\n" if @keep == @$l; @$l = @keep; } else { my $l = $self->_list_at($state, \@seg, 0) or die "keine Liste\n"; my $from = $self->_index($self->value($op->{"from"}, $args), $l, "Eintrag"); my($item) = splice(@$l, $from, 1); my $to = $self->_index($self->value($op->{"to"}, $args), $l, "Ziel", 1); splice @$l, $to, 0, $item; } ; 1 } } or $err = ($@ =~ s/$Langertha::Holmgang::Target::LOCATION\.?\n?\z//r) =~ s/\s+\z//r 1831 8 1839
311 1839 ▶ die 'unbekannte Aenderung '.join( ',', sort keys %$op )."\n" unless defined $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kind 0 1839 1839
312 1839 my @seg = path( $op->{$kind}, $args );
313 1839 ▶ if ( $kind eq 'set' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($kind eq 'set') { } 1794 45 1839
elsif ($kind eq 'push') { } 40 5 45
elsif ($kind eq 'insert') { } 0 5 5
elsif ($kind eq 'delete') { } 1 4 5
elsif ($kind eq 'remove') { } 2 2 4
314 1794 my ( $p, $last ) = $self->_parent( $state, @seg );
315 1794 ▶ die "Pfad nicht vorhanden\n" unless ref $p;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 0 1794 1794
316 1794 ▶ if ( ref $p eq 'HASH' ) { $p->{$last} = $self->value( $op->{value}, $args ) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p eq 'HASH') { } 1794 0 1794
317 0 else { $p->[ $self->_index( $last, $p, 'Eintrag' ) ] = $self->value( $op->{value}, $args ) }
318 }
319 elsif ( $kind eq 'push' ) {
320 40 ▶ my $l = $self->_list_at( $state, \@seg, 1 ) or die "keine Liste\n";
Branch: 1 branch
BranchTrueFalseTotal
my $l = $self->_list_at($state, \@seg, 1) or die "keine Liste\n" 40 0 40
321 40 push @$l, $self->value( $op->{value}, $args );
322 }
323 elsif ( $kind eq 'insert' ) {
324 0 ▶ my $l = $self->_list_at( $state, \@seg, 1 ) or die "keine Liste\n";
Branch: 1 branch
BranchTrueFalseTotal
my $l = $self->_list_at($state, \@seg, 1) or die "keine Liste\n" 0 0 0
325 0 my $at = $self->_index( $self->value( $op->{at}, $args ), $l, 'Position', 1 );
326 0 splice @$l, $at, 0, $self->value( $op->{value}, $args );
327 }
328 elsif ( $kind eq 'delete' ) {
329 1 my ( $p, $last ) = $self->_parent( $state, @seg );
330 1 ▶ die "nicht vorhanden\n" unless ref $p eq 'HASH' && exists $p->{$last}
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p eq "HASH" and exists $p->{$last} or ref $p eq "ARRAY" and $last =~ /\A\d+\z/ and $last < @$p 1 0 1
Condition33%4/12
ref $p eq "HASH" and exists $p->{$last} or ref $p eq "ARRAY" and $last =~ /\A\d+\z/ and $last < @$p
l!l&&r!l&&!r
001
ref $p eq "HASH" and exists $p->{$last}
!ll&&!rl&&r
010
ref $p eq "ARRAY" and $last =~ /\A\d+\z/ and $last < @$p
!ll&&!rl&&r
100
ref $p eq "ARRAY" and $last =~ /\A\d+\z/
!ll&&!rl&&r
100
MC/DC0%0/5
ref $p eq "HASH" and exists $p->{$last} or ref $p eq "ARRAY" and $last =~ /\A\d+\z/ and $last < @$p
ref $p eq "HASH" exists $p->{$last} ref $p eq "ARRAY" $last =~ /\A\d+\z/ $last < @$p
Truth table11%1/9
A and B or C and D and E
A= ref $p eq "HASH"B= exists $p->{$last}C= ref $p eq "ARRAY"D= $last =~ /\A\d+\z/E= $last < @$p
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
331 || ref $p eq 'ARRAY' && $last =~ /\A\d+\z/ && $last < @$p;
332 0 ▶ if ( ref $p eq 'HASH' ) { delete $p->{$last} }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p eq 'HASH') { } 0 0 0
333 0 else { splice @$p, $last, 1 }
334 }
335 elsif ( $kind eq 'remove' ) {
336 2 ▶ my $l = $self->_list_at( $state, \@seg, 0 ) or die "keine Liste\n";
Branch: 1 branch
BranchTrueFalseTotal
my $l = $self->_list_at($state, \@seg, 0) or die "keine Liste\n" 2 0 2
337 2 my @keep = grep { !element_match( $_, $op->{where}, $args ) } @$l;
338 2 ▶ die "kein passender Eintrag\n" if @keep == @$l;
Branch: 1 branch
BranchTrueFalseTotal
if @keep == @$l 1 1 2
339 1 @$l = @keep;
340 }
341 else { # move
342 2 ▶ my $l = $self->_list_at( $state, \@seg, 0 ) or die "keine Liste\n";
Branch: 1 branch
BranchTrueFalseTotal
my $l = $self->_list_at($state, \@seg, 0) or die "keine Liste\n" 2 0 2
343 2 my $from = $self->_index( $self->value( $op->{from}, $args ), $l, 'Eintrag' );
344 1 my ( $item ) = splice @$l, $from, 1;
345 1 my $to = $self->_index( $self->value( $op->{to}, $args ), $l, 'Ziel', 1 );
346 1 splice @$l, $to, 0, $item;
347 }
348 1831 1;
349 } or $err = ( $@ =~ s/$Langertha::Holmgang::Target::LOCATION\.?\n?\z//r =~ s/\s+\z//r );
350 1839 return $err;
351 }
352  
353  
354 26296 ▶sub diff {
Subroutine diff: called CC=15 SCAR=27.1
Pod documented
355 26296 my ( $self, $a, $b, @at ) = @_;
356 26296 ▶ if ( ref $a eq 'HASH' && ref $b eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a eq "HASH" and ref $b eq "HASH") 11104 15192 26296
Condition66%2/3
ref $a eq "HASH" and ref $b eq "HASH"
!ll&&!rl&&r
15192011104
MC/DC50%1/2
ref $a eq "HASH" and ref $b eq "HASH"
ref $a eq "HASH" ref $b eq "HASH"
Truth table66%2/3
A and B
A= ref $a eq "HASH"B= ref $b eq "HASH"
ABresult
0X0
100
111
357 11104 my %k = map { $_ => 1 } grep { !/\A_/ } keys %$a, keys %$b;
358 11104 my @out;
359 11104 for my $k ( sort keys %k ) {
360 # a new or removed hash is shown key by key
361 22200 ▶ if ( !exists $b->{$k} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $b->{$k}) { } 4 22196 22200
elsif (not exists $a->{$k}) { } 889 21307 22196
362 1 push @out, ref $a->{$k} eq 'HASH' && %{ $a->{$k} } ? $self->diff( $a->{$k}, {}, @at, $k )
363 4 ▶ : { path => [ @at, $k ], before => $a->{$k} };
Branch: 1 branch
BranchTrueFalseTotal
ref $a->{$k} eq 'HASH' && %{$a->{$k};} ? : 1 3 4
Condition66%2/3
ref $a->{$k} eq "HASH" and %{$a->{$k};}
!ll&&!rl&&r
301
MC/DC50%1/2
ref $a->{$k} eq "HASH" and %{$a->{$k};}
ref $a->{$k} eq "HASH" %{$a->{$k};}
Truth table66%2/3
A and B
A= ref $a->{$k} eq "HASH"B= %{$a->{$k};}
ABresult
0X0
100
111
364 }
365 elsif ( !exists $a->{$k} ) {
366 229 push @out, ref $b->{$k} eq 'HASH' && %{ $b->{$k} } ? $self->diff( {}, $b->{$k}, @at, $k )
367 889 ▶ : { path => [ @at, $k ], after => $b->{$k} };
Branch: 1 branch
BranchTrueFalseTotal
ref $b->{$k} eq 'HASH' && %{$b->{$k};} ? : 229 660 889
Condition66%2/3
ref $b->{$k} eq "HASH" and %{$b->{$k};}
!ll&&!rl&&r
6600229
MC/DC50%1/2
ref $b->{$k} eq "HASH" and %{$b->{$k};}
ref $b->{$k} eq "HASH" %{$b->{$k};}
Truth table66%2/3
A and B
A= ref $b->{$k} eq "HASH"B= %{$b->{$k};}
ABresult
0X0
100
111
368 }
369 21307 else { push @out, $self->diff( $a->{$k}, $b->{$k}, @at, $k ) }
370 }
371 11104 return @out;
372 }
373 15192 ▶ if ( ref $a eq 'ARRAY' && ref $b eq 'ARRAY' && @$a == @$b && grep { ref } @$a, @$b ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a eq "ARRAY" and ref $b eq "ARRAY" and @$a == @$b and grep {ref $_;} @$a, @$b) 10 15182 15192
Condition88%8/9
ref $a eq "ARRAY" and ref $b eq "ARRAY" and @$a == @$b and grep {ref $_;} @$a, @$b
!ll&&!rl&&r
1441277010
ref $a eq "ARRAY" and ref $b eq "ARRAY" and @$a == @$b
!ll&&!rl&&r
14306106780
ref $a eq "ARRAY" and ref $b eq "ARRAY"
!ll&&!rl&&r
143060886
MC/DC75%3/4
ref $a eq "ARRAY" and ref $b eq "ARRAY" and @$a == @$b and grep {ref $_;} @$a, @$b
ref $a eq "ARRAY" ref $b eq "ARRAY" @$a == @$b grep {ref $_;} @$a, @$b
Truth table80%4/5
A and B and C and D
A= ref $a eq "ARRAY"B= ref $b eq "ARRAY"C= @$a == @$bD= grep {ref $_;} @$a, @$b
ABCDresult
0XXX0
10XX0
110X0
11100
11111
374 10 return map { $self->diff( $a->[$_], $b->[$_], @at, $_ ) } 0 .. $#$a;
375 }
376 15182 ▶ return () if $JSON->encode($a) eq $JSON->encode($b);
Branch: 1 branch
BranchTrueFalseTotal
if $JSON->encode($a) eq $JSON->encode($b) 11705 3477 15182
377 3477 return { path => \@at, before => $a, after => $b };
378 }
379  
380  
381 2308 ▶sub path_text {
Subroutine path_text: called CC=5 SCAR=16.1
Pod documented
382 2308 my ( $self, $seg ) = @_;
383 2308 my $s = '';
384 2308 for my $k ( @$seg ) {
385 5167 ▶ if ( $k =~ /[.\s"\[\]]/ || !length $k ) { $s .= '['.$JSON->encode("$k").']' }
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /[.\s"\[\]]/ or not length $k) { } 4 5163 5167
Condition100%3/3
$k =~ /[.\s"\[\]]/ or not length $k
l!l&&r!l&&!r
315163
MC/DC100%2/2
$k =~ /[.\s"\[\]]/ or not length $k
$k =~ /[.\s"\[\]]/ not length $k
Truth table100%3/3
A or not(B)
A= $k =~ /[.\s"\[\]]/B= not length $k
ABresult
1X1
011
000
386 5163 ▶ else { $s .= ( length $s ? '.' : '' ).$k }
Branch: 1 branch
BranchTrueFalseTotal
length $s ? : 2855 2308 5163
387 }
388 2308 return $s;
389 }
390  
391  
392 1928 ▶sub covered {
Subroutine covered: called CC=8 SCAR=20.8
Pod documented
393 1928 my ( $self, $seg, $allowed ) = @_;
394 1928 ALLOWED: for my $al ( @$allowed ) {
395 2083 ▶ next if @$al > @$seg;
Branch: 1 branch
BranchTrueFalseTotal
if @$al > @$seg 30 2053 2083
396 2053 for my $i ( 0 .. $#$al ) {
397 3955 ▶ next if $al->[$i] eq '*' || $al->[$i] eq $seg->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $al->[$i] eq "*" or $al->[$i] eq $seg->[$i] 3733 222 3955
Condition100%3/3
$al->[$i] eq "*" or $al->[$i] eq $seg->[$i]
l!l&&r!l&&!r
13732222
MC/DC100%2/2
$al->[$i] eq "*" or $al->[$i] eq $seg->[$i]
$al->[$i] eq "*" $al->[$i] eq $seg->[$i]
Truth table100%3/3
A or B
A= $al->[$i] eq "*"B= $al->[$i] eq $seg->[$i]
ABresult
1X1
011
000
398 222 ▶ next ALLOWED unless index( $al->[$i], '*' ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($al->[$i], "*") != -1 219 3 222
399 3 my $re = join '[^/]*', map { quotemeta } split /\*/, $al->[$i], -1;
400 3 ▶ next ALLOWED unless $seg->[$i] =~ /\A$re\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $seg->[$i] =~ /\A$re\z/ 2 1 3
401 }
402 1832 return 1;
403 }
404 96 return 0;
405 }
406  
407 41 __PACKAGE__->meta->make_immutable;
408  
409 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Postfix.pm »