Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 11920
Status: resolved
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: jlvarner [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.14
Fixed in: (no value)



Subject: Side effect if notation causes a variable to be unset when condition is false
I'm running on RH9.0 with perl settings: [josh@lcc51 bug]$ perl -e 'use Template; print "$Template::VERSION\n";' 2.14 [josh@lcc51 bug]$ perl -V Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux, osvers=2.4.20-2.48smp, archname=i386-linux-thread-multi uname='linux str' config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -g -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef' useithreads=define usemultiplicity= useperlio= d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=un uselongdouble= usemymalloc=, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)', gccosandvers='' gccversion='3.2.2 200302' intsize=e, longsize= , ptrsize=p, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long' k', ivsize=4' ivtype='long' known_ext, nvtype='double' o_nonbl', nvsize=, Off_t='', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc' l', ldflags =' -L/usr/local/lib' ldf' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil perllibs= libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libper gnulibc_version='2.3.1' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE' cccdlflags='-fPIC' ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s Unicode/Normalize XS/A' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT Locally applied patches: MAINT18379 Built under linux Compiled at Feb 18 2003 22:19:53 %ENV: PERL5LIB="/home/josh/public_html/cgi-bin/site_perl/lib/perl5:/home/josh/public_html/cgi-bin/site_perl/lib/perl5/site_perl:/shared/lcc51/disk1/work/test/multi/tools/lib/perl5/site_perl" @INC: /home/josh/public_html/cgi-bin/site_perl/lib/perl5/5.8.0/i386-linux-thread-multi /home/josh/public_html/cgi-bin/site_perl/lib/perl5/5.8.0 /home/josh/public_html/cgi-bin/site_perl/lib/perl5 /home/josh/public_html/cgi-bin/site_perl/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /home/josh/public_html/cgi-bin/site_perl/lib/perl5/site_perl/5.8.0 /home/josh/public_html/cgi-bin/site_perl/lib/perl5/site_perl /shared/lcc51/disk1/work/test/multi/tools/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /shared/lcc51/disk1/work/test/multi/tools/lib/perl5/site_perl/5.8.0 /shared/lcc51/disk1/work/test/multi/tools/lib/perl5/site_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 ---------------------- I found that if you want to change the value of a variable with a side effect IF notation it unsets the variable if the condition is false. The following template: Start Buggy Template [% var = 'hello' %] I'm var: [% var %] [% IF 0 > 1 %] [% var = 'wrong1' %] [% END %] I should still be: [% var %] [% IF 0 > 1; var = 'wrong2'; END; %] I should still be: [% var %] [% var = 'wrong3' IF 1 < 0 %] What is going on [% var %] End Buggy Template produces this output: Start Buggy Template I'm var: hello I should still be: hello I should still be: hello What is going on End Buggy Template ------------- Notice the if check causes the variable to be unset, but using IF in a normal IF, statement, END notation does not have this effect.
Show quoted text
> [% var = 'wrong3' IF 1 < 0 %] >
I found this in the FAQ, sorry for the noise. This is a byproduct of a known parsing behavior, if I understand correctly [% SET var = 'wrong3' IF 1 < 0 %] would work in the manner I was expecting, I think you might want to place this warning into a more prominent location, rather than just the FAQ. Possibly as a footnote where SET is described to explicitly mention this exception. Josh