File Coverage

blib/lib/DTL/Fast/Tag.pm
Criterion Covered Total %
statement 41 43 95.3
branch 4 4 100.0
condition 3 6 50.0
subroutine 13 14 92.8
pod 0 8 0.0
total 61 75 81.3


line stmt bran cond sub pod time code
1             package DTL::Fast::Tag;
2 36     36   11575 use strict;
  36         75  
  36         808  
3 36     36   150 use utf8;
  36         63  
  36         138  
4 36     36   745 use warnings FATAL => 'all';
  36         70  
  36         923  
5 36     36   152 use parent 'DTL::Fast::Parser';
  36         90  
  36         178  
6            
7 36     36   2114 use DTL::Fast;
  36         71  
  36         1255  
8 36     36   177 use DTL::Fast::Template;
  36         69  
  36         13296  
9            
10             sub new
11             {
12 843     843 0 2821 my ( $proto, $parameter, %kwargs ) = @_;
13 843   50     1890 $parameter //= '';
14            
15 843         3180 $parameter =~ s/^\s+|\s+$//gs;
16            
17 843         1585 $kwargs{parameter} = $parameter;
18            
19 843         2933 return $proto->SUPER::new(%kwargs);
20             }
21            
22 22     22 0 44 sub parse_parameters {return shift;}
23            
24             sub parse_chunks
25             {
26 843     843 0 1452 my ( $self ) = @_;
27 843         2417 $self->parse_parameters();
28            
29             $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $self->{_open_tag_lines}
30 828 100       1923 if ($self->{_open_tag_lines});
31            
32 828         2208 return $self->SUPER::parse_chunks();
33             }
34            
35             sub get_close_tag
36             {
37 0     0 0 0 my ( $self ) = @_;
38 0         0 die sprintf(
39             "ABSTRACT method get_close_tag, must be overriden in %s"
40             , ref $self
41             );
42             }
43            
44             # Close tag processor
45             sub parse_tag_chunk
46             {
47 946     946 0 1942 my ( $self, $tag_name, $tag_param, $chunk_lines ) = @_;
48            
49 946         1390 my $result = undef;
50            
51 946 100       2297 if ($tag_name eq $self->get_close_tag)
52             {
53 640         1206 $self->{raw_chunks} = [ ]; # this stops parsing
54 640         1003 $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines;
55             }
56             else
57             {
58 306         904 $result = $self->SUPER::parse_tag_chunk($tag_name, $tag_param, $chunk_lines);
59             }
60            
61 922         1928 return $result;
62             }
63            
64             # returns restored opening tag
65             sub open_tag_syntax
66             {
67 2     2 0 6 my ($self) = @_;
68            
69             return join( ' ',
70             grep(
71             $_
72             , (
73             '{%'
74             , $DTL::Fast::KNOWN_SLUGS{ref $self}
75             , $self->{parameter}
76 2         35 , '%}'
77             )
78             )
79             );
80             }
81            
82             # returns restored opening tag
83             sub open_tag_syntax_with_line_number
84             {
85 2     2 0 7 my ($self) = @_;
86 2   50     10 return $self->open_tag_syntax().' at line '.($self->{_template_line} // 'unknown');
87             }
88            
89             sub get_block_parse_error
90             {
91 1     1 0 4 my ($self, $message) = @_;
92             return $self->get_parse_error(
93             $message,
94             Block => sprintf(
95             '%s at line %s'
96             , ref $self
97 1   50     15 , $self->{_template_line} // 'unknown'
98             )
99             );
100             }
101            
102             1;