blib/lib/Langertha/Holmgang/Sim/RouterOS.pm

filter: Statementstmt 94.7% 790 / 834 Branchbran 72.9% 321 / 440 Conditioncond 52.5% 218 / 415 MC/DCmcdc 27.0% 63 / 233 Subroutinesub 94.9% 75 / 79 Podpod 100% 4 / 4 totaltotal 73.3% 1471 / 2005 CC 404 SCAR 29.5
CC
404
Cov
79%
_route
74.0
__ANON__
42.8
_cond
32.8
CRAP 19.1
« blib/lib/Langertha/Holmgang/CLI.pm ↑ Summary blib/lib/Langertha/Holmgang/Runner.pm »
1 package Langertha::Holmgang::Sim::RouterOS;
2 # ABSTRACT: The simulator of device type routeros — a RouterOS (MikroTik) console
3  
4 40 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 with 'Langertha::Holmgang::Role::Simulator';
9  
10 40 our $VERSION = '0.002';
11  
12  
13 40 my @FLAGS = ( [ X => 'disabled' ], [ I => 'invalid' ], [ D => 'dynamic' ] );
14  
15 40 my %MENU;
16  
17 1120 ▶sub _menu {
Subroutine _menu: called CC=1 SCAR=0.0
18 1120 my ( $path, %o ) = @_;
19 1120 my $m = { kind => 'list', flags => \@FLAGS, props => [], readonly => [], required => [], %o, path => $path };
20 1120 $m->{is_prop} = { map { $_ => 1 } @{ $m->{props} }, 'comment', map { $_->[1] } @{ $m->{flags} } };
21 1120 $m->{ro} = { map { $_ => 1 } @{ $m->{readonly} }, grep { $_ ne 'disabled' } map { $_->[1] } @{ $m->{flags} } };
22 1120 $m->{is_flag} = { map { $_->[1] => 1 } @{ $m->{flags} } };
23 1120 $m->{has_name} = grep { $_ eq 'name' } @{ $m->{props} };
24 1120 $MENU{$path} = $m;
25 1120 return;
26 }
27  
28 40 my @FW = qw(
29 chain action src-address dst-address protocol src-port dst-port port in-interface out-interface
30 in-interface-list out-interface-list connection-state connection-nat-state connection-type
31 connection-mark packet-mark routing-mark src-address-list dst-address-list src-address-type
32 dst-address-type src-mac-address in-bridge-port out-bridge-port tcp-flags tcp-mss icmp-options
33 packet-size ttl dscp priority limit dst-limit connection-limit connection-rate content
34 layer7-protocol ipsec-policy fragment nth random time per-connection-classifier jump-target
35 address-list address-list-timeout passthrough log log-prefix
36 );
37 40 my @FW_ACT = qw( accept add-dst-to-address-list add-src-to-address-list jump log passthrough return );
38 40 my @RUN = ( [ X => 'disabled' ], [ R => 'running' ] );
39  
40 40 _menu '/ip firewall filter',
41 props => [ @FW, qw( reject-with hw-offload ) ],
42 actions => [ @FW_ACT, qw( drop fasttrack-connection reject tarpit ) ],
43 required => ['chain'], move => 1, fw => 1;
44 40 _menu '/ip firewall nat',
45 props => [ @FW, qw( to-addresses to-ports randomise ) ],
46 actions => [ @FW_ACT, qw( dst-nat endpoint-independent-nat masquerade netmap redirect same src-nat ) ],
47 required => ['chain'], move => 1, fw => 1;
48 40 _menu '/ip firewall mangle',
49 props => [ @FW, qw( new-connection-mark new-packet-mark new-routing-mark new-mss new-dscp new-ttl
50 new-priority route-dst sniff-id sniff-target sniff-target-port ) ],
51 actions => [ @FW_ACT, qw( change-dscp change-mss change-ttl clear-df fasttrack-connection mark-connection
52 mark-packet mark-routing route set-priority sniff-pc sniff-tzsp strip-ipv4-options ) ],
53 required => ['chain'], move => 1, fw => 1;
54 40 _menu '/ip firewall raw',
55 props => [@FW],
56 actions => [ @FW_ACT, qw( drop notrack ) ],
57 required => ['chain'], move => 1, fw => 1;
58 40 _menu '/ip firewall address-list',
59 props => [qw( list address timeout creation-time )], readonly => ['creation-time'], required => [qw( list address )];
60 40 _menu '/ip address', props => [qw( address network interface )], required => [qw( address interface )];
61 40 _menu '/ip route', props => [qw( dst-address gateway distance scope target-scope routing-table routing-mark
62 pref-src check-gateway type blackhole vrf-interface suppress-hw-offload )];
63 40 _menu '/ip pool', props => [qw( name ranges next-pool )], autoname => 'pool';
64 # belegte Adressen der Pools: abgeleitet aus den DHCP-Leases (nur lesen)
65 40 _menu '/ip pool used', props => [qw( pool address owner info )], flags => [], derived => 1, noadd => 1;
66 40 _menu '/ip dhcp-server',
67 props => [qw( name interface address-pool lease-time authoritative add-arp bootp-support always-broadcast
68 conflict-detection lease-script relay server-address use-radius )],
69 required => ['interface'], autoname => 'dhcp';
70 40 _menu '/ip dhcp-server network',
71 props => [qw( address gateway netmask dns-server domain ntp-server wins-server next-server boot-file-name
72 dhcp-option )],
73 required => ['address'];
74 40 _menu '/ip dhcp-server lease',
75 props => [qw( address mac-address client-id server lease-time host-name status last-seen active-address
76 active-mac-address active-client-id active-server expires-after always-broadcast block-access
77 address-lists rate-limit use-src-mac )],
78 readonly => [qw( host-name status last-seen active-address active-mac-address active-client-id
79 active-server expires-after )],
80 flags => [ [ X => 'disabled' ], [ R => 'radius' ], [ D => 'dynamic' ], [ B => 'blocked' ] ],
81 required => ['address'], lease => 1;
82 40 _menu '/ip dhcp-client',
83 props => [qw( interface add-default-route default-route-distance use-peer-dns use-peer-ntp status address
84 gateway dhcp-server )],
85 readonly => [qw( status address gateway dhcp-server )], required => ['interface'];
86 40 _menu '/ip dns static',
87 props => [qw( name regexp address type cname text forward-to ttl match-subdomain address-list )], move => 1;
88 40 _menu '/ip arp', props => [qw( address mac-address interface published )], required => ['address'];
89 40 _menu '/ip dns', kind => 'settings',
90 props => [qw( servers dynamic-servers use-doh-server verify-doh-cert doh-max-server-connections
91 doh-max-concurrent-queries doh-timeout allow-remote-requests max-udp-packet-size query-server-timeout
92 query-total-timeout max-concurrent-queries max-concurrent-tcp-sessions cache-size cache-max-ttl
93 address-list-extra-time vrf mdns-repeat-ifaces cache-used )],
94 readonly => [qw( dynamic-servers cache-used )];
95 40 _menu '/system identity', kind => 'settings', props => ['name'], identity => 1;
96 40 _menu '/system resource', kind => 'resource';
97 40 _menu '/interface',
98 props => [qw( name default-name type mtu actual-mtu l2mtu max-l2mtu mac-address last-link-up-time
99 link-downs )],
100 readonly => [qw( default-name type actual-mtu max-l2mtu mac-address last-link-up-time link-downs )],
101 flags => [ [ D => 'dynamic' ], [ X => 'disabled' ], [ R => 'running' ], [ S => 'slave' ] ], noadd => 1;
102 40 _menu '/interface ethernet',
103 props => [qw( name default-name mtu l2mtu mac-address arp auto-negotiation speed )],
104 readonly => ['default-name'], flags => \@RUN, noadd => 1;
105 40 _menu '/interface pppoe-client',
106 props => [qw( name interface user password service-name ac-name add-default-route default-route-distance
107 use-peer-dns max-mtu max-mru mrru profile dial-on-demand allow keepalive-timeout )],
108 flags => \@RUN, required => ['interface'], autoname => 'pppoe-out';
109 40 _menu '/interface vlan', props => [qw( name mtu arp vlan-id interface )], flags => \@RUN,
110 required => [qw( interface vlan-id )], autoname => 'vlan';
111 40 _menu '/interface bridge', props => [qw( name mtu arp protocol-mode vlan-filtering admin-mac auto-mac )],
112 flags => \@RUN, autoname => 'bridge';
113 40 _menu '/interface bridge port', props => [qw( interface bridge pvid frame-types ingress-filtering horizon hw )],
114 required => [qw( interface bridge )], move => 1;
115 40 _menu '/interface list', props => [qw( name include exclude )], required => ['name'];
116 40 _menu '/interface list member', props => [qw( list interface )], required => [qw( list interface )];
117 40 _menu '/interface wireguard', props => [qw( name mtu listen-port private-key public-key )], flags => \@RUN,
118 autoname => 'wireguard';
119 40 _menu '/interface wireguard peers',
120 props => [qw( name interface public-key endpoint-address endpoint-port allowed-address preshared-key
121 persistent-keepalive )],
122 required => [qw( interface public-key )];
123  
124 # Reihenfolge der Bloecke in export (wie RouterOS: erst Schnittstellen, dann IP)
125 40 my @EXPORT_ORDER = (
126 '/interface bridge', '/interface pppoe-client', '/interface vlan', '/interface wireguard',
127 '/interface list', '/ip pool', '/ip dhcp-server', '/interface bridge port',
128 '/interface list member', '/interface wireguard peers', '/ip address', '/ip arp',
129 '/ip dhcp-client', '/ip dhcp-server lease', '/ip dhcp-server network', '/ip dns',
130 '/ip dns static', '/ip firewall address-list', '/ip firewall filter', '/ip firewall mangle',
131 '/ip firewall nat', '/ip firewall raw', '/ip route', '/system identity',
132 );
133  
134 40 my %ESC = ( n => "\n", t => "\t", r => "\r", _ => ' ' );
135  
136 my %CMD = (
137 print => \&_c_print,
138 export => \&_c_export,
139 add => \&_c_add,
140 set => \&_c_set,
141 remove => \&_c_remove,
142 disable => \&_c_disable,
143 enable => \&_c_enable,
144 comment => \&_c_comment,
145 move => \&_c_move,
146 find => \&_c_find,
147 'make-static' => \&_c_make_static,
148 'reset-counters' => \&_c_noop,
149 'reset-counters-all' => \&_c_noop,
150 reboot => \&_c_reboot,
151 shutdown => \&_c_shutdown,
152 ping => \&_c_ping,
153 traceroute => \&_c_traceroute,
154 0 ▶ quit => sub { return { stop => 1 } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
155 40 );
156  
157 40 my $VERSION_ROS = '7.16.2';
158  
159  
160 # Echte RouterOS-Menues und -Optionen, die der Simulator nicht nachbildet: die
161 # Zeile bekommt eine neutrale (leere) Antwort und wird als Luecke gemeldet.
162 40 our $GAP_RE = qr{
163 \A\s*/?\s*(?:
164 log\b | tool\s+(?!traceroute\b|ping\b)\S | ppp\b | routing\b | queue\b | certificate\b | snmp\b | ipv6\b | user\b | file\b | caps-man\b
165 | system\s+(?:script|scheduler|logging|package|clock|history|ntp|routerboard|health|license|note|backup|upgrade)\b
166 | ip\s+(?:service|neighbor|firewall\s+connection|cloud|ssh|socks|proxy|traffic-flow|upnp|ipsec|hotspot|smb|settings|kid-control)\b
167 | interface\s+(?:monitor-traffic|ethernet\s+monitor|wireless|wifi|lte|sstp-client|l2tp-client|ovpn-client|bonding|eoip|gre)\b
168 )
169 | \bprint\b.*\b(?:stats|interval|follow|follow-only|oid|without-paging|brief|value-list|as-value|stats-detail)\b
170 | \b(?:monitor|monitor-traffic|torch|bandwidth-test|sniffer)\b
171 }xi;
172  
173 98 ▶sub run {
Subroutine run: called CC=16 SCAR=27.7
Pod documented
174 98 my ( $class, $dev, $command, $ctx ) = @_;
175 98 ▶ $ctx //= {};
Condition100%2/2
$ctx //= {}
l!l
917
MC/DC100%1/1
$ctx //= {}
$ctx
Truth table100%2/2
A
A= $ctx
Aresult
11
00
176 98 my @gaps;
177 98 ▶ my $host = $ctx->{host} // $dev->{identity} // 'router';
Condition100%5/5
($$ctx{"host"} // $$dev{"identity"}) // "router"
l!l
935
$$ctx{"host"} // $$dev{"identity"}
l!l&&r!l&&!r
9125
MC/DC100%2/2
($$ctx{"host"} // $$dev{"identity"}) // "router"
$$ctx{"host"} $$dev{"identity"}
Truth table100%3/3
A // B
A= $$ctx{"host"}B= $$dev{"identity"}
ABresult
1X1
011
000
178 98 ▶ return ( "ssh: connect to host $host port 22: Connection timed out", 0 ) if _yes( $dev->{shutdown} );
Branch: 1 branch
BranchTrueFalseTotal
if _yes($$dev{"shutdown"}) 1 97 98
179 97 my $s = { dev => $dev, ctx => $ctx, path => '' };
180 97 my @out;
181 97 my $L = 0;
182 97 ▶ for my $line ( split /\r?\n/, $command // '' ) {
Condition50%1/2
$command // ""
l!l
970
MC/DC0%0/1
$command // ""
$command
Truth table50%1/2
A
A= $command
Aresult
11
00
183 109 $L++;
184 109 ▶ next if $line =~ /\A\s*(?:#.*)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*(?:#.*)?\z/ 1 108 109
185 108 ▶ if ( $line =~ $GAP_RE ) { push @gaps, $line =~ s/\A\s+|\s+\z//gr; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$Langertha::Holmgang::Sim::RouterOS::GAP_RE/) 2 106 108
186 106 my @stmts = eval { _statements( $line, $L ) };
187 106 ▶ if ( my $e = $@ ) { push @out, _msg($e); return ( join( "\n", @out ), 0, _gaps(@gaps) ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 105 106
188 105 for my $st (@stmts) {
189 106 my $r = eval { _statement( $s, $st, $L ) };
190 106 ▶ if ( my $e = $@ ) { push @out, _msg($e); return ( join( "\n", @out ), 0, _gaps(@gaps) ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 23 83 106
191 83 ▶ $r = { out => $r } unless ref $r;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r 80 3 83
192 83 ▶ push @out, $r->{out} if defined $r->{out} && length $r->{out};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"out"} and length $$r{"out"} 44 39 83
Condition66%2/3
defined $$r{"out"} and length $$r{"out"}
!ll&&!rl&&r
03944
MC/DC50%1/2
defined $$r{"out"} and length $$r{"out"}
defined $$r{"out"} length $$r{"out"}
Truth table66%2/3
A and B
A= defined $$r{"out"}B= length $$r{"out"}
ABresult
0X0
100
111
193 83 ▶ return ( join( "\n", @out ), 1, _gaps(@gaps) ) if $r->{stop};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"stop"} 3 80 83
194 }
195 }
196 70 return ( join( "\n", @out ), 1, _gaps(@gaps) );
197 }
198  
199 77 ▶sub device_type { 'routeros' }
Subroutine device_type: called CC=1 SCAR=0.0
Pod documented
200  
201  
202 4 ▶sub run_command {
Subroutine run_command: called CC=1 SCAR=0.0
Pod documented
203 4 my ( $self, $dev, $command, $ctx ) = @_;
204 4 return $self->run( $dev, $command, $ctx );
205 }
206  
207  
208 0 ▶sub menus { return sort keys %MENU }
Subroutine menus: not called CC=1 SCAR=6.9
Pod documented
209  
210 97 ▶sub _gaps { return @_ ? join( '; ', @_ ) : undef }
Subroutine _gaps: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 95 97
211  
212 # --- Fehler -------------------------------------------------------------------
213  
214 11 ▶sub _err { die { msg => $_[0] } }
Subroutine _err: called CC=1 SCAR=0.0
215 13 ▶sub _errat { my ( $msg, $L, $col ) = @_; die { msg => "$msg (line $L column $col)" } }
Subroutine _errat: called CC=1 SCAR=0.0
216  
217 24 ▶sub _msg {
Subroutine _msg: called CC=2 SCAR=7.1
218 24 my ($e) = @_;
219 24 ▶ die $e unless ref $e eq 'HASH'; # Programmfehler nicht verschlucken
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 0 24 24
220 24 return $e->{msg};
221 }
222  
223 # --- Zerlegen -----------------------------------------------------------------
224  
225 106 ▶sub _statements {
Subroutine _statements: called CC=3 SCAR=11.0
226 106 my ( $line, $L ) = @_;
227 106 my @st = ( [] );
228 106 for my $t ( _tokenize( $line, $L, 0 ) ) {
229 471 ▶ if ( $t->{semi} ) { push @st, [] }
Branch: 1 branch
BranchTrueFalseTotal
if ($$t{'semi'}) { } 1 470 471
230 470 else { push @{ $st[-1] }, $t }
231 }
232 105 return grep {@$_} @st;
233 }
234  
235 # Woerter mit Spalte; "..." mit Escapes; [ ... ] als Klammer (br) am Wortende; ; als Trenner
236 114 ▶sub _tokenize {
Subroutine _tokenize: called CC=24 SCAR=33.7
237 114 my ( $line, $L, $off ) = @_;
238 114 my @t;
239 114 my $len = length $line;
240 114 pos($line) = 0;
241 114 while (1) {
242 608 $line =~ /\G[ \t]+/gc;
243 608 ▶ last if ( pos($line) // $len ) >= $len;
Branch: 1 branch
BranchTrueFalseTotal
if (pos $line // $len) >= $len 113 495 608
Condition33%1/3
pos $line // $len
l!l&&r!l&&!r
60800
MC/DC0%0/2
pos $line // $len
pos $line $len
Truth table33%1/3
A // B
A= pos $lineB= $len
ABresult
1X1
011
000
244 495 my $col = pos($line) + 1 + $off;
245 495 ▶ if ( $line =~ /\G;/gc ) { push @t, { semi => 1, col => $col }; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G;/cg) 1 494 495
246 494 my %tok = ( text => '', col => $col );
247 494 ▶ $tok{quoted} = 1 if substr( $line, pos($line), 1 ) eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if substr($line, pos $line, 1) eq "\"" 0 494 494
248 494 ▶ while ( pos($line) < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $line < $len) 878 107 985
249 878 ▶ if ( $line =~ /\G"/gc ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /\G"/cg) { } 7 871 878
elsif ($line =~ /\G\[/cg) { } 9 862 871
elsif ($line =~ /\G([^\s";\[\]]+)/cg) { } 485 377 862
elsif ($line =~ /\G\]/cg) { } 0 377 377
250 7 while (1) {
251 0 ▶ if ( $line =~ /\G\\(.)/gcs ) { $tok{text} .= $ESC{$1} // $1 }
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /\G\\(.)/cgs) { } 0 13 13
elsif ($line =~ /\G"/cg) { } 6 7 13
elsif ($line =~ /\G([^"\\]+)/cg) { } 6 1 7
Condition0%0/3
$ESC{$1} // $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$ESC{$1} // $1
$ESC{$1} $1
Truth table0%0/3
A // B
A= $ESC{$1}B= $1
ABresult
1X1
011
000
252 6 elsif ( $line =~ /\G"/gc ) { last }
253 6 elsif ( $line =~ /\G([^"\\]+)/gc ) { $tok{text} .= $1 }
254 1 else { _errat( 'syntax error', $L, $len + 1 + $off ) }
255 }
256 }
257 elsif ( $line =~ /\G\[/gc ) {
258 9 my $start = pos($line);
259 9 my ( $i, $depth, $inq ) = ( $start, 1, 0 );
260 9 ▶ while ( $i < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 157 0 157
261 157 my $c = substr( $line, $i, 1 );
262 0 ▶ if ( $inq && $c eq '\\' ) { $i++ }
Branch: 4 branches
BranchTrueFalseTotal
if ($inq and $c eq '\\') { } 0 157 157
elsif ($c eq '"') { } 4 153 157
elsif (not $inq and $c eq '[') { } 0 153 153
elsif (not $inq and $c eq ']') { } 9 156 165
Condition66%2/3
$inq and $c eq "\\"
!ll&&!rl&&r
143140
MC/DC0%0/2
$inq and $c eq "\\"
$inq $c eq "\\"
Truth table66%2/3
A and B
A= $inqB= $c eq "\\"
ABresult
0X0
100
111
263 4 elsif ( $c eq '"' ) { $inq = !$inq }
264 0 ▶ elsif ( !$inq && $c eq '[' ) { $depth++ }
Condition66%2/3
not $inq and $c eq "["
!ll&&!rl&&r
121410
MC/DC0%0/2
not $inq and $c eq "["
not $inq $c eq "["
Truth table66%2/3
not(A) and B
A= not $inqB= $c eq "["
ABresult
0X0
100
111
265 9 ▶ elsif ( !$inq && $c eq ']' ) { last unless --$depth }
Branch: 1 branch
BranchTrueFalseTotal
unless --$depth 9 0 9
Condition100%3/3
not $inq and $c eq "]"
!ll&&!rl&&r
121329
MC/DC100%2/2
not $inq and $c eq "]"
not $inq $c eq "]"
Truth table100%3/3
not(A) and B
A= not $inqB= $c eq "]"
ABresult
0X0
100
111
266 148 $i++;
267 }
268 9 ▶ _errat( 'syntax error', $L, $len + 1 + $off ) if $depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth 0 9 9
269 9 $tok{br} = substr( $line, $start, $i - $start );
270 9 $tok{brcol} = $start + 1 + $off;
271 9 pos($line) = $i + 1;
272 9 last;
273 }
274 485 elsif ( $line =~ /\G([^\s";\[\]]+)/gc ) { $tok{text} .= $1 }
275 0 elsif ( $line =~ /\G\]/gc ) { _errat( 'syntax error', $L, pos($line) + $off ) }
276 377 else { last }
277 }
278 493 push @t, \%tok;
279 }
280 113 return @t;
281 }
282  
283 # --- Menuebaum ----------------------------------------------------------------
284  
285 463 ▶sub _paths {
Subroutine _paths: called CC=4 SCAR=13.9
286 463 my ($s) = @_;
287 463 my %p = map { $_ => 1 } keys %MENU, '/system', '/tool';
288 463 for my $k (qw( menus settings )) {
289 926 ▶ next unless ref $s->{dev}{$k} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$s{"dev"}{$k} eq "HASH" 35 891 926
290 891 $p{$_} = 1 for grep {m{\A/[a-z]}} keys %{ $s->{dev}{$k} };
291 }
292 463 return keys %p;
293 }
294  
295 459 ▶sub _children {
Subroutine _children: called CC=5 SCAR=16.1
296 459 my ( $s, $path ) = @_;
297 459 ▶ my $pre = $path eq '' ? '/' : "$path ";
Branch: 1 branch
BranchTrueFalseTotal
$path eq '' ? : 107 352 459
298 459 my %c;
299 459 for my $p ( _paths($s) ) {
300 13770 ▶ next unless length $p > length $pre && index( $p, $pre ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless length $p > length $pre and index($p, $pre) == 0 8801 4969 13770
Condition100%3/3
length $p > length $pre and index($p, $pre) == 0
!ll&&!rl&&r
451642854969
MC/DC100%2/2
length $p > length $pre and index($p, $pre) == 0
length $p > length $pre index($p, $pre) == 0
Truth table100%3/3
A and B
A= length $p > length $preB= index($p, $pre) == 0
ABresult
0X0
100
111
301 4969 my ($first) = split / /, substr( $p, length $pre );
302 4969 $c{$first} = $pre . $first;
303 }
304 459 return \%c;
305 }
306  
307 840 ▶sub _kind {
Subroutine _kind: called CC=6 SCAR=19.3
308 840 my ( $s, $path ) = @_;
309 840 ▶ return $MENU{$path}{kind} if $MENU{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $MENU{$path} 304 536 840
310 536 ▶ return 'list' if ref $s->{dev}{menus} eq 'HASH' && ref $s->{dev}{menus}{$path} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$s{"dev"}{"menus"} eq "HASH" and ref $$s{"dev"}{"menus"}{$path} eq "ARRAY" 0 536 536
Condition33%1/3
ref $$s{"dev"}{"menus"} eq "HASH" and ref $$s{"dev"}{"menus"}{$path} eq "ARRAY"
!ll&&!rl&&r
05360
MC/DC0%0/2
ref $$s{"dev"}{"menus"} eq "HASH" and ref $$s{"dev"}{"menus"}{$path} eq "ARRAY"
ref $$s{"dev"}{"menus"} eq "HASH" ref $$s{"dev"}{"menus"}{$path} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $$s{"dev"}{"menus"} eq "HASH"B= ref $$s{"dev"}{"menus"}{$path} eq "ARRAY"
ABresult
0X0
100
111
311 536 ▶ return 'settings' if ref $s->{dev}{settings} eq 'HASH' && ref $s->{dev}{settings}{$path} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$s{"dev"}{"settings"} eq "HASH" and ref $$s{"dev"}{"settings"}{$path} eq "HASH" 0 536 536
Condition66%2/3
ref $$s{"dev"}{"settings"} eq "HASH" and ref $$s{"dev"}{"settings"}{$path} eq "HASH"
!ll&&!rl&&r
325040
MC/DC0%0/2
ref $$s{"dev"}{"settings"} eq "HASH" and ref $$s{"dev"}{"settings"}{$path} eq "HASH"
ref $$s{"dev"}{"settings"} eq "HASH" ref $$s{"dev"}{"settings"}{$path} eq "HASH"
Truth table66%2/3
A and B
A= ref $$s{"dev"}{"settings"} eq "HASH"B= ref $$s{"dev"}{"settings"}{$path} eq "HASH"
ABresult
0X0
100
111
312 536 return 'dir';
313 }
314  
315 610 ▶sub _spec {
Subroutine _spec: called CC=2 SCAR=6.9
316 610 my ( $s, $path ) = @_;
317 610 ▶ return $MENU{$path} if $MENU{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $MENU{$path} 346 264 610
318 return {
319 kind => _kind( $s, $path ), path => $path, any => 1, flags => \@FLAGS, props => [], required => [],
320 792 is_prop => { comment => 1, map { $_->[1] => 1 } @FLAGS }, ro => { dynamic => 1, invalid => 1 },
321 264 is_flag => { map { $_->[1] => 1 } @FLAGS }, has_name => 1,
322 };
323 }
324  
325 459 ▶sub _commands {
Subroutine _commands: called CC=11 SCAR=24.0
326 459 my ( $s, $path ) = @_;
327 459 my $kind = _kind( $s, $path );
328 459 my $m = _spec( $s, $path );
329 459 my @c;
330 459 ▶ if ( $kind eq 'list' && $m->{derived} ) { push @c, qw( print find ) }
Branch: 4 branches
BranchTrueFalseTotal
if ($kind eq 'list' and $$m{'derived'}) { } 8 451 459
elsif ($kind eq 'list') { } 173 278 451
elsif ($kind eq 'settings') { } 12 266 278
elsif ($kind eq 'resource') { } 2 264 266
Condition100%3/3
$kind eq "list" and $$m{"derived"}
!ll&&!rl&&r
2781738
MC/DC100%2/2
$kind eq "list" and $$m{"derived"}
$kind eq "list" $$m{"derived"}
Truth table100%3/3
A and B
A= $kind eq "list"B= $$m{"derived"}
ABresult
0X0
100
111
331 elsif ( $kind eq 'list' ) {
332 173 push @c, qw( print export find set disable enable comment );
333 173 ▶ push @c, qw( add remove ) unless $m->{noadd};
Branch: 1 branch
BranchTrueFalseTotal
unless $$m{"noadd"} 167 6 173
334 173 ▶ push @c, 'move' if $m->{move};
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"move"} 136 37 173
335 173 ▶ push @c, 'make-static' if $m->{lease};
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"lease"} 14 159 173
336 173 ▶ push @c, qw( reset-counters reset-counters-all ) if $m->{fw};
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"fw"} 136 37 173
337 }
338 12 elsif ( $kind eq 'settings' ) { push @c, qw( print set export ) }
339 2 elsif ( $kind eq 'resource' ) { push @c, 'print' }
340 264 else { push @c, 'export' }
341 459 ▶ push @c, qw( reboot shutdown ) if $path eq '/system';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/system" 9 450 459
342 459 return ( @c, qw( ping traceroute quit ) );
343 }
344  
345 # Name -> Unterpfad oder Befehl; exakt vor eindeutiger Abkuerzung
346 459 ▶sub _resolve_word {
Subroutine _resolve_word: called CC=4 SCAR=13.9
347 459 my ( $s, $path, $w ) = @_;
348 459 my $ch = _children( $s, $path );
349 459 my @cmd = _commands( $s, $path );
350 459 ▶ return ( child => $ch->{$w} ) if $ch->{$w};
Branch: 1 branch
BranchTrueFalseTotal
if $$ch{$w} 238 221 459
351 221 ▶ return ( cmd => $w ) if grep { $_ eq $w } @cmd;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $w;} @cmd 198 23 221
352 3 my @hit = ( ( map { [ child => $ch->{$_} ] } grep { index( $_, $w ) == 0 } sort keys %$ch ),
353 23 ( map { [ cmd => $_ ] } grep { index( $_, $w ) == 0 } @cmd ) );
354 23 ▶ return @hit == 1 ? @{ $hit[0] } : ();
Branch: 1 branch
BranchTrueFalseTotal
@hit == 1 ? : 5 18 23
355 }
356  
357 1 ▶sub _parent { my ($p) = @_; return $p =~ /\A(.+) [^ ]+\z/ ? $1 : '' }
Subroutine _parent: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$p =~ /\A(.+) [^ ]+\z/ ? : 1 0 1
358  
359 # Pfad am Anfang der Woerter abarbeiten: ( neuer Pfad, Rest )
360 114 ▶sub _navigate {
Subroutine _navigate: called CC=12 SCAR=25.8
361 114 my ( $s, $path, $toks ) = @_;
362 114 my @t = @$toks;
363 114 ▶ if ( @t && !defined $t[0]{br} && !$t[0]{quoted} && $t[0]{text} =~ m{\A/(.*)\z}s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t and not defined $t[0]{"br"} and not $t[0]{"quoted"} and $t[0]{"text"} =~ m[\A/(.*)\z]s) 92 22 114
Condition44%4/9
@t and not defined $t[0]{"br"} and not $t[0]{"quoted"} and $t[0]{"text"} =~ m[\A/(.*)\z]s
!ll&&!rl&&r
02292
@t and not defined $t[0]{"br"} and not $t[0]{"quoted"}
!ll&&!rl&&r
00114
@t and not defined $t[0]{"br"}
!ll&&!rl&&r
00114
MC/DC25%1/4
@t and not defined $t[0]{"br"} and not $t[0]{"quoted"} and $t[0]{"text"} =~ m[\A/(.*)\z]s
@t not defined $t[0]{"br"} not $t[0]{"quoted"} $t[0]{"text"} =~ m[\A/(.*)\z]s
Truth table40%2/5
A and not(B) and not(C) and D
A= @tB= not defined $t[0]{"br"}C= not $t[0]{"quoted"}D= $t[0]{"text"} =~ m[\A/(.*)\z]s
ABCDresult
0XXX0
10XX0
110X0
11100
11111
364 92 my $rest = $1;
365 92 my $col = $t[0]{col} + 1;
366 92 shift @t;
367 92 $path = '';
368 92 unshift @t, map { { text => $_, col => $col } } grep { length } split m{/}, $rest;
369 }
370 114 ▶ while (@t) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 351 5 356
371 351 my $w = $t[0];
372 351 ▶ last if defined $w->{br} || $w->{quoted} || $w->{text} =~ /[=!~]/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"br"} or $$w{"quoted"} or $$w{"text"} =~ /[=!~]/ 0 351 351
Condition33%2/6
defined $$w{"br"} or $$w{"quoted"} or $$w{"text"} =~ /[=!~]/
l!l&&r!l&&!r
00351
defined $$w{"br"} or $$w{"quoted"}
l!l&&r!l&&!r
00351
MC/DC0%0/3
defined $$w{"br"} or $$w{"quoted"} or $$w{"text"} =~ /[=!~]/
defined $$w{"br"} $$w{"quoted"} $$w{"text"} =~ /[=!~]/
Truth table25%1/4
A or B or C
A= defined $$w{"br"}B= $$w{"quoted"}C= $$w{"text"} =~ /[=!~]/
ABCresult
1XX1
01X1
0011
0000
373 351 ▶ if ( $w->{text} eq '..' ) { $path = _parent($path); shift @t; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($$w{"text"} eq "..") 1 350 351
374 350 my ( $what, $to ) = _resolve_word( $s, $path, $w->{text} );
375 350 ▶ last unless $what && $what eq 'child';
Branch: 1 branch
BranchTrueFalseTotal
unless $what and $what eq "child" 109 241 350
Condition100%3/3
$what and $what eq "child"
!ll&&!rl&&r
9100241
MC/DC100%2/2
$what and $what eq "child"
$what $what eq "child"
Truth table100%3/3
A and B
A= $whatB= $what eq "child"
ABresult
0X0
100
111
376 241 $path = $to;
377 241 shift @t;
378 }
379 114 return ( $path, @t );
380 }
381  
382 106 ▶sub _statement {
Subroutine _statement: called CC=8 SCAR=21.9
383 106 my ( $s, $toks, $L ) = @_;
384 106 my ( $path, @t ) = _navigate( $s, $s->{path}, $toks );
385 106 ▶ unless (@t) { $s->{path} = $path; return '' }
Branch: 1 branch
BranchTrueFalseTotal
unless (@t) 5 101 106
386 101 my $ct = shift @t;
387 101 ▶ my ( $what, $cmd ) = defined $ct->{br} || $ct->{quoted} ? () : _resolve_word( $s, $path, $ct->{text} );
Branch: 1 branch
BranchTrueFalseTotal
defined $$ct{'br'} || $$ct{'quoted'} ? : 0 101 101
Condition33%1/3
defined $$ct{"br"} or $$ct{"quoted"}
l!l&&r!l&&!r
00101
MC/DC0%0/2
defined $$ct{"br"} or $$ct{"quoted"}
defined $$ct{"br"} $$ct{"quoted"}
Truth table33%1/3
A or B
A= defined $$ct{"br"}B= $$ct{"quoted"}
ABresult
1X1
011
000
388 101 ▶ unless ( $what && $what eq 'cmd' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($what and $what eq "cmd") 9 92 101
Condition66%2/3
$what and $what eq "cmd"
!ll&&!rl&&r
9092
MC/DC50%1/2
$what and $what eq "cmd"
$what $what eq "cmd"
Truth table66%2/3
A and B
A= $whatB= $what eq "cmd"
ABresult
0X0
100
111
389 9 my $name = $ct->{text};
390 9 ▶ $name = '[' if $name eq '' && defined $ct->{br};
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "" and defined $$ct{"br"} 0 9 9
Condition33%1/3
$name eq "" and defined $$ct{"br"}
!ll&&!rl&&r
900
MC/DC0%0/2
$name eq "" and defined $$ct{"br"}
$name eq "" defined $$ct{"br"}
Truth table33%1/3
A and B
A= $name eq ""B= defined $$ct{"br"}
ABresult
0X0
100
111
391 9 _errat( "bad command name $name", $L, $ct->{col} );
392 }
393 92 return $CMD{$cmd}->( $s, $path, \@t, $L );
394 }
395  
396 # --- Argumente ----------------------------------------------------------------
397  
398 62 ▶sub _key {
Subroutine _key: called CC=8 SCAR=22.8
399 62 my ( $spec, $k, $extra, $mode ) = @_;
400 62 my @c = @$extra;
401 62 ▶ if ($mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) 58 4 62
402 58 ▶ if ( $spec->{any} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$spec{"any"}) 0 58 58
403 0 ▶ return undef if $mode eq 'write' && $spec->{ro}{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "write" and $$spec{"ro"}{$k} 0 0 0
Condition0%0/3
$mode eq "write" and $$spec{"ro"}{$k}
!ll&&!rl&&r
000
MC/DC0%0/2
$mode eq "write" and $$spec{"ro"}{$k}
$mode eq "write" $$spec{"ro"}{$k}
Truth table0%0/3
A and B
A= $mode eq "write"B= $$spec{"ro"}{$k}
ABresult
0X0
100
111
404 0 return $k;
405 }
406 58 ▶ push @c, grep { $mode eq 'read' || !$spec->{ro}{$_} } sort keys %{ $spec->{is_prop} };
Condition100%3/3
$mode eq 'read' || !$$spec{'ro'}{$_}
l!l&&r!l&&!r
8911820103
MC/DC100%2/2
$mode eq 'read' || !$$spec{'ro'}{$_}
$mode eq 'read' !$$spec{'ro'}{$_}
Truth table100%3/3
A || not(B)
A= $mode eq 'read'B= !$$spec{'ro'}{$_}
ABresult
1X1
011
000
407 }
408 62 ▶ return $k if grep { $_ eq $k } @c;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $k;} @c 59 3 62
409 3 my @p = grep { index( $_, $k ) == 0 } @c;
410 3 ▶ return @p == 1 ? $p[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@p == 1 ? : 0 3 3
411 }
412  
413 # o: keys => [..] (weitere k=v), props => 'write'|'read', words => [..], pos => max, unset => 1
414 91 ▶sub _args {
Subroutine _args: called CC=17 SCAR=28.7
415 91 my ( $spec, $toks, $L, %o ) = @_;
416 91 my %r = ( kv => [], unset => [], pos => [], word => {} );
417 91 for my $t (@$toks) {
418 103 my $text = $t->{text};
419 103 ▶ if ( !$t->{quoted} && $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$t{"quoted"} and $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s) 43 60 103
Condition66%2/3
not $$t{"quoted"} and $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s
!ll&&!rl&&r
06043
MC/DC50%1/2
not $$t{"quoted"} and $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s
not $$t{"quoted"} $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s
Truth table66%2/3
not(A) and B
A= not $$t{"quoted"}B= $text =~ /\A([a-z][a-z0-9-]*)=(.*)\z/s
ABresult
0X0
100
111
420 43 ▶ my $k = _key( $spec, $1, $o{keys} || [], $o{props} ) // _errat( 'expected end of command', $L, $t->{col} );
Condition80%4/5
_key($spec, $1, $o{"keys"} || [], $o{"props"}) // _errat("expected end of command", $L, $$t{"col"})
l!l&&r!l&&!r
4030
$o{'keys'} || []
l!l
394
MC/DC0%0/2
_key($spec, $1, $o{"keys"} || [], $o{"props"}) // _errat("expected end of command", $L, $$t{"col"})
_key($spec, $1, $o{"keys"} || [], $o{"props"}) _errat("expected end of command", $L, $$t{"col"})
MC/DC100%1/1
$o{'keys'} || []
$o{'keys'}
Truth table33%1/3
A // B
A= _key($spec, $1, $o{"keys"} || [], $o{"props"})B= _errat("expected end of command", $L, $$t{"col"})
ABresult
1X1
011
000
Truth table100%2/2
A
A= $o{'keys'}
Aresult
11
00
421 40 push @{ $r{kv} }, [ $k, { text => $2, br => $t->{br}, brcol => $t->{brcol}, col => $t->{col} } ];
422 40 next;
423 }
424 60 ▶ if ( $o{unset} && !$t->{quoted} && !defined $t->{br} && $text =~ /\A!([a-z][a-z0-9-]*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"unset"} and not $$t{"quoted"} and not defined $$t{"br"} and $text =~ /\A!([a-z][a-z0-9-]*)\z/) 1 59 60
Condition88%8/9
$o{"unset"} and not $$t{"quoted"} and not defined $$t{"br"} and $text =~ /\A!([a-z][a-z0-9-]*)\z/
!ll&&!rl&&r
5361
$o{"unset"} and not $$t{"quoted"} and not defined $$t{"br"}
!ll&&!rl&&r
5037
$o{"unset"} and not $$t{"quoted"}
!ll&&!rl&&r
50010
MC/DC75%3/4
$o{"unset"} and not $$t{"quoted"} and not defined $$t{"br"} and $text =~ /\A!([a-z][a-z0-9-]*)\z/
$o{"unset"} not $$t{"quoted"} not defined $$t{"br"} $text =~ /\A!([a-z][a-z0-9-]*)\z/
Truth table80%4/5
A and not(B) and not(C) and D
A= $o{"unset"}B= not $$t{"quoted"}C= not defined $$t{"br"}D= $text =~ /\A!([a-z][a-z0-9-]*)\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
425 1 ▶ my $k = _key( $spec, $1, [], 'write' ) // _errat( 'expected end of command', $L, $t->{col} );
Condition33%1/3
_key($spec, $1, scalar [], "write") // _errat("expected end of command", $L, $$t{"col"})
l!l&&r!l&&!r
100
MC/DC0%0/2
_key($spec, $1, scalar [], "write") // _errat("expected end of command", $L, $$t{"col"})
_key($spec, $1, scalar [], "write") _errat("expected end of command", $L, $$t{"col"})
Truth table33%1/3
A // B
A= _key($spec, $1, scalar [], "write")B= _errat("expected end of command", $L, $$t{"col"})
ABresult
1X1
011
000
426 1 push @{ $r{unset} }, $k;
427 1 next;
428 }
429 59 ▶ if ( !$t->{quoted} && !defined $t->{br} && grep { $_ eq $text } @{ $o{words} || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$t{"quoted"} || defined $$t{"br"} and grep {$_ eq $text;} @{$o{"words"} or [];}) 19 40 59
Condition87%7/8
not $$t{"quoted"} || defined $$t{"br"} and grep {$_ eq $text;} @{$o{"words"} or [];}
!ll&&!rl&&r
83219
$$t{'quoted'} || defined $$t{'br'}
l!l&&r!l&&!r
0851
$o{'words'} || []
l!l
2526
MC/DC66%2/3
not $$t{"quoted"} || defined $$t{"br"} and grep {$_ eq $text;} @{$o{"words"} or [];}
$$t{'quoted'} defined $$t{'br'} grep {$_ eq $text;} @{$o{"words"} or [];}
MC/DC100%1/1
$o{'words'} || []
$o{'words'}
Truth table75%3/4
not(A || B) and C
A= $$t{'quoted'}B= defined $$t{'br'}C= grep {$_ eq $text;} @{$o{"words"} or [];}
ABCresult
1XX0
01X0
0000
0011
Truth table100%2/2
A
A= $o{'words'}
Aresult
11
00
430 19 $r{word}{$text} = 1;
431 19 next;
432 }
433 40 ▶ _errat( 'expected end of command', $L, $t->{col} ) if @{ $r{pos} } >= ( $o{pos} // 0 );
Branch: 1 branch
BranchTrueFalseTotal
if @{$r{"pos"};} >= ($o{"pos"} // 0) 0 40 40
Condition50%1/2
$o{"pos"} // 0
l!l
400
MC/DC0%0/1
$o{"pos"} // 0
$o{"pos"}
Truth table50%1/2
A
A= $o{"pos"}
Aresult
11
00
434 40 push @{ $r{pos} }, $t;
435 }
436 88 return \%r;
437 }
438  
439 58 ▶sub _take {
Subroutine _take: called CC=2 SCAR=6.9
440 58 my ( $a, $k ) = @_;
441 58 my ($hit) = grep { $_->[0] eq $k } @{ $a->{kv} };
442 58 $a->{kv} = [ grep { $_->[0] ne $k } @{ $a->{kv} } ];
443 58 ▶ return $hit ? $hit->[1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$hit ? : 4 54 58
444 }
445  
446 39 ▶sub _val {
Subroutine _val: called CC=3 SCAR=14.2
447 39 my ( $v, $L ) = @_;
448 39 ▶ _errat( 'expected end of command', $L, $v->{brcol} // $v->{col} ) if defined $v->{br};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$v{"br"} 0 39 39
Condition0%0/3
$$v{"brcol"} // $$v{"col"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$v{"brcol"} // $$v{"col"}
$$v{"brcol"} $$v{"col"}
Truth table0%0/3
A // B
A= $$v{"brcol"}B= $$v{"col"}
ABresult
1X1
011
000
449 39 return $v->{text};
450 }
451  
452 31 ▶sub _norm {
Subroutine _norm: called CC=9 SCAR=30.1
453 31 my ( $spec, $k, $v ) = @_;
454 31 ▶ if ( $k eq 'action' && $spec->{actions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "action" and $$spec{"actions"}) 10 21 31
Condition66%2/3
$k eq "action" and $$spec{"actions"}
!ll&&!rl&&r
21010
MC/DC50%1/2
$k eq "action" and $$spec{"actions"}
$k eq "action" $$spec{"actions"}
Truth table66%2/3
A and B
A= $k eq "action"B= $$spec{"actions"}
ABresult
0X0
100
111
455 10 ▶ _err('input does not match any value of action') unless grep { $_ eq $v } @{ $spec->{actions} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $v;} @{$$spec{"actions"};} 3 7 10
456 }
457 28 ▶ if ( $spec->{is_flag}{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$spec{"is_flag"}{$k}) 0 28 28
458 0 $v = lc $v;
459 0 ▶ $v = 'yes' if $v eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "true" 0 0 0
460 0 ▶ $v = 'no' if $v eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "false" 0 0 0
461 0 ▶ _err("input does not match any value of $k") unless $v eq 'yes' || $v eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
unless $v eq "yes" or $v eq "no" 0 0 0
Condition0%0/3
$v eq "yes" or $v eq "no"
l!l&&r!l&&!r
000
MC/DC0%0/2
$v eq "yes" or $v eq "no"
$v eq "yes" $v eq "no"
Truth table0%0/3
A or B
A= $v eq "yes"B= $v eq "no"
ABresult
1X1
011
000
462 }
463 28 return $v;
464 }
465  
466 305 ▶sub _yes {
Subroutine _yes: called CC=4 SCAR=14.2
467 305 my ($v) = @_;
468 305 ▶ return 0 unless defined $v && length "$v";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length "$v" 267 38 305
Condition66%2/3
defined $v and length "$v"
!ll&&!rl&&r
267038
MC/DC50%1/2
defined $v and length "$v"
defined $v length "$v"
Truth table66%2/3
A and B
A= defined $vB= length "$v"
ABresult
0X0
100
111
469 38 ▶ return "$v" =~ /\A(?:no|false|0)\z/i ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
"$v" =~ /\A(?:no|false|0)\z/i ? : 0 38 38
470 }
471  
472 # --- Listen -------------------------------------------------------------------
473  
474 163 ▶sub _list {
Subroutine _list: called CC=7 SCAR=19.5
475 163 my ( $s, $path, $create ) = @_;
476 163 my $dev = $s->{dev};
477 163 ▶ return _pool_used($s) if $path eq '/ip pool used';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/ip pool used" 3 160 163
478 160 ▶ if ($create) {
Branch: 1 branch
BranchTrueFalseTotal
if ($create) 6 154 160
479 6 ▶ $dev->{menus} = {} unless ref $dev->{menus} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$dev{"menus"} eq "HASH" 0 6 6
480 6 ▶ return $dev->{menus}{$path} //= [];
Condition100%2/2
$$dev{"menus"}{$path} //= []
l!l
51
MC/DC100%1/1
$$dev{"menus"}{$path} //= []
$$dev{"menus"}{$path}
Truth table100%2/2
A
A= $$dev{"menus"}{$path}
Aresult
11
00
481 }
482 154 ▶ return ref $dev->{menus} eq 'HASH' && ref $dev->{menus}{$path} eq 'ARRAY' ? $dev->{menus}{$path} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'menus'} eq 'HASH' && ref $$dev{'menus'}{$path} eq 'ARRAY' ? : 103 51 154
Condition66%2/3
ref $$dev{"menus"} eq "HASH" and ref $$dev{"menus"}{$path} eq "ARRAY"
!ll&&!rl&&r
051103
MC/DC50%1/2
ref $$dev{"menus"} eq "HASH" and ref $$dev{"menus"}{$path} eq "ARRAY"
ref $$dev{"menus"} eq "HASH" ref $$dev{"menus"}{$path} eq "ARRAY"
Truth table66%2/3
A and B
A= ref $$dev{"menus"} eq "HASH"B= ref $$dev{"menus"}{$path} eq "ARRAY"
ABresult
0X0
100
111
483 }
484  
485 # /ip pool used: je Lease eines DHCP-Servers, deren Adresse im Pool des Servers liegt (nicht abgeschaltet)
486 3 ▶sub _pool_used {
Subroutine _pool_used: called CC=17 SCAR=30.5
487 3 my ($s) = @_;
488 3 ▶ my $n2 = sub { my @o = split /\./, $_[0] // ''; @o == 4 ? ( ( $o[0] * 256 + $o[1] ) * 256 + $o[2] ) * 256 + $o[3] : undef };
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
@o == 4 ? : 13 0 13
Condition50%1/2
$_[0] // ""
l!l
130
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
489 3 my %range;
490 3 for my $p ( @{ _list( $s, '/ip pool' ) } ) {
491 3 ▶ for my $r ( split /,/, $p->{ranges} // '' ) {
Condition50%1/2
$$p{"ranges"} // ""
l!l
30
MC/DC0%0/1
$$p{"ranges"} // ""
$$p{"ranges"}
Truth table50%1/2
A
A= $$p{"ranges"}
Aresult
11
00
492 3 my ( $a, $b ) = split /-/, $r;
493 3 ▶ push @{ $range{ $p->{name} // '' } }, [ $n2->($a), $n2->( $b // $a ) ];
Condition40%2/5
$$p{"name"} // ""
l!l
30
$b // $a
l!l&&r!l&&!r
300
MC/DC0%0/1
$$p{"name"} // ""
$$p{"name"}
MC/DC0%0/2
$b // $a
$b $a
Truth table50%1/2
A
A= $$p{"name"}
Aresult
11
00
Truth table33%1/3
A // B
A= $bB= $a
ABresult
1X1
011
000
494 }
495 }
496 3 ▶ my %pool = map { ( $_->{name} // '' ) => $_->{'address-pool'} } @{ _list( $s, '/ip dhcp-server' ) };
Condition50%1/2
$$_{"name"} // ""
l!l
30
MC/DC0%0/1
$$_{"name"} // ""
$$_{"name"}
Truth table50%1/2
A
A= $$_{"name"}
Aresult
11
00
497 3 my @u;
498 3 for my $l ( @{ _list( $s, '/ip dhcp-server lease' ) } ) {
499 9 ▶ next if _yes( $l->{disabled} );
Branch: 1 branch
BranchTrueFalseTotal
if _yes($$l{"disabled"}) 2 7 9
500 7 ▶ my $pn = $pool{ $l->{server} // '' } // next;
Condition50%2/4
$pool{$$l{"server"} // ""} // (next)
l!l
70
$$l{"server"} // ""
l!l
70
MC/DC0%0/1
$pool{$$l{"server"} // ""} // (next)
$pool{$$l{"server"} // ""}
MC/DC0%0/1
$$l{"server"} // ""
$$l{"server"}
Truth table50%1/2
A
A= $pool{$$l{"server"} // ""}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"server"}
Aresult
11
00
501 7 ▶ my $a = $n2->( $l->{address} ) // next;
Condition50%1/2
&$n2($$l{"address"}) // (next)
l!l
70
MC/DC0%0/1
&$n2($$l{"address"}) // (next)
&$n2($$l{"address"})
Truth table50%1/2
A
A= &$n2($$l{"address"})
Aresult
11
00
502 7 ▶ next unless grep { defined $_->[0] && $a >= $_->[0] && $a <= $_->[1] } @{ $range{$pn} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $$_[0] and $a >= $$_[0] and $a <= $$_[1];} @{$range{$pn} or [];} 3 4 7
Condition62%5/8
defined $$_[0] && $a >= $$_[0] && $a <= $$_[1]
!ll&&!rl&&r
304
defined $$_[0] and $a >= $$_[0]
!ll&&!rl&&r
034
$range{$pn} || []
l!l
70
MC/DC33%1/3
defined $$_[0] && $a >= $$_[0] && $a <= $$_[1]
defined $$_[0] $a >= $$_[0] $a <= $$_[1]
MC/DC0%0/1
$range{$pn} || []
$range{$pn}
Truth table50%2/4
A and B && C
A= defined $$_[0]B= $a >= $$_[0]C= $a <= $$_[1]
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $range{$pn}
Aresult
11
00
503 4 ▶ push @u, { pool => $pn, address => $l->{address}, owner => $l->{server}, info => $l->{'mac-address'} // '' };
Condition50%1/2
$$l{"mac-address"} // ""
l!l
40
MC/DC0%0/1
$$l{"mac-address"} // ""
$$l{"mac-address"}
Truth table50%1/2
A
A= $$l{"mac-address"}
Aresult
11
00
504 }
505 3 return \@u;
506 }
507  
508 17 ▶sub _index_of {
Subroutine _index_of: called CC=3 SCAR=11.1
509 17 my ( $list, $ref ) = @_;
510 17 ▶ for ( 0 .. $#$list ) { return $_ if $list->[$_] == $ref }
Branch: 1 branch
BranchTrueFalseTotal
if $$list[$_] == $ref 17 16 33
511 0 return undef;
512 }
513  
514 # Nummern, Namen oder [find ...] -> Eintraege (Referenzen in die Liste)
515 36 ▶sub _refs {
Subroutine _refs: called CC=11 SCAR=30.2
516 36 my ( $s, $spec, $path, $list, $v, $L ) = @_;
517 36 my @r;
518 36 ▶ if ( defined $v->{br} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$v{'br'}) { } 8 28 36
519 8 @r = _bracket( $s, $path, $v, $L );
520 8 ▶ defined _index_of( $list, $_ ) or _err('no such item') for @r;
Branch: 1 branch
BranchTrueFalseTotal
defined _index_of($list, $_) or _err("no such item") 12 0 12
521 }
522 else {
523 28 ▶ _err('no such item') unless length $v->{text};
Branch: 1 branch
BranchTrueFalseTotal
unless length $$v{"text"} 0 28 28
524 28 for my $p ( split /,/, $v->{text} ) {
525 31 ▶ if ( $p =~ /\A\d+\z/ ) { push @r, $list->[$p] // _err('no such item'); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\A\d+\z/) 31 0 31
Condition66%2/3
$$list[$p] // _err("no such item")
l!l&&r!l&&!r
2830
MC/DC0%0/2
$$list[$p] // _err("no such item")
$$list[$p] _err("no such item")
Truth table33%1/3
A // B
A= $$list[$p]B= _err("no such item")
ABresult
1X1
011
000
526 0 ▶ my ($it) = $spec->{has_name} ? grep { defined $_->{name} && $_->{name} eq $p } @$list : ();
Branch: 1 branch
BranchTrueFalseTotal
$$spec{'has_name'} ? : 0 0 0
Condition0%0/3
defined $$_{'name'} && $$_{'name'} eq $p
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$_{'name'} && $$_{'name'} eq $p
defined $$_{'name'} $$_{'name'} eq $p
Truth table0%0/3
A && B
A= defined $$_{'name'}B= $$_{'name'} eq $p
ABresult
0X0
100
111
527 0 ▶ push @r, $it // _err('no such item');
Condition0%0/3
$it // _err("no such item")
l!l&&r!l&&!r
000
MC/DC0%0/2
$it // _err("no such item")
$it _err("no such item")
Truth table0%0/3
A // B
A= $itB= _err("no such item")
ABresult
1X1
011
000
528 }
529 }
530 33 my %seen;
531 33 return grep { !$seen{$_}++ } @r;
532 }
533  
534 8 ▶sub _bracket {
Subroutine _bracket: called CC=13 SCAR=29.1
535 8 my ( $s, $path, $v, $L ) = @_;
536 8 ▶ my @t = _tokenize( $v->{br}, $L, ( $v->{brcol} // 1 ) - 1 );
Condition50%1/2
$$v{"brcol"} // 1
l!l
80
MC/DC0%0/1
$$v{"brcol"} // 1
$$v{"brcol"}
Truth table50%1/2
A
A= $$v{"brcol"}
Aresult
11
00
537 8 _errat( 'syntax error', $L, $_->{col} ) for grep { $_->{semi} } @t;
538 8 ( $path, @t ) = _navigate( $s, $path, \@t );
539 8 ▶ my $ct = shift @t or _errat( 'expected command name', $L, $v->{brcol} // 1 );
Branch: 1 branch
BranchTrueFalseTotal
my $ct = shift @t or _errat("expected command name", $L, $$v{"brcol"} // 1) 8 0 8
Condition0%0/2
$$v{"brcol"} // 1
l!l
00
MC/DC0%0/1
$$v{"brcol"} // 1
$$v{"brcol"}
Truth table0%0/2
A
A= $$v{"brcol"}
Aresult
11
00
540 8 ▶ my ( $what, $cmd ) = defined $ct->{br} || $ct->{quoted} ? () : _resolve_word( $s, $path, $ct->{text} );
Branch: 1 branch
BranchTrueFalseTotal
defined $$ct{'br'} || $$ct{'quoted'} ? : 0 8 8
Condition33%1/3
defined $$ct{"br"} or $$ct{"quoted"}
l!l&&r!l&&!r
008
MC/DC0%0/2
defined $$ct{"br"} or $$ct{"quoted"}
defined $$ct{"br"} $$ct{"quoted"}
Truth table33%1/3
A or B
A= defined $$ct{"br"}B= $$ct{"quoted"}
ABresult
1X1
011
000
541 8 ▶ _errat( "bad command name $ct->{text}", $L, $ct->{col} ) unless $what && $what eq 'cmd' && $cmd eq 'find';
Branch: 1 branch
BranchTrueFalseTotal
unless $what and $what eq "cmd" and $cmd eq "find" 0 8 8
Condition33%2/6
$what and $what eq "cmd" and $cmd eq "find"
!ll&&!rl&&r
008
$what and $what eq "cmd"
!ll&&!rl&&r
008
MC/DC0%0/3
$what and $what eq "cmd" and $cmd eq "find"
$what $what eq "cmd" $cmd eq "find"
Truth table25%1/4
A and B and C
A= $whatB= $what eq "cmd"C= $cmd eq "find"
ABCresult
0XX0
10X0
1100
1111
542 8 ▶ shift @t if @t && !$t[0]{quoted} && $t[0]{text} eq 'where';
Branch: 1 branch
BranchTrueFalseTotal
if @t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where" 1 7 8
Condition83%5/6
@t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where"
!ll&&!rl&&r
161
@t and not $t[0]{"quoted"}
!ll&&!rl&&r
107
MC/DC66%2/3
@t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where"
@t not $t[0]{"quoted"} $t[0]{"text"} eq "where"
Truth table75%3/4
A and not(B) and C
A= @tB= not $t[0]{"quoted"}C= $t[0]{"text"} eq "where"
ABCresult
0XX0
10X0
1100
1111
543 8 my $spec = _spec( $s, $path );
544 8 my $cond = _cond( $spec, \@t, $L );
545 8 return grep { $cond->($_) } @{ _list( $s, $path ) };
546 }
547  
548 # where-Ausdruck: Begriffe, und vor oder, not/! verneint
549 16 ▶sub _cond {
Subroutine _cond: called CC=23 SCAR=34.9
550 16 my ( $spec, $toks, $L ) = @_;
551 16 my @or = ( [] );
552 16 my $neg = 0;
553 16 for my $t (@$toks) {
554 21 my $x = $t->{text};
555 21 ▶ _errat( 'expected end of command', $L, $t->{col} ) if defined $t->{br};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$t{"br"} 0 21 21
556 21 ▶ if ( !$t->{quoted} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$t{"quoted"}) 21 0 21
557 21 ▶ next if $x eq 'and' || $x eq '&&';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "and" or $x eq "&&" 2 19 21
Condition66%2/3
$x eq "and" or $x eq "&&"
l!l&&r!l&&!r
2019
MC/DC50%1/2
$x eq "and" or $x eq "&&"
$x eq "and" $x eq "&&"
Truth table66%2/3
A or B
A= $x eq "and"B= $x eq "&&"
ABresult
1X1
011
000
558 19 ▶ if ( $x eq 'or' || $x eq '||' ) { push @or, []; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "or" or $x eq "||") 1 18 19
Condition66%2/3
$x eq "or" or $x eq "||"
l!l&&r!l&&!r
1018
MC/DC50%1/2
$x eq "or" or $x eq "||"
$x eq "or" $x eq "||"
Truth table66%2/3
A or B
A= $x eq "or"B= $x eq "||"
ABresult
1X1
011
000
559 0 ▶ if ( $x eq 'not' || $x eq '!' ) { $neg = !$neg; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "not" or $x eq "!") 0 18 18
Condition33%1/3
$x eq "not" or $x eq "!"
l!l&&r!l&&!r
0018
MC/DC0%0/2
$x eq "not" or $x eq "!"
$x eq "not" $x eq "!"
Truth table33%1/3
A or B
A= $x eq "not"B= $x eq "!"
ABresult
1X1
011
000
560 }
561 my ( $bang, $k, $op, $v ) = $x =~ /\A(!?)([a-z][a-z0-9-]*)(?:(!=|=|~|<|>)(.*))?\z/s
562 18 ▶ or _errat( 'expected end of command', $L, $t->{col} );
Branch: 1 branch
BranchTrueFalseTotal
() = $x =~ /\A(!?)([a-z][a-z0-9-]*)(?:(!=|=|~|<|>)(.*))?\z/s or _errat("expected end of command", $L, $$t{"col"}) 18 0 18
563 18 ▶ $k = _key( $spec, $k, [], 'read' ) // _errat( 'expected end of command', $L, $t->{col} );
Condition33%1/3
_key($spec, $k, scalar [], "read") // _errat("expected end of command", $L, $$t{"col"})
l!l&&r!l&&!r
1800
MC/DC0%0/2
_key($spec, $k, scalar [], "read") // _errat("expected end of command", $L, $$t{"col"})
_key($spec, $k, scalar [], "read") _errat("expected end of command", $L, $$t{"col"})
Truth table33%1/3
A // B
A= _key($spec, $k, scalar [], "read")B= _errat("expected end of command", $L, $$t{"col"})
ABresult
1X1
011
000
564 18 ▶ my $flip = ( $bang ? 1 : 0 ) ^ ( $neg ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
$bang ? : 1 17 18
$neg ? : 0 18 18
565 18 $neg = 0;
566 18 my $flag = $spec->{is_flag}{$k};
567 18 ▶ if ( $flag && defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag and defined $v) 1 17 18
Condition100%3/3
$flag and defined $v
!ll&&!rl&&r
1431
MC/DC100%2/2
$flag and defined $v
$flag defined $v
Truth table100%3/3
A and B
A= $flagB= defined $v
ABresult
0X0
100
111
568 1 $v = lc $v;
569 1 ▶ $v = 'yes' if $v eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "true" 0 1 1
570 1 ▶ $v = 'no' if $v eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "false" 0 1 1
571 }
572 18 ▶ my $re = defined $op && $op eq '~' ? eval {qr/$v/} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $op && $op eq '~' ? : 2 16 18
Condition100%3/3
defined $op and $op eq "~"
!ll&&!rl&&r
3132
MC/DC100%2/2
defined $op and $op eq "~"
defined $op $op eq "~"
Truth table100%3/3
A and B
A= defined $opB= $op eq "~"
ABresult
0X0
100
111
573 18 ▶ push @{ $or[-1] }, sub {
Subroutine __ANON__: called CC=19 SCAR=37.6
574 51 my ($it) = @_;
575 51 ▶ my $iv = $flag ? ( _yes( $it->{$k} ) ? 'yes' : 'no' ) : $it->{$k};
Branch: 2 branches
BranchTrueFalseTotal
$flag ? : 13 38 51
_yes($$it{$k}) ? : 7 6 13
576 51 my $m;
577 51 ▶ if ( !defined $op ) { $m = $flag ? _yes( $it->{$k} ) : defined $iv && length $iv }
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $op) { } 10 41 51
elsif ($op eq '=') { } 32 9 41
elsif ($op eq '!=') { } 3 6 9
elsif ($op eq '~') { } 6 0 6
$flag ? : 10 0 10
Condition0%0/3
defined $iv and length $iv
!ll&&!rl&&r
000
MC/DC0%0/2
defined $iv and length $iv
defined $iv length $iv
Truth table0%0/3
A and B
A= defined $ivB= length $iv
ABresult
0X0
100
111
578 32 ▶ elsif ( $op eq '=' ) { $m = ( $iv // '' ) eq $v }
Condition100%2/2
$iv // ""
l!l
293
MC/DC100%1/1
$iv // ""
$iv
Truth table100%2/2
A
A= $iv
Aresult
11
00
579 3 ▶ elsif ( $op eq '!=' ) { $m = ( $iv // '' ) ne $v }
Condition50%1/2
$iv // ""
l!l
30
MC/DC0%0/1
$iv // ""
$iv
Truth table50%1/2
A
A= $iv
Aresult
11
00
580 6 ▶ elsif ( $op eq '~' ) { $m = $re && ( $iv // '' ) =~ $re }
Condition80%4/5
$re && ($iv // '') =~ /$re/
!ll&&!rl&&r
042
$iv // ""
l!l
33
MC/DC50%1/2
$re && ($iv // '') =~ /$re/
$re $iv
Truth table66%2/3
A && B
A= $reB= $iv
ABresult
0X0
100
111
581 else {
582 0 ▶ my ( $a, $b ) = ( $iv // '', $v );
Condition0%0/2
$iv // ""
l!l
00
MC/DC0%0/1
$iv // ""
$iv
Truth table0%0/2
A
A= $iv
Aresult
11
00
583 0 ▶ my $num = $a =~ /\A-?\d+\z/ && $b =~ /\A-?\d+\z/;
Condition0%0/3
$a =~ /\A-?\d+\z/ && $b =~ /\A-?\d+\z/
!ll&&!rl&&r
000
MC/DC0%0/2
$a =~ /\A-?\d+\z/ && $b =~ /\A-?\d+\z/
$a =~ /\A-?\d+\z/ $b =~ /\A-?\d+\z/
Truth table0%0/3
A && B
A= $a =~ /\A-?\d+\z/B= $b =~ /\A-?\d+\z/
ABresult
0X0
100
111
584 0 ▶ $m = $op eq '<' ? ( $num ? $a < $b : $a lt $b ) : ( $num ? $a > $b : $a gt $b );
Branch: 3 branches
BranchTrueFalseTotal
$op eq '<' ? : 0 0 0
$num ? : 0 0 0
$num ? : 0 0 0
585 }
586 51 ▶ return $flip ? !$m : $m;
Branch: 1 branch
BranchTrueFalseTotal
$flip ? : 3 48 51
587 18 };
588 }
589 16 ▶ return sub {1} if @or == 1 && !@{ $or[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if @or == 1 and not @{$or[0];} 1 15 16
Condition100%3/3
@or == 1 and not @{$or[0];}
!ll&&!rl&&r
1141
MC/DC100%2/2
@or == 1 and not @{$or[0];}
@or == 1 not @{$or[0];}
Truth table100%3/3
A and not(B)
A= @or == 1B= not @{$or[0];}
ABresult
0X0
100
111
590 15 ▶ _errat( 'expected end of command', $L, $toks->[-1]{col} ) if grep { !@$_ } @or;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not @$_;} @or 0 15 15
591 43 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
592 43 my ($it) = @_;
593 43 ▶ for my $and (@or) { return 1 unless grep { !$_->($it) } @$and }
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not &$_($it);} @$and 18 27 45
594 25 return 0;
595 15 };
596 }
597  
598 # --- Ausgabe ------------------------------------------------------------------
599  
600 168 ▶sub _q {
Subroutine _q: called CC=2 SCAR=6.9
601 168 my ($v) = @_;
602 168 $v = "$v";
603 168 ▶ return $v if $v =~ /\A[^\s"\\;\$\[\]{}=]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A[^\s"\\;\$\[\]{}=]+\z/ 163 5 168
604 5 $v =~ s/(["\\\$])/\\$1/g;
605 5 $v =~ s/\n/\\n/g;
606 5 $v =~ s/\t/\\t/g;
607 5 return qq{"$v"};
608 }
609  
610 29 ▶sub _pairs {
Subroutine _pairs: called CC=3 SCAR=11.0
611 29 my ( $spec, $it ) = @_;
612 29 my %in = map { $_ => 1 } @{ $spec->{props} };
613 29 my @k = ( ( grep { exists $it->{$_} } @{ $spec->{props} } ), ( sort grep { !$in{$_} } keys %$it ) );
614 29 ▶ return map { "$_=" . _q( $it->{$_} // '' ) } grep { $_ ne 'comment' && !$spec->{is_flag}{$_} } @k;
Condition80%4/5
$$it{$_} // ""
l!l
800
$_ ne 'comment' && !$$spec{'is_flag'}{$_}
!ll&&!rl&&r
101180
MC/DC0%0/1
$$it{$_} // ""
$$it{$_}
MC/DC100%2/2
$_ ne 'comment' && !$$spec{'is_flag'}{$_}
$_ ne 'comment' !$$spec{'is_flag'}{$_}
Truth table50%1/2
A
A= $$it{$_}
Aresult
11
00
Truth table100%3/3
A && not(B)
A= $_ ne 'comment'B= !$$spec{'is_flag'}{$_}
ABresult
0X0
100
111
615 }
616  
617 29 ▶sub _flags {
Subroutine _flags: called CC=1 SCAR=0.0
618 29 my ( $spec, $it ) = @_;
619 29 return join '', map { $_->[0] } grep { _yes( $it->{ $_->[1] } ) } @{ $spec->{flags} };
620 }
621  
622 34 ▶sub _rtrim { my ($x) = @_; $x =~ s/[ \t]+$//mg; return $x }
Subroutine _rtrim: called CC=1 SCAR=0.0
623  
624 26 ▶sub _entry {
Subroutine _entry: called CC=4 SCAR=14.0
625 26 my ( $spec, $n, $it ) = @_;
626 26 my $pre = sprintf '%2d %-3s', $n, _flags( $spec, $it );
627 26 my $kv = join ' ', _pairs( $spec, $it );
628 26 ▶ return _rtrim( $pre . $kv ) unless defined $it->{comment} && length $it->{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$it{"comment"} and length $$it{"comment"} 17 9 26
Condition66%2/3
defined $$it{"comment"} and length $$it{"comment"}
!ll&&!rl&&r
1709
MC/DC50%1/2
defined $$it{"comment"} and length $$it{"comment"}
defined $$it{"comment"} length $$it{"comment"}
Truth table66%2/3
A and B
A= defined $$it{"comment"}B= length $$it{"comment"}
ABresult
0X0
100
111
629 9 ▶ return _rtrim( "$pre;;; $it->{comment}" . ( length $kv ? "\n $kv" : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
length $kv ? : 9 0 9
630 }
631  
632 8 ▶sub _settings_get {
Subroutine _settings_get: called CC=6 SCAR=19.9
633 8 my ( $s, $spec ) = @_;
634 8 ▶ return { name => $s->{dev}{identity} // $s->{ctx}{host} // 'MikroTik' } if $spec->{identity};
Branch: 1 branch
BranchTrueFalseTotal
if $$spec{"identity"} 3 5 8
Condition40%2/5
($$s{"dev"}{"identity"} // $$s{"ctx"}{"host"}) // "MikroTik"
l!l
30
$$s{"dev"}{"identity"} // $$s{"ctx"}{"host"}
l!l&&r!l&&!r
300
MC/DC0%0/2
($$s{"dev"}{"identity"} // $$s{"ctx"}{"host"}) // "MikroTik"
$$s{"dev"}{"identity"} $$s{"ctx"}{"host"}
Truth table33%1/3
A // B
A= $$s{"dev"}{"identity"}B= $$s{"ctx"}{"host"}
ABresult
1X1
011
000
635 5 ▶ my $h = ref $s->{dev}{settings} eq 'HASH' ? $s->{dev}{settings}{ $spec->{path} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$s{'dev'}{'settings'} eq 'HASH' ? : 5 0 5
636 5 ▶ return ref $h eq 'HASH' ? $h : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $h eq 'HASH' ? : 5 0 5
637 }
638  
639 1 ▶sub _resource {
Subroutine _resource: called CC=2 SCAR=6.9
640 1 my ($s) = @_;
641 1 my @r = (
642 uptime => '3d04:12:31', version => "$VERSION_ROS (stable)", 'build-time' => '2024-11-26 13:15:01',
643 'factory-software' => '7.1', 'free-memory' => '811.5MiB', 'total-memory' => '1024.0MiB',
644 cpu => 'ARMv7', 'cpu-count' => 4, 'cpu-load' => '2%', 'free-hdd-space' => '3.4MiB',
645 'total-hdd-space' => '16.0MiB', 'architecture-name' => 'arm', 'board-name' => 'hEX',
646 platform => 'MikroTik',
647 );
648 1 my @l;
649 1 ▶ while ( my ( $k, $v ) = splice @r, 0, 2 ) { push @l, sprintf '%19s: %s', $k, $v }
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@r, 0, 2)) 14 1 15
650 1 return join "\n", @l;
651 }
652  
653 # --- Befehle ------------------------------------------------------------------
654  
655 32 ▶sub _c_print {
Subroutine _c_print: called CC=15 SCAR=27.1
656 32 my ( $s, $path, $toks, $L ) = @_;
657 32 my $kind = _kind( $s, $path );
658 32 my $spec = _spec( $s, $path );
659 32 ▶ if ( $kind eq 'resource' ) { _args( $spec, $toks, $L, words => ['without-paging'] ); return _resource($s) }
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "resource") 1 31 32
660 31 ▶ if ( $kind eq 'settings' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "settings") 3 28 31
661 3 _args( $spec, $toks, $L, words => ['without-paging'] );
662 3 my $h = _settings_get( $s, $spec );
663 3 my %in = map { $_ => 1 } @{ $spec->{props} };
664 3 my @k = ( ( grep { exists $h->{$_} } @{ $spec->{props} } ), sort grep { !$in{$_} } keys %$h );
665 3 my ($w) = sort { $b <=> $a } map {length} @k;
666 3 ▶ return join "\n", map { sprintf '%*s: %s', ( $w // 0 ) + 2, $_, $h->{$_} // '' } @k;
Condition50%2/4
$w // 0
l!l
60
$$h{$_} // ""
l!l
60
MC/DC0%0/1
$w // 0
$w
MC/DC0%0/1
$$h{$_} // ""
$$h{$_}
Truth table50%1/2
A
A= $w
Aresult
11
00
Truth table50%1/2
A
A= $$h{$_}
Aresult
11
00
667 }
668 28 my @t = @$toks;
669 28 ▶ my ($wi) = grep { !$t[$_]{quoted} && !defined $t[$_]{br} && $t[$_]{text} eq 'where' } 0 .. $#t;
Condition50%3/6
!($t[$_]{'quoted'} || defined $t[$_]{'br'}) && $t[$_]{'text'} eq 'where'
!ll&&!rl&&r
0287
$t[$_]{'quoted'} || defined $t[$_]{'br'}
l!l&&r!l&&!r
0035
MC/DC33%1/3
!($t[$_]{'quoted'} || defined $t[$_]{'br'}) && $t[$_]{'text'} eq 'where'
$t[$_]{'quoted'} defined $t[$_]{'br'} $t[$_]{'text'} eq 'where'
Truth table50%2/4
not(A || B) && C
A= $t[$_]{'quoted'}B= defined $t[$_]{'br'}C= $t[$_]{'text'} eq 'where'
ABCresult
1XX0
01X0
0000
0011
670 28 my @w;
671 28 ▶ if ( defined $wi ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wi) 7 21 28
672 7 @w = @t[ $wi + 1 .. $#t ];
673 7 ▶ _errat( 'expected end of command', $L, $t[$wi]{col} + 5 ) unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 0 7 7
674 7 @t = @t[ 0 .. $wi - 1 ];
675 }
676 28 my $a = _args( $spec, \@t, $L, words => [qw( detail terse brief without-paging count-only )] );
677 28 ▶ my $cond = defined $wi ? _cond( $spec, \@w, $L ) : sub {1};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $wi ? : 7 21 28
678 28 my $list = _list( $s, $path );
679 28 my @idx = grep { $cond->( $list->[$_] ) } 0 .. $#$list;
680 28 ▶ return scalar @idx if $a->{word}{'count-only'};
Branch: 1 branch
BranchTrueFalseTotal
if $$a{"word"}{"count-only"} 15 13 28
681 13 ▶ if ( $a->{word}{terse} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$a{"word"}{"terse"}) 1 12 13
682 return join "\n", map {
683 1 my $it = $list->[$_];
684 3 ▶ my @c = defined $it->{comment} ? ( 'comment=' . _q( $it->{comment} ) ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $$it{'comment'} ? : 1 2 3
685 3 _rtrim( sprintf '%2d %-2s %s', $_, _flags( $spec, $it ), join ' ', @c, _pairs( $spec, $it ) );
686 } @idx;
687 }
688 12 ▶ my @head = @{ $spec->{flags} } ? ( 'Flags: ' . join ', ', map {"$_->[0] - $_->[1]"} @{ $spec->{flags} } ) : ();
Branch: 1 branch
BranchTrueFalseTotal
@{$$spec{'flags'};} ? : 11 1 12
689 12 ▶ return join "\n", @head unless @idx;
Branch: 1 branch
BranchTrueFalseTotal
unless @idx 2 10 12
690 10 return join "\n", @head, join( "\n\n", map { _entry( $spec, $_, $list->[$_] ) } @idx );
691 }
692  
693 64 ▶sub _export_block {
Subroutine _export_block: called CC=10 SCAR=23.8
694 64 my ( $s, $path, $terse ) = @_;
695 64 my $spec = _spec( $s, $path );
696 64 my $kind = _kind( $s, $path );
697 64 ▶ my $pre = $terse ? "$path " : '';
Branch: 1 branch
BranchTrueFalseTotal
$terse ? : 15 49 64
698 64 my @l;
699 29 ▶ my $kv = sub {
Subroutine __ANON__: called CC=4 SCAR=15.9
700 29 my ($h) = @_;
701 87 return map { "$_=" . _q( $h->{$_} ) }
702 29 ▶ grep { defined $h->{$_} && !$spec->{ro}{$_} && !( $spec->{is_flag}{$_} && !_yes( $h->{$_} ) ) }
Condition44%4/9
defined $$h{$_} && !$$spec{'ro'}{$_} && !($$spec{'is_flag'}{$_} && !_yes($$h{$_}))
!ll&&!rl&&r
0087
defined $$h{$_} and not $$spec{"ro"}{$_}
!ll&&!rl&&r
0087
$$spec{'is_flag'}{$_} && !_yes($$h{$_})
!ll&&!rl&&r
8340
MC/DC0%0/4
defined $$h{$_} && !$$spec{'ro'}{$_} && !($$spec{'is_flag'}{$_} && !_yes($$h{$_}))
defined $$h{$_} not $$spec{"ro"}{$_} $$spec{'is_flag'}{$_} !_yes($$h{$_})
Truth table40%2/5
A and not(B) && not(C && not(D))
A= defined $$h{$_}B= not $$spec{"ro"}{$_}C= $$spec{'is_flag'}{$_}D= !_yes($$h{$_})
ABCDresult
0XXX0
10XX0
11110
110X1
11101
703 sort keys %$h;
704 64 };
705 64 ▶ if ( $kind eq 'settings' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'settings') { } 5 59 64
elsif ($kind eq 'list') { } 59 0 59
706 5 ▶ return () if $spec->{identity} && !defined $s->{dev}{identity};
Branch: 1 branch
BranchTrueFalseTotal
if $$spec{"identity"} and not defined $$s{"dev"}{"identity"} 0 5 5
Condition66%2/3
$$spec{"identity"} and not defined $$s{"dev"}{"identity"}
!ll&&!rl&&r
320
MC/DC0%0/2
$$spec{"identity"} and not defined $$s{"dev"}{"identity"}
$$spec{"identity"} not defined $$s{"dev"}{"identity"}
Truth table66%2/3
A and not(B)
A= $$spec{"identity"}B= not defined $$s{"dev"}{"identity"}
ABresult
0X0
100
111
707 5 my @p = $kv->( _settings_get( $s, $spec ) );
708 5 ▶ push @l, $pre . join ' ', 'set', @p if @p;
Branch: 1 branch
BranchTrueFalseTotal
if @p 5 0 5
709 }
710 elsif ( $kind eq 'list' ) {
711 59 push @l, $pre . join ' ', 'add', $kv->($_) for grep { !_yes( $_->{dynamic} ) } @{ _list( $s, $path ) };
712 }
713 64 ▶ return () unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 46 18 64
714 18 ▶ return $terse ? @l : ( $path, @l );
Branch: 1 branch
BranchTrueFalseTotal
$terse ? : 5 13 18
715 }
716  
717 4 ▶sub _c_export {
Subroutine _c_export: called CC=9 SCAR=22.0
718 4 my ( $s, $path, $toks, $L ) = @_;
719 4 my $a = _args( {}, $toks, $L, words => [qw( compact verbose terse hide-sensitive show-sensitive )],
720 keys => ['file'] );
721 4 ▶ return '' if _take( $a, 'file' );
Branch: 1 branch
BranchTrueFalseTotal
if _take($a, "file") 0 4 4
722 4 my %known = map { $_ => 1 } @EXPORT_ORDER;
723 4 ▶ my @extra = sort grep { !$known{$_} && !$MENU{$_} && _kind( $s, $_ ) ne 'dir' } _paths($s);
Condition83%5/6
!($known{$_} || $MENU{$_}) && _kind($s, $_) ne 'dir'
!ll&&!rl&&r
11280
$known{$_} || $MENU{$_}
l!l&&r!l&&!r
96168
MC/DC0%0/3
!($known{$_} || $MENU{$_}) && _kind($s, $_) ne 'dir'
$known{$_} $MENU{$_} _kind($s, $_) ne 'dir'
Truth table75%3/4
not(A || B) && C
A= $known{$_}B= $MENU{$_}C= _kind($s, $_) ne 'dir'
ABCresult
1XX0
01X0
0000
0011
724 4 ▶ my $pre = $path eq '' ? '/' : "$path ";
Branch: 1 branch
BranchTrueFalseTotal
$path eq '' ? : 2 2 4
725 4 my @l = ("# by RouterOS $VERSION_ROS");
726 4 for my $p ( @EXPORT_ORDER, @extra ) {
727 96 ▶ next unless $path eq '' || $p eq $path || index( $p, $pre ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $path eq "" or $p eq $path or index($p, $pre) == 0 32 64 96
Condition100%6/6
$path eq "" or $p eq $path or index($p, $pre) == 0
l!l&&r!l&&!r
491532
$path eq "" or $p eq $path
l!l&&r!l&&!r
48147
MC/DC100%3/3
$path eq "" or $p eq $path or index($p, $pre) == 0
$path eq "" $p eq $path index($p, $pre) == 0
Truth table100%4/4
A or B or C
A= $path eq ""B= $p eq $pathC= index($p, $pre) == 0
ABCresult
1XX1
01X1
0011
0000
728 64 push @l, _export_block( $s, $p, $a->{word}{terse} );
729 }
730 4 return join "\n", @l;
731 }
732  
733 15 ▶sub _fixup {
Subroutine _fixup: called CC=7 SCAR=20.4
734 15 my ( $spec, $it, $changed ) = @_;
735 15 ▶ return unless $spec->{path} eq '/ip address' && $changed->{address} && defined $it->{address};
Branch: 1 branch
BranchTrueFalseTotal
unless $$spec{"path"} eq "/ip address" and $$changed{"address"} and defined $$it{"address"} 14 1 15
Condition66%4/6
$$spec{"path"} eq "/ip address" and $$changed{"address"} and defined $$it{"address"}
!ll&&!rl&&r
1401
$$spec{"path"} eq "/ip address" and $$changed{"address"}
!ll&&!rl&&r
1401
MC/DC33%1/3
$$spec{"path"} eq "/ip address" and $$changed{"address"} and defined $$it{"address"}
$$spec{"path"} eq "/ip address" $$changed{"address"} defined $$it{"address"}
Truth table50%2/4
A and B and C
A= $$spec{"path"} eq "/ip address"B= $$changed{"address"}C= defined $$it{"address"}
ABCresult
0XX0
10X0
1100
1111
736 1 ▶ $it->{address} .= '/32' unless $it->{address} =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
unless $$it{"address"} =~ m[/] 0 1 1
737 1 ▶ return if $changed->{network};
Branch: 1 branch
BranchTrueFalseTotal
if $$changed{"network"} 0 1 1
738 1 ▶ my ( $n, $m ) = _net( $it->{address} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = _net($$it{"address"}) or return 1 0 1
739 1 $it->{network} = _ntoa( $n & $m );
740 1 return;
741 }
742  
743 0 ▶sub _name_taken {
Subroutine _name_taken: not called CC=5 SCAR=34.0
744 0 my ( $list, $name, @except ) = @_;
745 0 for my $it (@$list) {
746 0 ▶ next if grep { $_ == $it } @except;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $it;} @except 0 0 0
747 0 ▶ return 1 if defined $it->{name} && $it->{name} eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$it{"name"} and $$it{"name"} eq $name 0 0 0
Condition0%0/3
defined $$it{"name"} and $$it{"name"} eq $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$it{"name"} and $$it{"name"} eq $name
defined $$it{"name"} $$it{"name"} eq $name
Truth table0%0/3
A and B
A= defined $$it{"name"}B= $$it{"name"} eq $name
ABresult
0X0
100
111
748 }
749 0 return 0;
750 }
751  
752 11 ▶sub _c_add {
Subroutine _c_add: called CC=16 SCAR=32.2
753 11 my ( $s, $path, $toks, $L ) = @_;
754 11 my $spec = _spec( $s, $path );
755 11 my $a = _args( $spec, $toks, $L, props => 'write', keys => ['place-before'] );
756 10 my $before = _take( $a, 'place-before' );
757 10 my ( %it, %changed );
758 10 for ( @{ $a->{kv} } ) {
759 22 my ( $k, $v ) = @$_;
760 22 $v = _norm( $spec, $k, _val( $v, $L ) );
761 19 $changed{$k} = 1;
762 19 ▶ next if $v eq '' || ( $spec->{is_flag}{$k} && $v eq 'no' );
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "" or $$spec{"is_flag"}{$k} and $v eq "no" 0 19 19
Condition33%2/6
$v eq "" or $$spec{"is_flag"}{$k} and $v eq "no"
l!l&&r!l&&!r
0019
$$spec{"is_flag"}{$k} and $v eq "no"
!ll&&!rl&&r
1900
MC/DC0%0/3
$v eq "" or $$spec{"is_flag"}{$k} and $v eq "no"
$v eq "" $$spec{"is_flag"}{$k} $v eq "no"
Truth table25%1/4
A or B and C
A= $v eq ""B= $$spec{"is_flag"}{$k}C= $v eq "no"
ABCresult
1XX1
0111
00X0
0100
763 19 $it{$k} = $v;
764 }
765 7 my $list = _list( $s, $path );
766 7 ▶ if ( $spec->{autoname} && !defined $it{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$spec{"autoname"} and not defined $it{"name"}) 0 7 7
Condition33%1/3
$$spec{"autoname"} and not defined $it{"name"}
!ll&&!rl&&r
700
MC/DC0%0/2
$$spec{"autoname"} and not defined $it{"name"}
$$spec{"autoname"} not defined $it{"name"}
Truth table33%1/3
A and not(B)
A= $$spec{"autoname"}B= not defined $it{"name"}
ABresult
0X0
100
111
767 0 my $i = 1;
768 0 ▶ $i++ while _name_taken( $list, "$spec->{autoname}$i" );
Branch: 1 branch
BranchTrueFalseTotal
_name_taken($list, qq[$$spec{"autoname"}$i]) and do { ++$i } 0 0 0
769 0 $it{name} = "$spec->{autoname}$i";
770 }
771 7 for my $r ( @{ $spec->{required} } ) {
772 8 ▶ _err("failure: $r not specified") unless defined $it{$r} && length $it{$r};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $it{$r} and length $it{$r} 1 7 8
Condition66%2/3
defined $it{$r} and length $it{$r}
!ll&&!rl&&r
107
MC/DC50%1/2
defined $it{$r} and length $it{$r}
defined $it{$r} length $it{$r}
Truth table66%2/3
A and B
A= defined $it{$r}B= length $it{$r}
ABresult
0X0
100
111
773 }
774 6 ▶ _err('failure: already have item with such name') if $spec->{has_name} && defined $it{name} && _name_taken( $list, $it{name} );
Branch: 1 branch
BranchTrueFalseTotal
if $$spec{"has_name"} and defined $it{"name"} and _name_taken($list, $it{"name"}) 0 6 6
Condition33%2/6
$$spec{"has_name"} and defined $it{"name"} and _name_taken($list, $it{"name"})
!ll&&!rl&&r
600
$$spec{"has_name"} and defined $it{"name"}
!ll&&!rl&&r
600
MC/DC0%0/3
$$spec{"has_name"} and defined $it{"name"} and _name_taken($list, $it{"name"})
$$spec{"has_name"} defined $it{"name"} _name_taken($list, $it{"name"})
Truth table25%1/4
A and B and C
A= $$spec{"has_name"}B= defined $it{"name"}C= _name_taken($list, $it{"name"})
ABCresult
0XX0
10X0
1100
1111
775 6 _fixup( $spec, \%it, \%changed );
776 6 my $at = @$list;
777 6 ▶ if ($before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before) 1 5 6
778 1 my ($ref) = _refs( $s, $spec, $path, $list, $before, $L );
779 1 ▶ $at = _index_of( $list, $ref ) if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 1 0 1
780 }
781 6 splice @{ _list( $s, $path, 1 ) }, $at, 0, \%it;
782 6 return '';
783 }
784  
785 24 ▶sub _numbers {
Subroutine _numbers: called CC=3 SCAR=11.0
786 24 my ( $s, $spec, $path, $a, $L ) = @_;
787 24 ▶ my $v = _take( $a, 'numbers' ) // shift @{ $a->{pos} };
Condition66%2/3
_take($a, "numbers") // shift @{$$a{"pos"};}
l!l&&r!l&&!r
0231
MC/DC50%1/2
_take($a, "numbers") // shift @{$$a{"pos"};}
_take($a, "numbers") shift @{$$a{"pos"};}
Truth table66%2/3
A // B
A= _take($a, "numbers")B= shift @{$$a{"pos"};}
ABresult
1X1
011
000
788 24 ▶ _err('missing value(s) of argument(s) numbers') unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 1 23 24
789 23 return _refs( $s, $spec, $path, _list( $s, $path ), $v, $L );
790 }
791  
792 24 ▶sub _no_dynamic {
Subroutine _no_dynamic: called CC=2 SCAR=6.9
793 24 my ( $verb, @refs ) = @_;
794 24 ▶ _err("failure: can not $verb dynamic item") if grep { _yes( $_->{dynamic} ) } @refs;
Branch: 1 branch
BranchTrueFalseTotal
if grep {_yes($$_{"dynamic"});} @refs 2 22 24
795 22 return;
796 }
797  
798 18 ▶sub _apply {
Subroutine _apply: called CC=6 SCAR=17.9
799 18 my ( $spec, $it, $k, $v ) = @_;
800 18 ▶ if ( !defined $v || $v eq '' ) { delete $it->{$k}; return }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v or $v eq "") 2 16 18
Condition100%3/3
not defined $v or $v eq ""
l!l&&r!l&&!r
1116
MC/DC100%2/2
not defined $v or $v eq ""
not defined $v $v eq ""
Truth table100%3/3
not(A) or B
A= not defined $vB= $v eq ""
ABresult
1X1
011
000
801 16 ▶ return if $spec->{is_flag}{$k} && $v eq 'no' && !exists $it->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $$spec{"is_flag"}{$k} and $v eq "no" and not exists $$it{$k} 1 15 16
Condition100%6/6
$$spec{"is_flag"}{$k} and $v eq "no" and not exists $$it{$k}
!ll&&!rl&&r
1231
$$spec{"is_flag"}{$k} and $v eq "no"
!ll&&!rl&&r
1024
MC/DC100%3/3
$$spec{"is_flag"}{$k} and $v eq "no" and not exists $$it{$k}
$$spec{"is_flag"}{$k} $v eq "no" not exists $$it{$k}
Truth table100%4/4
A and B and not(C)
A= $$spec{"is_flag"}{$k}B= $v eq "no"C= not exists $$it{$k}
ABCresult
0XX0
10X0
1100
1111
802 15 $it->{$k} = $v;
803 15 return;
804 }
805  
806 13 ▶sub _c_set {
Subroutine _c_set: called CC=19 SCAR=33.4
807 13 my ( $s, $path, $toks, $L ) = @_;
808 13 my $spec = _spec( $s, $path );
809 13 ▶ if ( _kind( $s, $path ) eq 'settings' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_kind($s, $path) eq "settings") 3 10 13
810 3 my $a = _args( $spec, $toks, $L, props => 'write', unset => 1 );
811 3 my @ch = ( ( map { [ $_->[0], _norm( $spec, $_->[0], _val( $_->[1], $L ) ) ] } @{ $a->{kv} } ),
812 0 map { [ $_, undef ] } @{ $a->{unset} } );
813 2 ▶ if ( $spec->{identity} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$spec{"identity"}) 1 1 2
814 1 ▶ for (@ch) { $s->{dev}{identity} = $_->[1] if $_->[0] eq 'name' && defined $_->[1] && length $_->[1] }
Branch: 1 branch
BranchTrueFalseTotal
if $$_[0] eq "name" and defined $$_[1] and length $$_[1] 1 0 1
Condition33%2/6
$$_[0] eq "name" and defined $$_[1] and length $$_[1]
!ll&&!rl&&r
001
$$_[0] eq "name" and defined $$_[1]
!ll&&!rl&&r
001
MC/DC0%0/3
$$_[0] eq "name" and defined $$_[1] and length $$_[1]
$$_[0] eq "name" defined $$_[1] length $$_[1]
Truth table25%1/4
A and B and C
A= $$_[0] eq "name"B= defined $$_[1]C= length $$_[1]
ABCresult
0XX0
10X0
1100
1111
815 1 return '';
816 }
817 1 ▶ return '' unless @ch;
Branch: 1 branch
BranchTrueFalseTotal
unless @ch 0 1 1
818 1 ▶ $s->{dev}{settings} = {} unless ref $s->{dev}{settings} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$s{"dev"}{"settings"} eq "HASH" 0 1 1
819 1 ▶ my $h = $s->{dev}{settings}{$path} //= {};
Condition50%1/2
$$s{"dev"}{"settings"}{$path} //= {}
l!l
10
MC/DC0%0/1
$$s{"dev"}{"settings"}{$path} //= {}
$$s{"dev"}{"settings"}{$path}
Truth table50%1/2
A
A= $$s{"dev"}{"settings"}{$path}
Aresult
11
00
820 1 _apply( $spec, $h, @$_ ) for @ch;
821 1 return '';
822 }
823 10 my $a = _args( $spec, $toks, $L, props => 'write', keys => ['numbers'], pos => 1, unset => 1 );
824 9 my @refs = _numbers( $s, $spec, $path, $a, $L );
825 6 my @ch = ( ( map { [ $_->[0], _norm( $spec, $_->[0], _val( $_->[1], $L ) ) ] } @{ $a->{kv} } ),
826 7 map { [ $_, undef ] } @{ $a->{unset} } );
827 7 ▶ return '' unless @ch;
Branch: 1 branch
BranchTrueFalseTotal
unless @ch 0 7 7
828 7 _no_dynamic( 'change', @refs );
829 0 ▶ my ($name) = map { $_->[1] } grep { $_->[0] eq 'name' && defined $_->[1] && length $_->[1] } @ch;
Condition33%2/6
$$_[0] eq 'name' && defined $$_[1] && length $$_[1]
!ll&&!rl&&r
600
$$_[0] eq "name" and defined $$_[1]
!ll&&!rl&&r
600
MC/DC0%0/3
$$_[0] eq 'name' && defined $$_[1] && length $$_[1]
$$_[0] eq "name" defined $$_[1] length $$_[1]
Truth table25%1/4
A and B && C
A= $$_[0] eq "name"B= defined $$_[1]C= length $$_[1]
ABCresult
0XX0
10X0
1100
1111
830 6 ▶ _err('failure: already have item with such name')
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and @refs > 1 || _name_taken(_list($s, $path), $name, @refs) 0 6 6
Condition16%1/6
defined $name and @refs > 1 || _name_taken(_list($s, $path), $name, @refs)
!ll&&!rl&&r
600
@refs > 1 or _name_taken(_list($s, $path), $name, @refs)
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $name and @refs > 1 || _name_taken(_list($s, $path), $name, @refs)
defined $name @refs > 1 _name_taken(_list($s, $path), $name, @refs)
Truth table25%1/4
A and B or C
A= defined $nameB= @refs > 1C= _name_taken(_list($s, $path), $name, @refs)
ABCresult
0XX0
1000
11X1
1011
831 if defined $name && ( @refs > 1 || _name_taken( _list( $s, $path ), $name, @refs ) );
832 6 my %changed = map { $_->[0] => 1 } @ch;
833 6 for my $it (@refs) {
834 9 _apply( $spec, $it, @$_ ) for @ch;
835 9 _fixup( $spec, $it, \%changed );
836 }
837 6 return '';
838 }
839  
840 8 ▶sub _c_remove {
Subroutine _c_remove: called CC=2 SCAR=6.9
841 8 my ( $s, $path, $toks, $L ) = @_;
842 8 my $spec = _spec( $s, $path );
843 8 my $a = _args( $spec, $toks, $L, keys => ['numbers'], pos => 1 );
844 8 my @refs = _numbers( $s, $spec, $path, $a, $L );
845 7 ▶ _no_dynamic( 'remove', @refs ) unless $spec->{lease};
Branch: 1 branch
BranchTrueFalseTotal
unless $$spec{"lease"} 5 2 7
846 6 my $list = _list( $s, $path );
847 6 my %gone = map { $_ => 1 } @refs;
848 6 @$list = grep { !$gone{$_} } @$list;
849 6 return '';
850 }
851  
852 6 ▶sub _endis {
Subroutine _endis: called CC=2 SCAR=6.9
853 6 my ( $s, $path, $toks, $L, $v ) = @_;
854 6 my $spec = _spec( $s, $path );
855 6 my $a = _args( $spec, $toks, $L, keys => ['numbers'], pos => 1 );
856 6 my @refs = _numbers( $s, $spec, $path, $a, $L );
857 6 _no_dynamic( 'change', @refs );
858 6 _apply( $spec, $_, disabled => $v ) for @refs;
859 6 return '';
860 }
861 2 ▶sub _c_disable { return _endis( @_, 'yes' ) }
Subroutine _c_disable: called CC=1 SCAR=0.0
862 4 ▶sub _c_enable { return _endis( @_, 'no' ) }
Subroutine _c_enable: called CC=1 SCAR=0.0
863  
864 1 ▶sub _c_comment {
Subroutine _c_comment: called CC=7 SCAR=20.8
865 1 my ( $s, $path, $toks, $L ) = @_;
866 1 my $spec = _spec( $s, $path );
867 1 my $a = _args( $spec, $toks, $L, keys => [qw( numbers comment )], pos => 2 );
868 1 my $c = _take( $a, 'comment' );
869 1 ▶ my $num = _take( $a, 'numbers' ) // shift @{ $a->{pos} };
Condition33%1/3
_take($a, "numbers") // shift @{$$a{"pos"};}
l!l&&r!l&&!r
010
MC/DC0%0/2
_take($a, "numbers") // shift @{$$a{"pos"};}
_take($a, "numbers") shift @{$$a{"pos"};}
Truth table33%1/3
A // B
A= _take($a, "numbers")B= shift @{$$a{"pos"};}
ABresult
1X1
011
000
870 0 ▶ $c //= shift @{ $a->{pos} };
Condition33%1/3
$c //= shift @{$$a{"pos"};}
l!l&&r!l&&!r
100
MC/DC0%0/2
$c //= shift @{$$a{"pos"};}
$c shift @{$$a{"pos"};}
Truth table33%1/3
A //= B
A= $cB= shift @{$$a{"pos"};}
ABresult
1X1
011
000
871 1 ▶ _errat( 'expected end of command', $L, $a->{pos}[0]{col} ) if @{ $a->{pos} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$a{"pos"};} 0 1 1
872 1 ▶ _err('missing value(s) of argument(s) numbers') unless $num;
Branch: 1 branch
BranchTrueFalseTotal
unless $num 0 1 1
873 1 ▶ _err('missing value(s) of argument(s) comment') unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 1 1
874 1 my $text = _val( $c, $L );
875 1 my @refs = _refs( $s, $spec, $path, _list( $s, $path ), $num, $L );
876 1 _no_dynamic( 'change', @refs );
877 1 _apply( $spec, $_, comment => $text ) for @refs;
878 1 return '';
879 }
880  
881 6 ▶sub _c_move {
Subroutine _c_move: called CC=9 SCAR=22.1
882 6 my ( $s, $path, $toks, $L ) = @_;
883 6 my $spec = _spec( $s, $path );
884 6 my $a = _args( $spec, $toks, $L, keys => [qw( numbers destination )], pos => 2 );
885 6 my $dv = _take( $a, 'destination' );
886 6 ▶ my $num = _take( $a, 'numbers' ) // shift @{ $a->{pos} };
Condition66%2/3
_take($a, "numbers") // shift @{$$a{"pos"};}
l!l&&r!l&&!r
150
MC/DC0%0/2
_take($a, "numbers") // shift @{$$a{"pos"};}
_take($a, "numbers") shift @{$$a{"pos"};}
Truth table66%2/3
A // B
A= _take($a, "numbers")B= shift @{$$a{"pos"};}
ABresult
1X1
011
000
887 6 ▶ $dv //= shift @{ $a->{pos} };
Condition100%3/3
$dv //= shift @{$$a{"pos"};}
l!l&&r!l&&!r
141
MC/DC100%2/2
$dv //= shift @{$$a{"pos"};}
$dv shift @{$$a{"pos"};}
Truth table100%3/3
A //= B
A= $dvB= shift @{$$a{"pos"};}
ABresult
1X1
011
000
888 6 ▶ _errat( 'expected end of command', $L, $a->{pos}[0]{col} ) if @{ $a->{pos} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$a{"pos"};} 0 6 6
889 6 ▶ _err('missing value(s) of argument(s) numbers') unless $num;
Branch: 1 branch
BranchTrueFalseTotal
unless $num 0 6 6
890 6 my $list = _list( $s, $path );
891 6 my @refs = _refs( $s, $spec, $path, $list, $num, $L );
892 6 ▶ my ($dest) = $dv ? _refs( $s, $spec, $path, $list, $dv, $L ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$dv ? : 5 1 6
893 5 _no_dynamic( 'move', @refs );
894 5 ▶ return '' if $dest && grep { $_ == $dest } @refs;
Branch: 1 branch
BranchTrueFalseTotal
if $dest and grep {$_ == $dest;} @refs 0 5 5
Condition66%2/3
$dest and grep {$_ == $dest;} @refs
!ll&&!rl&&r
140
MC/DC0%0/2
$dest and grep {$_ == $dest;} @refs
$dest grep {$_ == $dest;} @refs
Truth table66%2/3
A and B
A= $destB= grep {$_ == $dest;} @refs
ABresult
0X0
100
111
895 5 my %mv = map { $_ => 1 } @refs;
896 5 my @keep = grep { !$mv{$_} } @$list;
897 5 my @move = grep { $mv{$_} } @$list; # Reihenfolge der Liste behalten
898 5 ▶ my $at = $dest ? _index_of( \@keep, $dest ) : @keep;
Branch: 1 branch
BranchTrueFalseTotal
$dest ? : 4 1 5
899 5 splice @keep, $at, 0, @move;
900 5 @$list = @keep;
901 5 return '';
902 }
903  
904 1 ▶sub _c_find {
Subroutine _c_find: called CC=4 SCAR=15.9
905 1 my ( $s, $path, $toks, $L ) = @_;
906 1 my @t = @$toks;
907 1 ▶ shift @t if @t && !$t[0]{quoted} && $t[0]{text} eq 'where';
Branch: 1 branch
BranchTrueFalseTotal
if @t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where" 0 1 1
Condition33%2/6
@t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where"
!ll&&!rl&&r
010
@t and not $t[0]{"quoted"}
!ll&&!rl&&r
001
MC/DC0%0/3
@t and not $t[0]{"quoted"} and $t[0]{"text"} eq "where"
@t not $t[0]{"quoted"} $t[0]{"text"} eq "where"
Truth table25%1/4
A and not(B) and C
A= @tB= not $t[0]{"quoted"}C= $t[0]{"text"} eq "where"
ABCresult
0XX0
10X0
1100
1111
908 1 _cond( _spec( $s, $path ), \@t, $L );
909 1 return '';
910 }
911  
912 1 ▶sub _c_make_static {
Subroutine _c_make_static: called CC=2 SCAR=6.9
913 1 my ( $s, $path, $toks, $L ) = @_;
914 1 my $spec = _spec( $s, $path );
915 1 my $a = _args( $spec, $toks, $L, keys => ['numbers'], pos => 1 );
916 1 delete $_->{dynamic} for _numbers( $s, $spec, $path, $a, $L );
917 1 return '';
918 }
919  
920 0 ▶sub _c_noop {
Subroutine _c_noop: not called CC=3 SCAR=24.8
921 0 my ( $s, $path, $toks, $L ) = @_;
922 0 my $spec = _spec( $s, $path );
923 0 my $a = _args( $spec, $toks, $L, keys => ['numbers'], pos => 1 );
924 0 ▶ _numbers( $s, $spec, $path, $a, $L ) if @{ $a->{pos} } || @{ $a->{kv} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$a{"pos"};} or @{$$a{"kv"};} 0 0 0
Condition0%0/3
@{$$a{"pos"};} or @{$$a{"kv"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$$a{"pos"};} or @{$$a{"kv"};}
@{$$a{"pos"};} @{$$a{"kv"};}
Truth table0%0/3
A or B
A= @{$$a{"pos"};}B= @{$$a{"kv"};}
ABresult
1X1
011
000
925 0 return '';
926 }
927  
928 2 ▶sub _c_reboot {
Subroutine _c_reboot: called CC=2 SCAR=6.9
929 2 my ( $s, $path, $toks, $L ) = @_;
930 2 _args( {}, $toks, $L );
931 2 ▶ $s->{dev}{reboots} = ( $s->{dev}{reboots} // 0 ) + 1;
Condition100%2/2
$$s{"dev"}{"reboots"} // 0
l!l
11
MC/DC100%1/1
$$s{"dev"}{"reboots"} // 0
$$s{"dev"}{"reboots"}
Truth table100%2/2
A
A= $$s{"dev"}{"reboots"}
Aresult
11
00
932 2 return { out => "Reboot, yes? [y/N]: y\nsystem will reboot shortly", stop => 1 };
933 }
934  
935 1 ▶sub _c_shutdown {
Subroutine _c_shutdown: called CC=1 SCAR=0.0
936 1 my ( $s, $path, $toks, $L ) = @_;
937 1 _args( {}, $toks, $L );
938 1 $s->{dev}{shutdown} = 'yes';
939 1 return { out => "Shutdown, yes? [y/N]: y\nsystem will shutdown promptly", stop => 1 };
940 }
941  
942 # --- ping / traceroute aus dem Zustand ----------------------------------------
943  
944 25 ▶sub _ip {
Subroutine _ip: called CC=4 SCAR=14.0
945 25 my ($x) = @_;
946 25 ▶ return undef unless defined $x && $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x and $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ 1 24 25
Condition66%2/3
defined $x and $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
!ll&&!rl&&r
0124
MC/DC50%1/2
defined $x and $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
defined $x $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
Truth table66%2/3
A and B
A= defined $xB= $x =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
ABresult
0X0
100
111
947 24 ▶ return undef if grep { $_ > 255 } $1, $2, $3, $4;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ > 255;} $1, $2, $3, $4 0 24 24
948 24 return ( $1 << 24 ) | ( $2 << 16 ) | ( $3 << 8 ) | $4;
949 }
950  
951 14 ▶sub _net {
Subroutine _net: called CC=7 SCAR=20.7
952 14 my ($cidr) = @_;
953 14 ▶ my ( $a, $l ) = ( $cidr // '' ) =~ m{\A([\d.]+)(?:/(\d+))?\z} or return;
Branch: 1 branch
BranchTrueFalseTotal
() = ($cidr // "") =~ m[\A([\d.]+)(?:/(\d+))?\z] or return 14 0 14
Condition50%1/2
$cidr // ""
l!l
140
MC/DC0%0/1
$cidr // ""
$cidr
Truth table50%1/2
A
A= $cidr
Aresult
11
00
954 14 ▶ $l //= 32;
Condition50%1/2
$l //= 32
l!l
140
MC/DC0%0/1
$l //= 32
$l
Truth table50%1/2
A
A= $l
Aresult
11
00
955 14 ▶ return if $l > 32;
Branch: 1 branch
BranchTrueFalseTotal
if $l > 32 0 14 14
956 14 ▶ my $n = _ip($a) // return;
Condition50%1/2
_ip($a) // (return)
l!l
140
MC/DC0%0/1
_ip($a) // (return)
_ip($a)
Truth table50%1/2
A
A= _ip($a)
Aresult
11
00
957 14 ▶ my $m = $l ? ( 0xFFFFFFFF << ( 32 - $l ) ) & 0xFFFFFFFF : 0;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 11 3 14
958 14 return ( $n, $m, $l );
959 }
960  
961 6 ▶sub _ntoa { my ($n) = @_; return join '.', map { ( $n >> $_ ) & 255 } 24, 16, 8, 0 }
Subroutine _ntoa: called CC=1 SCAR=0.0
962  
963 # { kind => local|connected|routed|blackhole, gw => ip } oder undef
964 5 ▶sub _route {
Subroutine _route: called CC=30 SCAR=43.0
965 5 my ( $s, $ip ) = @_;
966 5 my @conn;
967 5 for my $a ( @{ _list( $s, '/ip address' ) } ) {
968 10 ▶ next if _yes( $a->{disabled} ) || _yes( $a->{invalid} );
Branch: 1 branch
BranchTrueFalseTotal
if _yes($$a{"disabled"}) or _yes($$a{"invalid"}) 0 10 10
Condition33%1/3
_yes($$a{"disabled"}) or _yes($$a{"invalid"})
l!l&&r!l&&!r
0010
MC/DC0%0/2
_yes($$a{"disabled"}) or _yes($$a{"invalid"})
_yes($$a{"disabled"}) _yes($$a{"invalid"})
Truth table33%1/3
A or B
A= _yes($$a{"disabled"})B= _yes($$a{"invalid"})
ABresult
1X1
011
000
969 10 ▶ my ( $n, $m ) = _net( $a->{address} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _net($$a{"address"}) or next 10 0 10
970 10 ▶ return { kind => 'local' } if $n == $ip;
Branch: 1 branch
BranchTrueFalseTotal
if $n == $ip 0 10 10
971 10 push @conn, [ $n, $m ];
972 }
973 5 ▶ my $on_link = sub { my ($x) = @_; return grep { ( $x & $_->[1] ) == ( $_->[0] & $_->[1] ) } @conn };
Subroutine __ANON__: called CC=1 SCAR=0.0
974 5 ▶ return { kind => 'connected' } if $on_link->($ip);
Branch: 1 branch
BranchTrueFalseTotal
if &$on_link($ip) 1 4 5
975 4 my ( $best, $bl, $bd );
976 4 for my $r ( @{ _list( $s, '/ip route' ) } ) {
977 3 ▶ next if _yes( $r->{disabled} );
Branch: 1 branch
BranchTrueFalseTotal
if _yes($$r{"disabled"}) 0 3 3
978 3 ▶ next if defined $r->{'routing-table'} && $r->{'routing-table'} ne 'main';
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"routing-table"} and $$r{"routing-table"} ne "main" 0 3 3
Condition33%1/3
defined $$r{"routing-table"} and $$r{"routing-table"} ne "main"
!ll&&!rl&&r
300
MC/DC0%0/2
defined $$r{"routing-table"} and $$r{"routing-table"} ne "main"
defined $$r{"routing-table"} $$r{"routing-table"} ne "main"
Truth table33%1/3
A and B
A= defined $$r{"routing-table"}B= $$r{"routing-table"} ne "main"
ABresult
0X0
100
111
979 3 ▶ my ( $n, $m, $l ) = _net( $r->{'dst-address'} // '0.0.0.0/0' ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _net($$r{"dst-address"} // "0.0.0.0/0") or next 3 0 3
Condition50%1/2
$$r{"dst-address"} // "0.0.0.0/0"
l!l
30
MC/DC0%0/1
$$r{"dst-address"} // "0.0.0.0/0"
$$r{"dst-address"}
Truth table50%1/2
A
A= $$r{"dst-address"}
Aresult
11
00
980 3 ▶ next unless ( $ip & $m ) == ( $n & $m );
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip & $m) == ($n & $m) 0 3 3
981 3 ▶ my $bh = _yes( $r->{blackhole} ) || ( $r->{type} // '' ) =~ /\A(?:blackhole|unreachable|prohibit)\z/;
Condition40%2/5
_yes($$r{'blackhole'}) || ($$r{'type'} // '') =~ /\A(?:blackhole|unreachable|prohibit)\z/
l!l&&r!l&&!r
003
$$r{"type"} // ""
l!l
03
MC/DC0%0/2
_yes($$r{'blackhole'}) || ($$r{'type'} // '') =~ /\A(?:blackhole|unreachable|prohibit)\z/
_yes($$r{'blackhole'}) $$r{"type"}
Truth table33%1/3
A || B
A= _yes($$r{'blackhole'})B= $$r{"type"}
ABresult
1X1
011
000
982 3 ▶ my ($gw) = split /,/, $r->{gateway} // '';
Condition50%1/2
$$r{"gateway"} // ""
l!l
30
MC/DC0%0/1
$$r{"gateway"} // ""
$$r{"gateway"}
Truth table50%1/2
A
A= $$r{"gateway"}
Aresult
11
00
983 3 ▶ unless ($bh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bh) 3 0 3
984 3 ▶ next unless defined $gw && length $gw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gw and length $gw 0 3 3
Condition33%1/3
defined $gw and length $gw
!ll&&!rl&&r
003
MC/DC0%0/2
defined $gw and length $gw
defined $gw length $gw
Truth table33%1/3
A and B
A= defined $gwB= length $gw
ABresult
0X0
100
111
985 3 my $g = _ip($gw);
986 3 ▶ next if defined $g && !$on_link->($g);
Branch: 1 branch
BranchTrueFalseTotal
if defined $g and not &$on_link($g) 1 2 3
Condition66%2/3
defined $g and not &$on_link($g)
!ll&&!rl&&r
021
MC/DC50%1/2
defined $g and not &$on_link($g)
defined $g not &$on_link($g)
Truth table66%2/3
A and not(B)
A= defined $gB= not &$on_link($g)
ABresult
0X0
100
111
987 }
988 2 ▶ my $d = $r->{distance} // 1;
Condition50%1/2
$$r{"distance"} // 1
l!l
20
MC/DC0%0/1
$$r{"distance"} // 1
$$r{"distance"}
Truth table50%1/2
A
A= $$r{"distance"}
Aresult
11
00
989 2 ▶ $d = 1 unless $d =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $d =~ /\A\d+\z/ 0 2 2
990 2 ▶ next if $best && ( $l < $bl || ( $l == $bl && $d >= $bd ) );
Branch: 1 branch
BranchTrueFalseTotal
if $best and $l < $bl || $l == $bl && $d >= $bd 0 2 2
Condition11%1/9
$best and $l < $bl || $l == $bl && $d >= $bd
!ll&&!rl&&r
200
$l < $bl or $l == $bl and $d >= $bd
l!l&&r!l&&!r
000
$l == $bl and $d >= $bd
!ll&&!rl&&r
000
MC/DC0%0/4
$best and $l < $bl || $l == $bl && $d >= $bd
$best $l < $bl $l == $bl $d >= $bd
Truth table20%1/5
A and B or C and D
A= $bestB= $l < $blC= $l == $blD= $d >= $bd
ABCDresult
0XXX0
100X0
10100
11XX1
10111
991 2 ▶ ( $best, $bl, $bd ) = ( { kind => $bh ? 'blackhole' : 'routed', gw => defined _ip($gw) ? $gw : undef }, $l, $d );
Branch: 2 branches
BranchTrueFalseTotal
$bh ? : 0 2 2
defined _ip($gw) ? : 2 0 2
992 }
993 4 return $best;
994 }
995  
996 6 ▶sub _target {
Subroutine _target: called CC=8 SCAR=26.3
997 6 my ( $s, $toks, $L, @keys ) = @_;
998 6 my $a = _args( {}, $toks, $L, keys => [ 'address', @keys ], pos => 1, words => ['do-not-fragment'] );
999 6 ▶ my $t = _take( $a, 'address' ) // shift @{ $a->{pos} };
Condition33%1/3
_take($a, "address") // shift @{$$a{"pos"};}
l!l&&r!l&&!r
060
MC/DC0%0/2
_take($a, "address") // shift @{$$a{"pos"};}
_take($a, "address") shift @{$$a{"pos"};}
Truth table33%1/3
A // B
A= _take($a, "address")B= shift @{$$a{"pos"};}
ABresult
1X1
011
000
1000 6 ▶ _err('missing value(s) of argument(s) address') unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 6 6
1001 6 my $name = _val( $t, $L );
1002 6 my $ip = _ip($name);
1003 6 ▶ unless ( defined $ip ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip) 1 5 6
1004 0 ▶ my ($st) = grep { !_yes( $_->{disabled} ) && ( $_->{name} // '' ) eq $name && defined _ip( $_->{address} ) }
Condition0%0/8
!_yes($$_{'disabled'}) && ($$_{'name'} // '') eq $name && defined _ip($$_{'address'})
!ll&&!rl&&r
000
not _yes($$_{"disabled"}) and ($$_{"name"} // "") eq $name
!ll&&!rl&&r
000
$$_{"name"} // ""
l!l
00
MC/DC0%0/3
!_yes($$_{'disabled'}) && ($$_{'name'} // '') eq $name && defined _ip($$_{'address'})
not _yes($$_{"disabled"}) $$_{"name"} defined _ip($$_{'address'})
Truth table0%0/4
not(A) and B && C
A= not _yes($$_{"disabled"})B= $$_{"name"}C= defined _ip($$_{'address'})
ABCresult
0XX0
10X0
1100
1111
1005 1 @{ _list( $s, '/ip dns static' ) };
1006 1 ▶ _err('invalid value for argument address') unless $st;
Branch: 1 branch
BranchTrueFalseTotal
unless $st 1 0 1
1007 0 $ip = _ip( $st->{address} );
1008 }
1009 5 return ( $a, $ip );
1010 }
1011  
1012 5 ▶sub _c_ping {
Subroutine _c_ping: called CC=15 SCAR=28.2
1013 5 my ( $s, $path, $toks, $L ) = @_;
1014 5 my ( $a, $ip ) = _target( $s, $toks, $L,
1015 qw( count interface src-address size interval ttl routing-table vrf arp-ping ) );
1016 4 my %kv = map { $_->[0] => _val( $_->[1], $L ) } @{ $a->{kv} };
1017 4 ▶ my $count = $kv{count} // 3;
Condition100%2/2
$kv{"count"} // 3
l!l
13
MC/DC100%1/1
$kv{"count"} // 3
$kv{"count"}
Truth table100%2/2
A
A= $kv{"count"}
Aresult
11
00
1018 4 ▶ _err('invalid value for argument count') unless $count =~ /\A\d+\z/ && $count > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $count =~ /\A\d+\z/ and $count > 0 0 4 4
Condition33%1/3
$count =~ /\A\d+\z/ and $count > 0
!ll&&!rl&&r
004
MC/DC0%0/2
$count =~ /\A\d+\z/ and $count > 0
$count =~ /\A\d+\z/ $count > 0
Truth table33%1/3
A and B
A= $count =~ /\A\d+\z/B= $count > 0
ABresult
0X0
100
111
1019 4 ▶ $count = 10 if $count > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 10 0 4 4
1020 4 ▶ my $size = $kv{size} // 56;
Condition50%1/2
$kv{"size"} // 56
l!l
04
MC/DC0%0/1
$kv{"size"} // 56
$kv{"size"}
Truth table50%1/2
A
A= $kv{"size"}
Aresult
11
00
1021 4 ▶ _err('invalid value for argument size') unless $size =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $size =~ /\A\d+\z/ 0 4 4
1022 4 my $host = _ntoa($ip);
1023 4 my $r = _route( $s, $ip );
1024 4 my ( $ttl, $time );
1025 4 ▶ if ( !$r || $r->{kind} eq 'blackhole' ) { }
Branch: 3 branches
BranchTrueFalseTotal
if (not $r or $$r{'kind'} eq 'blackhole') { } 2 2 4
elsif ($$r{'kind'} eq 'routed') { } 1 1 2
elsif ($$r{'kind'} eq 'local') { } 0 1 1
Condition66%2/3
not $r or $$r{"kind"} eq "blackhole"
l!l&&r!l&&!r
202
MC/DC50%1/2
not $r or $$r{"kind"} eq "blackhole"
not $r $$r{"kind"} eq "blackhole"
Truth table66%2/3
not(A) or B
A= not $rB= $$r{"kind"} eq "blackhole"
ABresult
1X1
011
000
1026 1 elsif ( $r->{kind} eq 'routed' ) { ( $ttl, $time ) = ( 57, '12ms' ) }
1027 0 elsif ( $r->{kind} eq 'local' ) { ( $ttl, $time ) = ( 64, '0ms' ) }
1028 1 else { ( $ttl, $time ) = ( 64, '1ms' ) }
1029 4 my @l = (' SEQ HOST SIZE TTL TIME STATUS');
1030 4 for my $i ( 0 .. $count - 1 ) {
1031 11 ▶ push @l, $ttl
Branch: 2 branches
BranchTrueFalseTotal
$ttl ? : 5 6 11
$r ? : 0 6 6
1032 ? sprintf( ' %3d %-40s %4d %3d %s', $i, $host, $size, $ttl, $time )
1033 : sprintf( ' %3d %-40s %4s %3s %-10s %s', $i, $host, '', '', '', $r ? 'timeout' : 'no route to host' );
1034 }
1035 4 ▶ push @l, $ttl
Branch: 1 branch
BranchTrueFalseTotal
$ttl ? : 2 2 4
1036 ? " sent=$count received=$count packet-loss=0% min-rtt=$time avg-rtt=$time max-rtt=$time"
1037 : " sent=$count received=0 packet-loss=100%";
1038 4 return _rtrim( join "\n", @l );
1039 }
1040  
1041 1 ▶sub _c_traceroute {
Subroutine _c_traceroute: called CC=9 SCAR=25.8
1042 1 my ( $s, $path, $toks, $L ) = @_;
1043 1 my ( $a, $ip ) = _target( $s, $toks, $L, qw( count interface src-address size timeout max-hops use-dns protocol port ) );
1044 1 my $host = _ntoa($ip);
1045 1 my $r = _route( $s, $ip );
1046 1 my @l = (
1047 'Columns: ADDRESS, LOSS, SENT, LAST, AVG, BEST, WORST, STD-DEV, STATUS',
1048 '# ADDRESS LOSS SENT LAST AVG BEST WORST STD-DEV STATUS',
1049 );
1050 2 ▶ my $row = sub { my ( $n, $ad, $loss, $last, $st ) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.0
1051 2 ▶ push @l, sprintf '%-2d %-16s %-5s %4d %-5s %-5s %-5s %-6s %-8s %s', $n, $ad, $loss, 3, $last,
Branch: 2 branches
BranchTrueFalseTotal
$last eq '' ? : 0 2 2
$last eq '' ? : 0 2 2
1052 1 ( $last eq '' ? ('') x 3 : ( $last =~ s/ms//r ) x 3 ), ( $last eq '' ? '' : '0' ), $st };
1053 0 ▶ if ( !$r || $r->{kind} eq 'blackhole' ) { $row->( 1, '', '100%', '', $r ? 'timeout' : 'no route to host' ) }
Branch: 2 branches
BranchTrueFalseTotal
if (not $r or $$r{'kind'} eq 'blackhole') { } 0 1 1
$r ? : 0 0 0
Condition33%1/3
not $r or $$r{"kind"} eq "blackhole"
l!l&&r!l&&!r
001
MC/DC0%0/2
not $r or $$r{"kind"} eq "blackhole"
not $r $$r{"kind"} eq "blackhole"
Truth table33%1/3
not(A) or B
A= not $rB= $$r{"kind"} eq "blackhole"
ABresult
1X1
011
000
1054 else {
1055 1 ▶ my @hops = $r->{kind} eq 'routed' && $r->{gw} && $r->{gw} ne $host ? ( $r->{gw}, $host ) : ($host);
Branch: 1 branch
BranchTrueFalseTotal
$$r{'kind'} eq 'routed' && $$r{'gw'} && $$r{'gw'} ne $host ? : 1 0 1
Condition33%2/6
$$r{"kind"} eq "routed" and $$r{"gw"} and $$r{"gw"} ne $host
!ll&&!rl&&r
001
$$r{"kind"} eq "routed" and $$r{"gw"}
!ll&&!rl&&r
001
MC/DC0%0/3
$$r{"kind"} eq "routed" and $$r{"gw"} and $$r{"gw"} ne $host
$$r{"kind"} eq "routed" $$r{"gw"} $$r{"gw"} ne $host
Truth table25%1/4
A and B and C
A= $$r{"kind"} eq "routed"B= $$r{"gw"}C= $$r{"gw"} ne $host
ABCresult
0XX0
10X0
1100
1111
1056 1 ▶ for my $i ( 0 .. $#hops ) { $row->( $i + 1, $hops[$i], '0%', $i ? '12ms' : '1ms', '' ) }
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 1 1 2
1057 }
1058 1 return _rtrim( join "\n", @l );
1059 }
1060  
1061 40 __PACKAGE__->meta->make_immutable;
1062  
1063 __END__
« blib/lib/Langertha/Holmgang/CLI.pm ↑ Summary blib/lib/Langertha/Holmgang/Runner.pm »