blib/lib/Text/Nunjucks/Loader/Precompiled.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 4 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 90.9% 40 / 44 CC 4 SCAR 5.9
CC
4
Cov
97%
BUILD
3.0
get_source
2.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Text/Nunjucks/Nodes/FromImport.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/SafeString.pm »
1 package Text::Nunjucks::Loader::Precompiled;
2 # ABSTRACT: 1:1 port of Nunjucks src/precompiled-loader.js -- templates from precompiled code objects
3  
4 1 our $VERSION = '0.001';
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Text::Nunjucks::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 extends 'Text::Nunjucks::Loader';
11  
12 # src/precompiled-loader.js: a Loader over a bag of precompiled templates, name
13 # -> the object a precompiled template evaluates to ({ root, b_<block>, ... }:
14 # in the port the hashref of coderefs the compiled Perl source returns, which
15 # Template takes as { type => 'code', obj => ... }). constructor(compiledTemplates)
16 # sets this.precompiled; BUILDARGS keeps the positional argument, BUILD is the
17 # body (super() is Moo's), as in Text::Nunjucks::Loader::FileSystem.
18  
19 1 has precompiled => ( is => 'rw' );
20 1 has _init_args => ( is => 'ro' );
21  
22 11 ▶sub _runtime { 'Text::Nunjucks::Runtime' }
Subroutine _runtime: called CC=1 SCAR=0.0
23  
24 # new PrecompiledLoader(compiledTemplates) -- positional.
25 5 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
26 5 my ( $class, @args ) = @_;
27 5 return { _init_args => [@args] };
28 }
29  
30 # constructor(compiledTemplates)
31 5 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
32 5 my ($self) = @_;
33 5 ▶ my ($compiled_templates) = @{ $self->_init_args // [] };
Condition50%1/2
$self->_init_args // []
l!l
50
MC/DC0%0/1
$self->_init_args // []
$self->_init_args
Truth table50%1/2
A
A= $self->_init_args
Aresult
11
00
34 5 delete $self->{_init_args};
35 5 ▶ $self->precompiled( $self->_runtime->_truthy($compiled_templates) ? $compiled_templates : {} );
Branch: 1 branch
BranchTrueFalseTotal
$self->_runtime->_truthy($compiled_templates) ? : 4 1 5
36 }
37  
38 # this.precompiled[name] is a JS property read on whatever the constructor
39 # kept -- a hash, but also a string or a number, where JS reads a character
40 # or undefined (node: new PrecompiledLoader('abc').getSource('0') has obj 'a',
41 # a number finds nothing) -- so it goes through Runtime's js_member_read.
42 6 ▶sub get_source {
Subroutine get_source: called CC=2 SCAR=6.9
Pod documented
43 6 my ( $self, $name ) = @_;
44 6 my $rt = $self->_runtime;
45 6 ▶ if ( $rt->_truthy( $rt->js_member_read( $self->precompiled, $name ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->_truthy($rt->js_member_read($self->precompiled, $name))) 3 3 6
46 return {
47 3 src => {
48 type => 'code',
49 obj => $rt->js_member_read( $self->precompiled, $name ),
50 },
51 path => $name,
52 };
53 }
54 3 return undef;
55 }
56  
57 1 1;
58  
59 __END__
« blib/lib/Text/Nunjucks/Nodes/FromImport.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/SafeString.pm »