blib/lib/Text/Nunjucks/Nodes/CallExtension.pm

filter: Statementstmt 77.7% 28 / 36 Branchbran 43.7% 7 / 16 Conditioncond 36.3% 8 / 22 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 4 totaltotal 51.9% 53 / 102 CC 17 SCAR 21.7
CC
17
Cov
58%
_ext_attr
13.5
_ext_attr
13.5
BUILDARGS
7.5
CRAP 8.8
« blib/lib/Text/Nunjucks/Loader/FileSystem.pm ↑ Summary blib/lib/Text/Nunjucks/Template.pm »
1 package Text::Nunjucks::Nodes::CallExtension;
2 # ABSTRACT: AST node CallExtension (fields extName, prop, args, contentArgs), ported from nodes.js
3  
4 20 our $VERSION = '0.001';
5  
6 20 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use Text::Nunjucks::Nodes::NodeList;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 20 extends 'Text::Nunjucks::Nodes::Node';
12  
13 # upstream: Node.extend('CallExtension', { init, fields }) -- custom init,
14 # declared in nodes.js before CallExtensionAsync.
15  
16 20 has extName => ( is => 'rw' );
17 20 has prop => ( is => 'rw' );
18 20 has args => ( is => 'rw' );
19 20 has contentArgs => ( is => 'rw' );
20 20 has autoescape => ( is => 'rw' ); # carried from the extension; not a field
21  
22 24 ▶sub typename { 'CallExtension' }
Subroutine typename: called CC=1 SCAR=0.0
Pod undocumented
23 22 ▶sub fields { [ 'extName', 'prop', 'args', 'contentArgs' ] }
Subroutine fields: called CC=1 SCAR=0.0
Pod undocumented
24  
25 # init(ext, prop, args, contentArgs): note -- no lineno/colno. Upstream calls
26 # this.parent() first, which leaves lineno/colno undefined and then overwrites
27 # the four fields below, so the observable end state is exactly this hash.
28 # extName = ext.__name || ext ; autoescape = ext.autoescape
29 # How an extension is represented in Perl is not yet decided; extName and
30 # autoescape are read as an object method or a hash key, else the value passes
31 # through (mirroring `ext.__name || ext` for a bare string ext).
32 28 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=20.1
Pod undocumented
33 0 ▶ my ( $class, $ext, $prop, $args, $contentArgs ) = @_;
Subroutine BUILDARGS: not called CC=4 SCAR=20.1
Pod undocumented
34 return {
35 0 ▶ lineno => undef,
Condition37%6/16
_ext_attr($ext, '__name') || $ext
l!l&&r!l&&!r
16120
$args || $class->_node_class('NodeList')->new
l!l&&r!l&&!r
13150
$contentArgs || []
l!l
1513
_ext_attr($ext, '__name') || $ext
l!l&&r!l&&!r
000
$args || $class->_node_class('NodeList')->new
l!l&&r!l&&!r
000
$contentArgs || []
l!l
00
MC/DC0%0/2
_ext_attr($ext, '__name') || $ext
_ext_attr($ext, '__name') $ext
MC/DC0%0/2
$args || $class->_node_class('NodeList')->new
$args $class->_node_class('NodeList')->new
MC/DC100%1/1
$contentArgs || []
$contentArgs
MC/DC0%0/2
_ext_attr($ext, '__name') || $ext
_ext_attr($ext, '__name') $ext
MC/DC0%0/2
$args || $class->_node_class('NodeList')->new
$args $class->_node_class('NodeList')->new
MC/DC0%0/1
$contentArgs || []
$contentArgs
Truth table66%2/3
A || B
A= _ext_attr($ext, '__name')B= $ext
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $argsB= $class->_node_class('NodeList')->new
ABresult
1X1
011
000
Truth table100%2/2
A
A= $contentArgs
Aresult
11
00
Truth table0%0/3
A || B
A= _ext_attr($ext, '__name')B= $ext
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $argsB= $class->_node_class('NodeList')->new
ABresult
1X1
011
000
Truth table0%0/2
A
A= $contentArgs
Aresult
11
00
36 colno => undef,
37 extName => ( _ext_attr( $ext, '__name' ) || $ext ),
38 prop => $prop,
39 args => ( $args || $class->_node_class('NodeList')->new ),
40 contentArgs => ( $contentArgs || [] ),
41 autoescape => _ext_attr( $ext, 'autoescape' ),
42 };
43 }
44  
45 56 ▶sub _ext_attr {
Subroutine _ext_attr: called CC=6 SCAR=26.1
46 0 ▶ my ( $ext, $prop ) = @_;
Subroutine _ext_attr: not called CC=6 SCAR=26.1
47 0 ▶ return undef unless defined $ext && ref $ext;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $ext and ref $ext 4 52 56
unless defined $ext and ref $ext 0 0 0
Condition33%2/6
defined $ext and ref $ext
!ll&&!rl&&r
0452
defined $ext and ref $ext
!ll&&!rl&&r
000
MC/DC50%1/2
defined $ext and ref $ext
defined $ext ref $ext
MC/DC0%0/2
defined $ext and ref $ext
defined $ext ref $ext
Truth table66%2/3
A and B
A= defined $extB= ref $ext
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $extB= ref $ext
ABresult
0X0
100
111
48 0 ▶ return ( $ext->can($prop) ? $ext->$prop : undef ) if blessed $ext;
Branch: 4 branches
BranchTrueFalseTotal
if builtin::blessed($ext) 48 4 52
$ext->can($prop) ? : 28 20 48
if builtin::blessed($ext) 0 0 0
$ext->can($prop) ? : 0 0 0
49 0 ▶ return $ext->{$prop} if ref $ext eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $ext eq "HASH" 4 0 4
if ref $ext eq "HASH" 0 0 0
50 0 return undef;
51 }
52  
53 20 1;
54  
55 __END__
« blib/lib/Text/Nunjucks/Loader/FileSystem.pm ↑ Summary blib/lib/Text/Nunjucks/Template.pm »