Item9179: Long dead code in tmplP() of Template.pm
Priority: Low
Current State: Needs Developer
Released In: n/a
Target Release: n/a
Applies To: Engine
Component: Template
Branches:
If I'm reading this right, it looks like the tests for param{'then'} and param{'else'} should always fail and line 172 should never be executed since both of those params were removed at lines 152 and 153.
From
trunk/core/lib/Foswiki/Template.pm@7682
147 sub tmplP {
148 my ( $this, $params ) = @_;
149
150 my $template = $params->remove('_DEFAULT') || '';
151 my $context = $params->remove('context');
152 my $then = $params->remove('then');
153 my $else = $params->remove('else');
154 if ($context) {
155 $template = $then if defined($then);
156 foreach my $id ( split( /\,\s*/, $context ) ) {
157 unless ( $this->{session}->{context}->{$id} ) {
158 $template = ( $else || '' );
159 last;
160 }
161 }
162 }
163
164 return '' unless $template;
165
166 my $val = '';
167 if ( exists( $this->{VARS}->{$template} ) ) {
168 $val = $this->{VARS}->{$template};
169 $val = "$val" if (TRACE);
170 foreach my $p ( keys %$params ) {
171 if ( $p eq 'then' || $p eq 'else' ) {
172 $val =~ s/%$p%/$this->expandTemplate($1)/ge;
173 }
174 elsif ( defined( $params->{$p} ) ) {
175 $val =~ s/%$p%/$params->{$p}/ge;
176 }
177 }
178 $val =~ s/%TMPL:PREV%/%TMPL:P{"$template:_PREV"}%/g;
179 $val =~ s/%TMPL:P{(.*?)}%/$this->expandTemplate($1)/ge;
180 }
181
182 return $val;
183 }
--
BryanThale - 20 Jun 2010
Yeah, dunno where that came from.
then
and
else
are special - they are selected between based on the result of the
context
test - and in no circumstances should %then% of %else% need to be expanded in the template body.
--
CrawfordCurrie - 28 Jun 2010