blib/lib/Text/Nunjucks/Lib/TemplateError.pm

filter: Statementstmt 75.4% 40 / 53 Branchbran 50.0% 12 / 24 Conditioncond 44.0% 11 / 25 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 59.0% 75 / 127 CC 22 SCAR 28.3
CC
22
Cov
62%
update
25.1
update
25.1
__ANON__
6.2
CRAP 17.0
« blib/lib/Text/Nunjucks/Runtime.pm ↑ Summary blib/lib/Text/Nunjucks/Transformer.pm »
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
BranchTrueFalseTotal
if @args == 1 and ref $args[0] eq "HASH" 0 774 774
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
4972770
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (builtin::blessed($message) and $message->can('name') and $message->can('message')) { } 697 77 774
Condition66%4/6
builtin::blessed($message) and $message->can("name") and $message->can("message")
!ll&&!rl&&r
770697
builtin::blessed($message) and $message->can("name")
!ll&&!rl&&r
770697
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")
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
defined $path && length $path ? : 288 428 716
defined $path && length $path ? : 0 0 0
Condition33%2/6
defined $path and length $path
!ll&&!rl&&r
4280288
defined $path and length $path
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
49  
50 # only show lineno + colno next to path of template where error occurred
51 0 ▶ if ( $self->first_update ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->first_update) 715 1 716
if ($self->first_update) 0 0 0
52 0 ▶ if ( $self->lineno && $self->colno ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->lineno and $self->colno) { } 18 697 715
elsif ($self->lineno) { } 0 697 697
if ($self->lineno and $self->colno) { } 0 0 0
elsif ($self->lineno) { } 0 0 0
Condition33%2/6
$self->lineno and $self->colno
!ll&&!rl&&r
697018
$self->lineno and $self->colno
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->linenoB= $self->colno
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->first_update) 715 1 716
if ($self->first_update) 0 0 0
61 0 $msg .= ' ';
62 }
63  
64 0 ▶ $self->message( $msg . ( $self->message // '' ) );
Condition25%1/4
$self->message // ""
l!l
7160
$self->message // ""
l!l
00
MC/DC0%0/1
$self->message // ""
$self->message
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->message
Aresult
11
00
Truth table0%0/2
A
A= $self->message
Aresult
11
00
65 0 $self->first_update(0);
66 0 return $self;
67 }
68  
69 23 1;
70  
71 __END__
« blib/lib/Text/Nunjucks/Runtime.pm ↑ Summary blib/lib/Text/Nunjucks/Transformer.pm »