blib/lib/Text/Nunjucks/Loader.pm

filter: Statementstmt 83.3% 20 / 24 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 75.4% 40 / 53 CC 5 SCAR 8.6
CC
5
Cov
74%
is_relative
4.1
is_relative
4.1
resolve
1.1
CRAP 2.4
« blib/lib/Text/Nunjucks/Tests.pm ↑ Summary blib/lib/Text/Nunjucks/Lib/Error.pm »
1 package Text::Nunjucks::Loader;
2 # ABSTRACT: 1:1 port of Nunjucks src/loader.js -- the base Loader (resolve/isRelative)
3  
4 15 our $VERSION = '0.001';
5  
6 15 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 with 'Text::Nunjucks::EmitterObj';
8 15 ▶use Text::Nunjucks::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # src/loader.js: `module.exports = class Loader extends EmitterObj { resolve;
12 # isRelative }`. EmitterObj -> the on/emit role (ADR 0002). The concrete
13 # loaders extend it in their own modules: src/node-loaders.js's FileSystemLoader
14 # is Text::Nunjucks::Loader::FileSystem, src/precompiled-loader.js's
15 # PrecompiledLoader is Text::Nunjucks::Loader::Precompiled (ADR 0018).
16 #
17 # `cache` is not declared by loader.js -- Environment attaches `loader.cache = {}`
18 # in _initLoaders. Declaring it here (with the same empty-hash default) gives the
19 # Environment a clean accessor to reach for instead of poking the object's guts.
20 5150 ▶has cache => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
21  
22 # loaders opt into async by setting `loader.async = true`; the base is sync.
23 # Environment reads `loader.async`, so the base answers it (falsey).
24 4291 ▶sub async { return }
Subroutine async: called CC=1 SCAR=0.0
Pod documented
25  
26 8 ▶sub _lib { 'Text::Nunjucks::Lib' }
Subroutine _lib: called CC=1 SCAR=0.0
27  
28 # resolve(from, to) -- path.resolve(path.dirname(from), to), through node's own
29 # path functions in Lib (ADR 0018): lexical, so '..' collapses on the string
30 # and the file system is never asked (from 'views/sub/page.njk', '../d.njk' is
31 # '<cwd>/views/d.njk'), anchored at the working directory only when `from` is
32 # relative. Environment.resolveTemplate calls it for a relative name, and the
33 # result is both the loader's cache key and the name getSource receives.
34 105 ▶sub resolve {
Subroutine resolve: called CC=1 SCAR=1.2
Pod documented
35 0 ▶ my ( $self, $from, $to ) = @_;
Subroutine resolve: not called CC=1 SCAR=1.2
Pod documented
36 0 return $self->_lib->node_path_resolve( $self->_lib->node_path_dirname($from), $to );
37 }
38  
39 # isRelative(filename) -- a name starting './' or '../'.
40 10931 ▶sub is_relative {
Subroutine is_relative: called CC=3 SCAR=14.2
Pod documented
41 0 ▶ my ( $self, $filename ) = @_;
Subroutine is_relative: not called CC=3 SCAR=14.2
Pod documented
42 0 ▶ return ( index( $filename, './' ) == 0 || index( $filename, '../' ) == 0 ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
index($filename, './') == 0 || index($filename, '../') == 0 ? : 103 10828 10931
index($filename, './') == 0 || index($filename, '../') == 0 ? : 0 0 0
Condition50%3/6
index($filename, "./") == 0 or index($filename, "../") == 0
l!l&&r!l&&!r
525110828
index($filename, "./") == 0 or index($filename, "../") == 0
l!l&&r!l&&!r
000
MC/DC100%2/2
index($filename, "./") == 0 or index($filename, "../") == 0
index($filename, "./") == 0 index($filename, "../") == 0
MC/DC0%0/2
index($filename, "./") == 0 or index($filename, "../") == 0
index($filename, "./") == 0 index($filename, "../") == 0
Truth table100%3/3
A or B
A= index($filename, "./") == 0B= index($filename, "../") == 0
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= index($filename, "./") == 0B= index($filename, "../") == 0
ABresult
1X1
011
000
43 }
44  
45 15 1;
46  
47 __END__
« blib/lib/Text/Nunjucks/Tests.pm ↑ Summary blib/lib/Text/Nunjucks/Lib/Error.pm »