blib/lib/Langertha/Holmgang/Template.pm

filter: Statementstmt 80.3% 49 / 61 Branchbran 70.0% 14 / 20 Conditioncond 48.8% 22 / 45 MC/DCmcdc 30.7% 8 / 26 Subroutinesub 82.3% 14 / 17 Podpod 100% 2 / 2 totaltotal 63.7% 109 / 171 CC 28 SCAR 16.5
CC
28
Cov
67%
__ANON__
10.2
__ANON__
10.2
render
6.0
CRAP 5.2
« blib/lib/Langertha/Holmgang/Sim/Roost.pm ↑ Summary blib/lib/Langertha/Holmgang.pm »
1 package Langertha::Holmgang::Template;
2 # ABSTRACT: Kolon output templates of handlers and observations
3  
4 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 43 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 43 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 43 ▶use Text::Xslate ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 43 ▶use Langertha::Holmgang::Expectation qw( same_scalar );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 43 ▶use Langertha::Holmgang::Simulators;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 43 our $VERSION = '0.001';
14  
15 43 our @EXPORT_OK = qw( render );
16  
17  
18 # the compiler with the fixed function table; the registry for nft_verdict comes
19 # per render through $SIMULATORS
20 43 my $TX;
21 43 our $SIMULATORS;
22  
23 1030 ▶sub _tx {
Subroutine _tx: called CC=2 SCAR=8.0
24 return $TX //= Text::Xslate->new(
25 syntax => 'Kolon',
26 type => 'text',
27 cache => 0,
28 verbose => 0,
29 function => {
30 5 ▶ re => sub { my ( $s, $re ) = @_; return defined $s && !ref $s && $s =~ /$re/ ? 1 : 0 },
Subroutine __ANON__: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
defined $s && !ref($s) && $s =~ /$re/ ? : 4 1 5
Condition50%3/6
defined $s and not ref $s and $s =~ /$re/
!ll&&!rl&&r
014
defined $s and not ref $s
!ll&&!rl&&r
005
MC/DC33%1/3
defined $s and not ref $s and $s =~ /$re/
defined $s not ref $s $s =~ /$re/
Truth table50%2/4
A and not(B) and C
A= defined $sB= not ref $sC= $s =~ /$re/
ABCresult
0XX0
10X0
1100
1111
31 6 ▶ cap => sub { my ( $s, $re ) = @_; return defined $s && !ref $s && $s =~ /$re/ ? $1 // '' : '' },
Subroutine __ANON__: called CC=5 SCAR=16.3
Branch: 1 branch
BranchTrueFalseTotal
defined $s && !ref($s) && $s =~ /$re/ ? : 4 2 6
Condition75%6/8
defined $s and not ref $s and $s =~ /$re/
!ll&&!rl&&r
114
defined $s and not ref $s
!ll&&!rl&&r
105
$1 // ""
l!l
40
MC/DC66%2/3
defined $s and not ref $s and $s =~ /$re/
defined $s not ref $s $s =~ /$re/
MC/DC0%0/1
$1 // ""
$1
Truth table75%3/4
A and not(B) and C
A= defined $sB= not ref $sC= $s =~ /$re/
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $1
Aresult
11
00
32 3 ▶ has => sub { my ( $l, $v ) = @_; return ref $l eq 'ARRAY' && ( grep { same_scalar( $_, $v ) } @$l ) ? 1 : 0 },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $l eq 'ARRAY' && grep({same_scalar($_, $v);} @$l) ? : 1 2 3
Condition100%3/3
ref $l eq "ARRAY" and grep {same_scalar($_, $v);} @$l
!ll&&!rl&&r
111
MC/DC100%2/2
ref $l eq "ARRAY" and grep {same_scalar($_, $v);} @$l
ref $l eq "ARRAY" grep {same_scalar($_, $v);} @$l
Truth table100%3/3
A and B
A= ref $l eq "ARRAY"B= grep {same_scalar($_, $v);} @$l
ABresult
0X0
100
111
33 2 ▶ pad => sub { my ( $s, $n ) = @_; $s //= ''; my $fill = $n - length $s; return $s.( $fill > 0 ? ' ' x $fill : '' ) },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$fill > 0 ? : 1 1 2
Condition50%1/2
$s //= ""
l!l
20
MC/DC0%0/1
$s //= ""
$s
Truth table50%1/2
A
A= $s
Aresult
11
00
34 4 ▶ nft_verdict => sub {
Subroutine __ANON__: called CC=5 SCAR=23.3
35 0 ▶ my ( $dev, $pkt ) = @_;
Subroutine __ANON__: not called CC=5 SCAR=23.3
36 0 ▶ return '' unless ref $dev eq 'HASH' && ref $pkt eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $dev eq "HASH" and ref $pkt eq "HASH" 1 3 4
unless ref $dev eq "HASH" and ref $pkt eq "HASH" 0 0 0
Condition33%2/6
ref $dev eq "HASH" and ref $pkt eq "HASH"
!ll&&!rl&&r
103
ref $dev eq "HASH" and ref $pkt eq "HASH"
!ll&&!rl&&r
000
MC/DC50%1/2
ref $dev eq "HASH" and ref $pkt eq "HASH"
ref $dev eq "HASH" ref $pkt eq "HASH"
MC/DC0%0/2
ref $dev eq "HASH" and ref $pkt eq "HASH"
ref $dev eq "HASH" ref $pkt eq "HASH"
Truth table66%2/3
A and B
A= ref $dev eq "HASH"B= ref $pkt eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $dev eq "HASH"B= ref $pkt eq "HASH"
ABresult
0X0
100
111
37 0 ▶ my $sims = $SIMULATORS // Langertha::Holmgang::Simulators->new;
Condition16%1/6
$Langertha::Holmgang::Template::SIMULATORS // "Langertha::Holmgang::Simulators"->new
l!l&&r!l&&!r
030
$Langertha::Holmgang::Template::SIMULATORS // "Langertha::Holmgang::Simulators"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$Langertha::Holmgang::Template::SIMULATORS // "Langertha::Holmgang::Simulators"->new
$Langertha::Holmgang::Template::SIMULATORS "Langertha::Holmgang::Simulators"->new
MC/DC0%0/2
$Langertha::Holmgang::Template::SIMULATORS // "Langertha::Holmgang::Simulators"->new
$Langertha::Holmgang::Template::SIMULATORS "Langertha::Holmgang::Simulators"->new
Truth table33%1/3
A // B
A= $Langertha::Holmgang::Template::SIMULATORSB= "Langertha::Holmgang::Simulators"->new
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $Langertha::Holmgang::Template::SIMULATORSB= "Langertha::Holmgang::Simulators"->new
ABresult
1X1
011
000
38 0 my ( $v ) = eval { $sims->packet_verdict( $dev, $pkt ) };
39 0 ▶ return $v // '';
Condition50%2/4
$v // ""
l!l
21
$v // ""
l!l
00
MC/DC100%1/1
$v // ""
$v
MC/DC0%0/1
$v // ""
$v
Truth table100%2/2
A
A= $v
Aresult
11
00
Truth table0%0/2
A
A= $v
Aresult
11
00
40 },
41 },
42 0 ▶ );
Subroutine _tx: not called CC=2 SCAR=10.9
Condition33%2/6
$TX //= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
l!l&&r!l&&!r
1008220
$TX //= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
l!l&&r!l&&!r
000
MC/DC0%0/2
$TX //= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
$TX "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
MC/DC0%0/2
$TX //= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
$TX "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
Truth table66%2/3
A //= B
A= $TXB= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
ABresult
1X1
011
000
Truth table0%0/3
A //= B
A= $TXB= "Text::Xslate"->new("syntax", "Kolon", "type", "text", "cache", 0, "verbose", 0, "function", {"re", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? 1 : 0; } , "cap", sub { my($s, $re) = @_; return defined $s && !ref($s) && $s =~ /$re/ ? $1 // "" : ""; } , "has", sub { my($l, $v) = @_; return ref $l eq "ARRAY" && grep({same_scalar($_, $v);} @$l) ? 1 : 0; } , "pad", sub { my($s, $n) = @_; $s //= ""; my $fill = $n - length($s); return $s . ($fill > 0 ? " " x $fill : ""); } , "nft_verdict", sub { my($dev, $pkt) = @_; return "" unless ref $dev eq "HASH" and ref $pkt eq "HASH"; my $sims = $SIMULATORS // "Langertha::Holmgang::Simulators"->new; my($v) = eval { do { $sims->packet_verdict($dev, $pkt) } }; return $v // ""; } })
ABresult
1X1
011
000
43 }
44  
45  
46 2222 ▶sub render {
Subroutine render: called CC=4 SCAR=17.9
Pod documented
47 0 ▶ my ( $tmpl, $state, $args, $sims ) = @_;
Subroutine render: not called CC=4 SCAR=17.9
Pod documented
48 0 ▶ return 'ok' unless defined $tmpl;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $tmpl 4 2218 2222
unless defined $tmpl 0 0 0
49 0 ▶ return $tmpl unless $tmpl =~ /<:|^\s*:/m;
Branch: 2 branches
BranchTrueFalseTotal
unless $tmpl =~ /<:|^\s*:/m 1188 1030 2218
unless $tmpl =~ /<:|^\s*:/m 0 0 0
50 0 local $SIMULATORS = $sims;
51 0 ▶ return _tx()->render_string( $tmpl, { state => $state, args => $args // {} } );
Condition50%2/4
$args // {}
l!l
10291
$args // {}
l!l
00
MC/DC100%1/1
$args // {}
$args
MC/DC0%0/1
$args // {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
Truth table0%0/2
A
A= $args
Aresult
11
00
52 }
53  
54 43 1;
55  
56 __END__
« blib/lib/Langertha/Holmgang/Sim/Roost.pm ↑ Summary blib/lib/Langertha/Holmgang.pm »