| 1 | package DTL::Fast::Entity; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 98 | ▶ | use strict; use utf8; use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | # prototype for template entity. Handling current line and current template references | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 98 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 98 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 8071 | ▶ | my( $proto, %kwargs ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8071 | ▶ | $proto = ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8071 | ▶ | $DTL::Fast::Template::CURRENT_TEMPLATE->{'modules'}->{$proto} = $proto->VERSION // DTL::Fast->VERSION; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$proto->VERSION // "DTL::Fast"->VERSION
MC/DC0%0/2
$proto->VERSION // "DTL::Fast"->VERSION
$proto->VERSION
"DTL::Fast"->VERSION
Truth table66%2/3
A // B
A= $proto->VERSIONB= "DTL::Fast"->VERSION
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8071 | my $self = bless {%kwargs}, $proto; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8071 | $self->remember_template; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8071 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub remember_template | ||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 7109 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remember_template: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7109 | $self->{'_template'} = $DTL::Fast::Template::CURRENT_TEMPLATE; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 7109 | $self->{'_template_line'} = $DTL::Fast::Template::CURRENT_TEMPLATE_LINE; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 7109 | weaken $self->{'_template'}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 7109 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | sub get_parse_error | ||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 18 | ▶ | my ($self, $message, @messages) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_parse_error: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | return $self->compile_error_message( | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 'Parsing error' => $message // 'undef' | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 18 | ▶ | , 'Template' => $DTL::Fast::Template::CURRENT_TEMPLATE->{'file_path'} | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$message // "undef"
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | , 'Line' => $DTL::Fast::Template::CURRENT_TEMPLATE_LINE | ||||||||||||||||||||||||||||||||||||||||||
| 42 | , @messages | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub get_parse_warning | ||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | ▶ | my ($self, $message, @messages) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_parse_warning: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | return $self->compile_error_message( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'Parsing warning' => $message // 'undef' | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | ▶ | , 'Template' => $DTL::Fast::Template::CURRENT_TEMPLATE->{'file_path'} | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$message // "undef"
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | , 'Line' => $DTL::Fast::Template::CURRENT_TEMPLATE_LINE | ||||||||||||||||||||||||||||||||||||||||||
| 54 | , @messages | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | sub get_render_error | ||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | my ($self, $context, $message, @messages) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_render_error: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | my @params = ( | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 'Rendering error' => $message // 'undef' | ||||||||||||||||||||||||||||||||||||||||||
| 64 | , 'Template' => $self->{'_template'}->{'file_path'} | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | , 'Line' => $self->{'_template_line'} | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$message // "undef"
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | , @messages | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 12 | ▶ | confess "No context passed for rendering error generator." unless $context; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
exists $context->{"ns"}[-1]{"_dtl_include_path"} and ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY" and scalar @{$context->{"ns"}[-1]{"_dtl_include_path"};} > 1
exists $context->{"ns"}[-1]{"_dtl_include_path"} and ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY"
MC/DC33%1/3
exists $context->{"ns"}[-1]{"_dtl_include_path"} and ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY" and scalar @{$context->{"ns"}[-1]{"_dtl_include_path"};} > 1
exists $context->{"ns"}[-1]{"_dtl_include_path"}
ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY"
scalar @{$context->{"ns"}[-1]{"_dtl_include_path"};} > 1
Truth table50%2/4
A and B and C
A= exists $context->{"ns"}[-1]{"_dtl_include_path"}B= ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY"C= scalar @{$context->{"ns"}[-1]{"_dtl_include_path"};} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | exists $context->{'ns'}->[-1]->{'_dtl_include_path'} | ||||||||||||||||||||||||||||||||||||||||||
| 73 | and ref $context->{'ns'}->[-1]->{'_dtl_include_path'} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | and scalar @{$context->{'ns'}->[-1]->{'_dtl_include_path'}} > 1 | |||||||||||||||||||||||||||||||||||||||||
| 75 | ) # has inclusions, appending stack trace | ||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | push @params, 'Stack trace' => join( "\n", reverse @{$context->{'ns'}->[-1]->{'_dtl_include_path'}}); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | return $self->compile_error_message( @params ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # format error message from key=>val pair | ||||||||||||||||||||||||||||||||||||||||||
| 84 | sub compile_error_message | ||||||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 42 | ▶ | my ($self, @messages) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_error_message: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 42 | ▶ | die 'Odd parameters in messages array' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | if scalar(@messages) % 2; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # calculating max padding | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 42 | my $padding = 0; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 42 | ▶ | for( my $i = 0; $i < scalar @messages; $i += 2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 151 | my $length = length $messages[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 151 | ▶ | $padding = $length if $length > $padding; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 42 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 42 | ▶ | while ( scalar @messages ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 151 | ▶ | my $key = shift @messages // 'undef'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @messages // "undef"
MC/DC0%0/1
shift @messages // "undef"
shift @messages
Truth table50%1/2
A
A= shift @messages
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 151 | ▶ | my $value = shift @messages // 'undef'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @messages // "undef"
MC/DC0%0/1
shift @messages // "undef"
shift @messages
Truth table50%1/2
A
A= shift @messages
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 151 | chomp($value); | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 151 | my $key_length = length $key; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 151 | $result .= sprintf | |||||||||||||||||||||||||||||||||||||||||
| 110 | '%s%s: ' | ||||||||||||||||||||||||||||||||||||||||||
| 111 | , ' ' x ($padding - $key_length) | ||||||||||||||||||||||||||||||||||||||||||
| 112 | , $key; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 151 | my @value = split /\n+/, $value; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 151 | $result .= shift @value; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 151 | $result .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 151 | foreach my $value (@value) | |||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 38 | $result .= (' ' x ($padding + 2)).$value."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 42 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 98 | 1; | |||||||||||||||||||||||||||||||||||||||||