blib/lib/DTL/Fast/Entity.pm

filter: Statementstmt 100% 58 / 58 Branchbran 83.3% 10 / 12 Conditioncond 50.0% 11 / 22 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 6 totaltotal 75.2% 91 / 121 SCAR 28.8
CC
17
Cov
86%
compile_error_message
8.1
get_render_error
6.6
new
3.1
CRAP 17.8
« blib/lib/DTL/Fast/Template.pm ↑ Summary blib/lib/DTL/Fast/Tag/Url.pm »
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
l!l&&r!l&&!r
080710
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
13
14 8071 ▶ $DTL::Fast::Template::CURRENT_TEMPLATE->{'modules'}->{$proto} = $proto->VERSION // DTL::Fast->VERSION;
Condition66%2/3
$proto->VERSION // "DTL::Fast"->VERSION
l!l&&r!l&&!r
2680450
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
ABresult
1X1
011
000
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"
l!l
180
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
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"
l!l
120
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
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"
l!l
120
MC/DC0%0/1
$message // "undef"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
66 , @messages
67 );
68
69 12 ▶ confess "No context passed for rendering error generator." unless $context;
Branch: 1 branch
BranchTrueFalseTotal
unless $context 0 12 12
70
71 12 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (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) 2 10 12
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
!ll&&!rl&&r
0102
exists $context->{"ns"}[-1]{"_dtl_include_path"} and ref $context->{"ns"}[-1]{"_dtl_include_path"} eq "ARRAY"
!ll&&!rl&&r
0012
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if scalar(@messages) % 2 0 42 42
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
BranchTrueFalseTotal
if ($i < scalar @messages) 151 42 193
94 {
95 151 my $length = length $messages[$i];
96 151 ▶ $padding = $length if $length > $padding;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $padding 55 96 151
97 }
98
99 42 my $result = '';
100 42 ▶ while ( scalar @messages )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @messages) 151 42 193
101 {
102 151 ▶ my $key = shift @messages // 'undef';
Condition50%1/2
shift @messages // "undef"
l!l
1510
MC/DC0%0/1
shift @messages // "undef"
shift @messages
Truth table50%1/2
A
A= shift @messages
Aresult
11
00
103 151 ▶ my $value = shift @messages // 'undef';
Condition50%1/2
shift @messages // "undef"
l!l
1510
MC/DC0%0/1
shift @messages // "undef"
shift @messages
Truth table50%1/2
A
A= shift @messages
Aresult
11
00
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;
« blib/lib/DTL/Fast/Template.pm ↑ Summary blib/lib/DTL/Fast/Tag/Url.pm »