« 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
Condition66%2/3
$path ne $base and index($path, $base . '/') != 0
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | 649 | return { src => decode_utf8_lossy($bytes), path => $path, noCache => !!1 }; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 61 | 1; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | __END__ | ||||||||||||||||||||||||||||