| 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
Condition50%3/6
defined $s and not ref $s and $s =~ /$re/
defined $s and not ref $s
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition75%6/8
defined $s and not ref $s and $s =~ /$re/
defined $s and not ref $s
$1 // ""
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/
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $l eq "ARRAY" and grep {same_scalar($_, $v);} @$l
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$s //= ""
MC/DC0%0/1
$s //= ""
$s
Truth table50%1/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $dev eq "HASH" and ref $pkt eq "HASH"
ref $dev eq "HASH" and ref $pkt eq "HASH"
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"
Truth table0%0/3
A and B
A= ref $dev eq "HASH"B= ref $pkt eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $sims = $SIMULATORS // Langertha::Holmgang::Simulators->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
$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
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
Truth table0%0/3
A // B
A= $Langertha::Holmgang::Template::SIMULATORSB= "Langertha::Holmgang::Simulators"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ( $v ) = eval { $sims->packet_verdict( $dev, $pkt ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return $v // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$v // ""
$v // ""
MC/DC100%1/1
$v // ""
$v
MC/DC0%0/1
$v // ""
$v
Truth table100%2/2
A
A= $v
Truth table0%0/2
A
A= $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 // "";
}
})
$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 // "";
}
})
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 // "";
}
})
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 // "";
}
})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $tmpl unless $tmpl =~ /<:|^\s*:/m; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | local $SIMULATORS = $sims; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return _tx()->render_string( $tmpl, { state => $state, args => $args // {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$args // {}
$args // {}
MC/DC100%1/1
$args // {}
$args
MC/DC0%0/1
$args // {}
$args
Truth table100%2/2
A
A= $args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 43 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||