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

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