blib/lib/Skilletor/Render/Loader.pm

filter: Statementstmt 100% 28 / 28 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 93.4% 43 / 46 CC 4 SCAR 8.0
CC
4
Cov
94%
get_source
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« lib/Skilletor/JSON/OrderedHash.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/Package/Stash.pm »
1 package Skilletor::Render::Loader;
2 # ABSTRACT: A Nunjucks loader confined to an item's source root – the reference's makeLoader
3  
4 61 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 61 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 61 ▶use Skilletor::Error::Render;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 61 ▶use Skilletor::FSUtil qw( decode_utf8_lossy encode_text path_resolve );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 61 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 61 extends 'Text::Nunjucks::Loader';
11  
12 61 our $VERSION = '0.008000';
13  
14 61 has root => (
15 is => 'ro',
16 required => 1,
17 );
18  
19 # The reference's loader has no isRelative, so Nunjucks never resolves a name against the
20 # template that includes it: `./x.md` and `../x.md` are relative to the source root as well.
21 246 ▶sub is_relative { 0 }
Subroutine is_relative: called CC=1 SCAR=0.0
Pod documented
22  
23 690 ▶sub get_source {
Subroutine get_source: called CC=4 SCAR=14.0
Pod documented
24 690 my ( $self, $name ) = @_;
25 690 my $base = path_resolve( $self->root );
26 690 my $path = path_resolve( $base, $name );
27 690 ▶ Skilletor::Error::Render->throw( 'template escapes source root: '.$name ) if $path ne $base && index( $path, $base.'/' ) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $path ne $base and index($path, $base . '/') != 0 41 649 690
Condition66%2/3
$path ne $base and index($path, $base . '/') != 0
!ll&&!rl&&r
064941
MC/DC50%1/2
$path ne $base and index($path, $base . '/') != 0
$path ne $base index($path, $base . '/') != 0
Truth table66%2/3
A and B
A= $path ne $baseB= index($path, $base . '/') != 0
ABresult
0X0
100
111
28 # readFileSync(path, "utf8"): whatever cannot be read (missing, a directory) is no template.
29 649 my $bytes = eval { path( encode_text($path) )->slurp_raw };
30 649 ▶ return undef unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 649 649
31 649 return { src => decode_utf8_lossy($bytes), path => $path, noCache => !!1 };
32 }
33  
34 61 1;
35  
36 __END__
« lib/Skilletor/JSON/OrderedHash.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/Package/Stash.pm »