| 1 | package Text::Nunjucks::Lib::TemplateError; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Nunjucks TemplateError (src/lib.js) -- name is always 'Template render error' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 23 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 23 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 23 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # 1:1 port of the TemplateError constructor / Update method in src/lib.js. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # JS constructor is positional -- new TemplateError(message, lineno, colno) -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # and 'message' may itself be an Error, in which case it becomes the cause and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # the message turns into "${cause.name}: ${cause.message}". BUILDARGS mirrors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # that. Object.setPrototypeOf / Error.captureStackTrace / the stack + cause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # getters are JS-runtime plumbing with no Perl analogue and are not ported. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | has message => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 774 | ▶ | has name => ( is => 'ro', init_arg => undef, default => sub { 'Template render error' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | has lineno => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | has colno => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | has cause => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 774 | ▶ | has first_update => ( is => 'rw', default => sub { 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 774 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 774 | my ( $orig, $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 774 | ▶ | return $class->$orig(@args) if @args == 1 && ref $args[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 774 | my ( $message, $lineno, $colno ) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 774 | my %attrs = ( lineno => $lineno, colno => $colno ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # if (message instanceof Error) -- a caught error object we are wrapping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 774 | ▶ | if ( blessed($message) && $message->can('name') && $message->can('message') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($message) and $message->can("name") and $message->can("message")
builtin::blessed($message) and $message->can("name")
MC/DC33%1/3
builtin::blessed($message) and $message->can("name") and $message->can("message")
builtin::blessed($message)
$message->can("name")
$message->can("message")
Truth table50%2/4
A and B and C
A= builtin::blessed($message)B= $message->can("name")C= $message->can("message")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 697 | $attrs{cause} = $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 697 | $attrs{message} = $message->name . ': ' . $message->message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 77 | $attrs{message} = $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 774 | return $class->$orig(%attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 23 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # err.Update(path) -- prepend the template path and, on the first update only, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # the line/column of the originating template. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 716 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=9 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=9 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # JS: '(' + (path || 'unknown path') + ')' -- '' is falsy in JS too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $msg = '(' . ( ( defined $path && length $path ) ? $path : 'unknown path' ) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $path and length $path
defined $path and length $path
MC/DC50%1/2
defined $path and length $path
defined $path
length $path
MC/DC0%0/2
defined $path and length $path
defined $path
length $path
Truth table66%2/3
A and B
A= defined $pathB= length $path
Truth table0%0/3
A and B
A= defined $pathB= length $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # only show lineno + colno next to path of template where error occurred | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $self->first_update ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( $self->lineno && $self->colno ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%2/6
$self->lineno and $self->colno
$self->lineno and $self->colno
MC/DC50%1/2
$self->lineno and $self->colno
$self->lineno
$self->colno
MC/DC0%0/2
$self->lineno and $self->colno
$self->lineno
$self->colno
Truth table66%2/3
A and B
A= $self->linenoB= $self->colno
Truth table0%0/3
A and B
A= $self->linenoB= $self->colno
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $msg .= ' [Line ' . $self->lineno . ', Column ' . $self->colno . ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ( $self->lineno ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $msg .= ' [Line ' . $self->lineno . ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $msg .= "\n "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( $self->first_update ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $msg .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->message( $msg . ( $self->message // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$self->message // ""
$self->message // ""
MC/DC0%0/1
$self->message // ""
$self->message
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->message
Truth table0%0/2
A
A= $self->message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->first_update(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||