| 1 | package DTL::Fast::Tag::Ifchanged; | ||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | 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 | 2 | ▶ | use parent 'DTL::Fast::Tag'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 2 | $DTL::Fast::TAG_HANDLERS{'ifchanged'} = __PACKAGE__; | |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use DTL::Fast::Expression::Operator::Binary::Eq; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | #@Override | ||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | sub get_close_tag{ return 'endifchanged'; } | ||||||||||||||||||||||||||||||
|
Subroutine
get_close_tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | #@Override | ||||||||||||||||||||||||||||||||
| 13 | sub parse_parameters | ||||||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
parse_parameters: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 8 | $self->add_branch(); | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | if ( $self->{'parameter'}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||
| 21 | 5 | $self->{'watches'} = $self->parse_sources($self->{'parameter'}); | |||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | else | ||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||
| 25 | 3 | $self->{'watch_content'} = 1; | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 8 | return $self; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | #@Override | ||||||||||||||||||||||||||||||||
| 33 | sub add_chunk | ||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||
| 35 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
add_chunk: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 36 | 34 | my $chunk = shift; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 34 | $self->{'branches'}->[-1]->add_chunk($chunk); | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 34 | return $self; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | #@Override | ||||||||||||||||||||||||||||||||
| 44 | sub parse_tag_chunk | ||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||
| 46 | 12 | ▶ | my( $self, $tag_name, $tag_param, $chunk_lines ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
parse_tag_chunk: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 12 | my $result = undef; | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 12 | ▶ | if( $tag_name eq 'else' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||
| 52 | 4 | $self->add_branch(); | |||||||||||||||||||||||||||||||
| 53 | 4 | $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | else | ||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||
| 57 | 8 | $result = $self->SUPER::parse_tag_chunk($tag_name, $tag_param, $chunk_lines); | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 12 | return $result; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | #@Override | ||||||||||||||||||||||||||||||||
| 64 | sub render | ||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||
| 66 | 71 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 67 | 71 | my $context = shift; | |||||||||||||||||||||||||||||||
| 68 | 71 | my $result = ''; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 71 | my $forloop = $context->{'ns'}->[-1]->{'forloop'}; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 71 | ▶ | if( defined $forloop ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||
| 74 | 71 | ▶ | if( $self->{'watch_content'} ) # slow behavior | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||
| 76 | 27 | $result = $self->{'branches'}->[0]->render($context); | |||||||||||||||||||||||||||||||
| 77 | 27 | ▶ | if( | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$forloop->{"first"} or $result ne $self->{"last_iteration_content"}
MC/DC100%2/2
$forloop->{"first"} or $result ne $self->{"last_iteration_content"}
$forloop->{"first"}
$result ne $self->{"last_iteration_content"}
Truth table100%3/3
A or B
A= $forloop->{"first"}B= $result ne $self->{"last_iteration_content"}
| |||||||||||||||||||||||||||||||||
| 78 | $forloop->{'first'} # first pass | ||||||||||||||||||||||||||||||||
| 79 | or $result ne $self->{'last_iteration_content'} # content changed | ||||||||||||||||||||||||||||||||
| 80 | ) | ||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||
| 82 | 9 | $self->{'last_iteration_content'} = $result; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | 18 | elsif( scalar @{$self->{'branches'}} > 1 ) | |||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||
| 86 | 9 | $result = $self->{'branches'}->[1]->render($context); | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | else | ||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||
| 90 | 9 | $result = ''; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | else | ||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||
| 95 | 44 | ▶ | if( $forloop->{'first'} ) # first pass | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||
| 97 | 5 | $self->update_preserved($context); | |||||||||||||||||||||||||||||||
| 98 | 5 | $result = $self->{'branches'}->[0]->render($context); | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | else | ||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||
| 102 | 39 | ▶ | if( $self->watches_changed($context) ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||
| 104 | 14 | $result = $self->{'branches'}->[0]->render($context); | |||||||||||||||||||||||||||||||
| 105 | 14 | $self->update_preserved($context); | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | 25 | elsif( scalar @{$self->{'branches'}} > 1 ) | |||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||
| 109 | 9 | $result = $self->{'branches'}->[1]->render($context); | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | else | ||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||
| 116 | 0 | warn "ifchanged tag can be rendered only inside for loop"; | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 71 | return $result; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | sub watches_changed | ||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||
| 124 | 39 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
watches_changed: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 125 | 39 | my $context = shift; | |||||||||||||||||||||||||||||||
| 126 | 39 | my $result = 0; | |||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 39 | ▶ | for( my $i = 0; $i < scalar @{$self->{'watches'}}; $i++ ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||
| 130 | 39 | my $watch = $self->{'watches'}->[$i]->render($context); | |||||||||||||||||||||||||||||||
| 131 | 39 | my $preserve = $self->{'preserved'}->[$i]; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 39 | ▶ | if( not DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $watch, $preserve)) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||
| 135 | 14 | $result = 1; | |||||||||||||||||||||||||||||||
| 136 | 14 | last; | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | 39 | return $result; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | sub update_preserved | ||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||
| 145 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
update_preserved: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 146 | 19 | my $context = shift; | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 19 | $self->{'preserved'} = []; | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 19 | foreach my $watch ( @{$self->{'watches'}} ) | |||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||
| 152 | 19 | push @{$self->{'preserved'}}, $watch->render($context); | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 19 | return $self; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | sub add_branch | ||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||
| 160 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
add_branch: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 12 | ▶ | $self->{'branches'} //= []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"branches"} //= []
MC/DC100%1/1
$self->{"branches"} //= []
$self->{"branches"}
Truth table100%2/2
A
A= $self->{"branches"}
| |||||||||||||||||||||||||||||||||
| 163 | 12 | push @{$self->{'branches'}}, DTL::Fast::Renderer->new(); | |||||||||||||||||||||||||||||||
| 164 | 12 | return $self; | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 2 | 1; | |||||||||||||||||||||||||||||||