| 1 | package DTL::Fast::Parser; | ||||||||||||||||||||||||||||
| 2 | 98 | ▶ | use strict; use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 98 | ▶ | use parent 'DTL::Fast::Renderer'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 98 | ▶ | use DTL::Fast::Expression; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 98 | ▶ | use DTL::Fast::Text; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 98 | ▶ | use DTL::Fast::Template; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 98 | ▶ | use DTL::Fast qw(count_lines); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub new | ||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||
| 12 | 1805 | ▶ | my( $proto, %kwargs ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | die $proto->get_parse_error('no directory arrays passed into constructor') | ||||||||||||||||||||||||||||
| 15 | if not $kwargs{'dirs'} | ||||||||||||||||||||||||||||
| 16 | 1805 | ▶ | or ref $kwargs{'dirs'} ne 'ARRAY' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $kwargs{"dirs"} or ref $kwargs{"dirs"} ne "ARRAY"
MC/DC0%0/2
not $kwargs{"dirs"} or ref $kwargs{"dirs"} ne "ARRAY"
not $kwargs{"dirs"}
ref $kwargs{"dirs"} ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $kwargs{"dirs"}B= ref $kwargs{"dirs"} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 17 | ; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | die $proto->get_parse_error('no raw chunks array passed into constructor') | ||||||||||||||||||||||||||||
| 20 | if not $kwargs{'raw_chunks'} | ||||||||||||||||||||||||||||
| 21 | 1805 | ▶ | or ref $kwargs{'raw_chunks'} ne 'ARRAY' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $kwargs{"raw_chunks"} or ref $kwargs{"raw_chunks"} ne "ARRAY"
MC/DC0%0/2
not $kwargs{"raw_chunks"} or ref $kwargs{"raw_chunks"} ne "ARRAY"
not $kwargs{"raw_chunks"}
ref $kwargs{"raw_chunks"} ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $kwargs{"raw_chunks"}B= ref $kwargs{"raw_chunks"} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 22 | ; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1805 | ▶ | $kwargs{'safe'} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$kwargs{"safe"} //= 0
MC/DC0%0/1
$kwargs{"safe"} //= 0
$kwargs{"safe"}
Truth table50%1/2
A
A= $kwargs{"safe"}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1805 | my $self = $proto->SUPER::new(%kwargs)->parse_chunks();; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1749 | delete @{$self}{'raw_chunks'}; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1749 | return $self; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub parse_chunks | ||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 1790 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_chunks: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 1790 | ▶ | while( scalar @{$self->{'raw_chunks'}} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 6711 | $self->add_chunk( $self->parse_next_chunk()); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 1749 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub parse_next_chunk | ||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 6501 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_next_chunk: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6501 | my $chunk = shift @{$self->{'raw_chunks'}}; | |||||||||||||||||||||||||||
| 48 | 6501 | my $chunk_lines = count_lines($chunk); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 6501 | ▶ | if( | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 51 | $chunk =~ /^ | ||||||||||||||||||||||||||||
| 52 | \{\{\s* # open sequence | ||||||||||||||||||||||||||||
| 53 | ([^\s].*?) # variable name or value $1 | ||||||||||||||||||||||||||||
| 54 | \s*\}\} # close sequence | ||||||||||||||||||||||||||||
| 55 | $/xs | ||||||||||||||||||||||||||||
| 56 | ) | ||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 638 | ▶ | if( $1 eq 'block.super' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 1 | require DTL::Fast::Tag::BlockSuper; | |||||||||||||||||||||||||||
| 61 | $chunk = DTL::Fast::Tag::BlockSuper->new( | ||||||||||||||||||||||||||||
| 62 | '' | ||||||||||||||||||||||||||||
| 63 | 1 | , 'dirs' => $self->{'dirs'} | |||||||||||||||||||||||||||
| 64 | , '_open_tag_lines' => $chunk_lines | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else | ||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 637 | $chunk = DTL::Fast::Variable->new($1); | |||||||||||||||||||||||||||
| 70 | 637 | $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | elsif | ||||||||||||||||||||||||||||
| 74 | ( | ||||||||||||||||||||||||||||
| 75 | $chunk =~ /^ | ||||||||||||||||||||||||||||
| 76 | \{\%\s* # open sequence | ||||||||||||||||||||||||||||
| 77 | ([^\s]+?) # tag keyword $1 | ||||||||||||||||||||||||||||
| 78 | (?: | ||||||||||||||||||||||||||||
| 79 | \s+ # spaces | ||||||||||||||||||||||||||||
| 80 | (.*?) # parameters $2 | ||||||||||||||||||||||||||||
| 81 | )? | ||||||||||||||||||||||||||||
| 82 | \s*\%\} # close sequence | ||||||||||||||||||||||||||||
| 83 | $/xs | ||||||||||||||||||||||||||||
| 84 | ) | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 2423 | $chunk = $self->parse_tag_chunk(lc $1, $2, $chunk_lines); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | elsif | ||||||||||||||||||||||||||||
| 89 | ( | ||||||||||||||||||||||||||||
| 90 | $chunk =~ /^\{\#.*\#\}$/s | ||||||||||||||||||||||||||||
| 91 | ) | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 2 | $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines; | |||||||||||||||||||||||||||
| 94 | 2 | $chunk = undef; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | elsif( $chunk ne '' ) | ||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 2364 | $chunk = DTL::Fast::Text->new( $chunk); | |||||||||||||||||||||||||||
| 99 | 2364 | $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else | ||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 1074 | $chunk = undef; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 6460 | return $chunk; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub parse_tag_chunk | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 849 | ▶ | my( $self, $tag_name, $tag_param, $chunk_lines ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_tag_chunk: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 849 | my $result = undef; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # dynamic module loading | ||||||||||||||||||||||||||||
| 116 | 849 | ▶ | if( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $DTL::Fast::TAG_HANDLERS{$tag_name} and exists $DTL::Fast::KNOWN_TAGS{$tag_name}
MC/DC100%2/2
not exists $DTL::Fast::TAG_HANDLERS{$tag_name} and exists $DTL::Fast::KNOWN_TAGS{$tag_name}
not exists $DTL::Fast::TAG_HANDLERS{$tag_name}
exists $DTL::Fast::KNOWN_TAGS{$tag_name}
Truth table100%3/3
not(A) and B
A= not exists $DTL::Fast::TAG_HANDLERS{$tag_name}B= exists $DTL::Fast::KNOWN_TAGS{$tag_name}
| |||||||||||||||||||||||||||||
| 117 | not exists $DTL::Fast::TAG_HANDLERS{$tag_name} | ||||||||||||||||||||||||||||
| 118 | and exists $DTL::Fast::KNOWN_TAGS{$tag_name} | ||||||||||||||||||||||||||||
| 119 | ) | ||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 53 | require Module::Load; | |||||||||||||||||||||||||||
| 122 | 53 | Module::Load::load($DTL::Fast::KNOWN_TAGS{$tag_name}); | |||||||||||||||||||||||||||
| 123 | 53 | $DTL::Fast::LOADED_MODULES{$DTL::Fast::KNOWN_TAGS{$tag_name}} = time; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # handling tag | ||||||||||||||||||||||||||||
| 127 | 849 | ▶ | if( exists $DTL::Fast::TAG_HANDLERS{$tag_name} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||
| 129 | $result = $DTL::Fast::TAG_HANDLERS{$tag_name}->new( | ||||||||||||||||||||||||||||
| 130 | $tag_param | ||||||||||||||||||||||||||||
| 131 | , 'raw_chunks' => $self->{'raw_chunks'} | ||||||||||||||||||||||||||||
| 132 | 843 | , 'dirs' => $self->{'dirs'} | |||||||||||||||||||||||||||
| 133 | , '_open_tag_lines' => $chunk_lines | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | else # not found | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | 6 | my $full_tag_name = join ' ', grep $_, ($tag_name, $tag_param); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 6 | ▶ | if ( # block tag parsing error | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->isa("DTL::Fast::Tag") and not $self->isa("DTL::Fast::Tag::Simple")
MC/DC50%1/2
$self->isa("DTL::Fast::Tag") and not $self->isa("DTL::Fast::Tag::Simple")
$self->isa("DTL::Fast::Tag")
not $self->isa("DTL::Fast::Tag::Simple")
Truth table66%2/3
A and not(B)
A= $self->isa("DTL::Fast::Tag")B= not $self->isa("DTL::Fast::Tag::Simple")
| |||||||||||||||||||||||||||||
| 141 | $self->isa('DTL::Fast::Tag') | ||||||||||||||||||||||||||||
| 142 | and not $self->isa('DTL::Fast::Tag::Simple') | ||||||||||||||||||||||||||||
| 143 | ) | ||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 2 | ▶ | warn $self->get_parse_warning( | ||||||||||||||||||||||||||
|
Condition50%2/4
$tag_name // "undef"
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE // "unknown"
MC/DC0%0/1
$tag_name // "undef"
$tag_name
MC/DC0%0/1
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE // "unknown"
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE
Truth table50%1/2
A
A= $tag_name
Truth table50%1/2
A
A= $DTL::Fast::Template::CURRENT_TEMPLATE_LINE
| |||||||||||||||||||||||||||||
| 146 | sprintf( 'unknown tag {%% %s %%}', $full_tag_name ) | ||||||||||||||||||||||||||||
| 147 | , 'Possible reasons' => sprintf( <<'_EOM_' | ||||||||||||||||||||||||||||
| 148 | typo in tag name | ||||||||||||||||||||||||||||
| 149 | duplicated close tag {%% %1$s %%} | ||||||||||||||||||||||||||||
| 150 | unopened close tag {%% %1$s %%} | ||||||||||||||||||||||||||||
| 151 | undisclosed block tag %3$s | ||||||||||||||||||||||||||||
| 152 | _EOM_ | ||||||||||||||||||||||||||||
| 153 | , $tag_name // 'undef' | ||||||||||||||||||||||||||||
| 154 | , $DTL::Fast::Template::CURRENT_TEMPLATE_LINE // 'unknown' | ||||||||||||||||||||||||||||
| 155 | , $self->open_tag_syntax_with_line_number() | ||||||||||||||||||||||||||||
| 156 | ) | ||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | else # template parsing error | ||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||
| 161 | 4 | ▶ | warn $self->get_parse_warning( | ||||||||||||||||||||||||||
|
Condition50%2/4
$tag_name // "undef"
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE // "unknown"
MC/DC0%0/1
$tag_name // "undef"
$tag_name
MC/DC0%0/1
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE // "unknown"
$DTL::Fast::Template::CURRENT_TEMPLATE_LINE
Truth table50%1/2
A
A= $tag_name
Truth table50%1/2
A
A= $DTL::Fast::Template::CURRENT_TEMPLATE_LINE
| |||||||||||||||||||||||||||||
| 162 | sprintf( 'unknown tag {%% %s %%}', $full_tag_name ) | ||||||||||||||||||||||||||||
| 163 | , 'Possible reasons' => sprintf( <<'_EOM_' | ||||||||||||||||||||||||||||
| 164 | typo, duplicated or unopened close tag {%% %1$s %%} at line %2$s | ||||||||||||||||||||||||||||
| 165 | _EOM_ | ||||||||||||||||||||||||||||
| 166 | , $tag_name // 'undef' | ||||||||||||||||||||||||||||
| 167 | , $DTL::Fast::Template::CURRENT_TEMPLATE_LINE // 'unknown' | ||||||||||||||||||||||||||||
| 168 | ) | ||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 6 | $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 6 | $result = DTL::Fast::Text->new(); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 809 | return $result; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 98 | 1; | |||||||||||||||||||||||||||