Thread: Re: [htmltmpl] (no subject) [Patch] (Page 2)
Brought to you by:
samtregar
|
From: Emanuele Z. <em...@li...> - 2005-07-13 03:09:23
Attachments:
Template.pm.patch
05random.t
|
> -----Original Message-----
> From: htm...@li...=20
> [mailto:htm...@li...] On=20
> Behalf Of Sam Tregar
> Sent: Monday, July 11, 2005 8:00 PM
> To: Emanuele Zeppieri
> Cc: htm...@li...
> Subject: Re: [htmltmpl] (no subject)
>=20
>=20
> On Mon, 11 Jul 2005, Emanuele Zeppieri wrote:
>=20
> > Well, I'm probably missing something (or everything), but=20
> it seems to me
> > that the following compiled code layout could solve the problem:
> >=20
> > JUMP to A IF false
> > ... # first true instruction
> > ...
> > ... # last true instruction
> > JUMP TO B
> > A: ... # first false instruction
> > ...
> > ... # last false instruction
> > B: ... # normal execution after the IF/ELSE, if any...
>=20
> Yup, that would do it. That's much easier than trying to store state
> from the first one. So, when can I see a patch?
Here it is Sam.
It guarantees that any conditional predicate is never re-evaluated and,
as an extra bonus, it also speeds up the output() execution in presence
of a TMPL_ELSE tag.
It passed all the tests under both Linux and Windows and I've also added
a new test for HTML::Template::Expr (05random.t) which reproduces the
case showed by Jochen Cichon.
The patch is against Template.pm ver. 2.7.
The patch is attached to this message (as well as the new test) and also
listed below.
Feel free to remove my name from the comments (left there merely to
easily find the relevant lines, just in case a correction is needed or a
further refinement comes to my mind).
Cheers,
Emanuele.
--- Template.pm.original Sat Jun 26 08:57:09 2004
+++ Template.pm Wed Jul 13 03:35:03 2005
@@ -897,7 +897,7 @@
# accesses into "objects". I used to use 'use constant' but that
# seems to cause occasional irritating warnings in older Perls.
package HTML::Template::LOOP;
-sub TEMPLATE_HASH () { 0; }
+sub TEMPLATE_HASH () { 0 };
sub PARAM_SET () { 1 };
=20
package HTML::Template::COND;
@@ -908,6 +908,7 @@
sub JUMP_IF_TRUE () { 2 };
sub JUMP_ADDRESS () { 3 };
sub WHICH () { 4 };
+sub UNCONDITIONAL_JUMP () { 5 };
sub WHICH_IF () { 0 };
sub WHICH_UNLESS () { 1 };
=20
@@ -2183,7 +2184,15 @@
=09
my $else =3D
HTML::Template::COND->new($cond->[HTML::Template::COND::VARIABLE]);
$else->[HTML::Template::COND::WHICH] =3D
$cond->[HTML::Template::COND::WHICH];
- $else->[HTML::Template::COND::JUMP_IF_TRUE] =3D not
$cond->[HTML::Template::COND::JUMP_IF_TRUE];
+
+ # <Emanuele Zeppieri>
+ # Removed because now unnecessary, as we'll unconditionally jump
over
+ #$else->[HTML::Template::COND::JUMP_IF_TRUE] =3D not
$cond->[HTML::Template::COND::JUMP_IF_TRUE];
+
+ # This is to mark this COND opcode as generated by a TMPL_ELSE
tag,
+ # so that we can just jump over during the output() execution.
+ $else->[HTML::Template::COND::UNCONDITIONAL_JUMP] =3D 1;
+ # </Emanuele Zeppieri>
=09
# need end-block resolution?
if (defined($cond->[HTML::Template::COND::VARIABLE_TYPE])) {
@@ -2201,7 +2210,7 @@
# the IF fails and falls though, output will reach the else
# and jump to the /if address.
$cond->[HTML::Template::COND::JUMP_ADDRESS] =3D $#pstack;
-=09
+ =09
} elsif ($which eq 'TMPL_INCLUDE') {
# handle TMPL_INCLUDEs
$options->{debug} and print STDERR "### HTML::Template Debug ###
$fname : line $fcounter : INCLUDE $name \n";
@@ -2657,7 +2666,12 @@
croak("HTML::Template->output() : fatal error in loop output :
$@")=20
if $@;
}
- } elsif ($type eq 'HTML::Template::COND') {
+ } elsif ($type eq 'HTML::Template::COND') {
+ =09
+ if ($line->[HTML::Template::COND::UNCONDITIONAL_JUMP]) {
+ $x =3D $line->[HTML::Template::COND::JUMP_ADDRESS]
+ } else {
+ =09
if ($line->[HTML::Template::COND::JUMP_IF_TRUE]) {
if ($line->[HTML::Template::COND::VARIABLE_TYPE] =3D=3D
HTML::Template::COND::VARIABLE_TYPE_VAR) {
if (defined ${$line->[HTML::Template::COND::VARIABLE]}) {
@@ -2689,6 +2703,9 @@
not scalar
@{$line->[HTML::Template::COND::VARIABLE][HTML::Template::LOOP::PARAM_SE
T]});
}
}
+ =20
+ }
+ =09
} elsif ($type eq 'HTML::Template::NOOP') {
next;
} elsif ($type eq 'HTML::Template::DEFAULT') {
|
|
From: Emanuele Z. <em...@li...> - 2005-07-13 04:11:30
Attachments:
05random.t
|
There was an error in the new test provided, sorry. Here is the correct version. Cheers, Emanuele. |
|
From: Sam T. <sa...@tr...> - 2005-07-13 17:50:07
|
On Wed, 13 Jul 2005, Emanuele Zeppieri wrote: > Here it is Sam. Awesome! I'll take a closer look soon. If you don't hear from me in a few days please feel free to nag. -sam |
|
From: <ig...@sh...> - 2005-12-07 01:29:24
|
htm...@li... MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.3 X-Originating-IP: 200.125.117.107 Hi, I think your problem is about mod_perl, and not HTML::Template. you must use strict and reset your global variables. On Tuesday 06 December 2005 11:25, Senthil Nathan wrote: > Hi All, > > Im using mod_perl 2 on Apache 2. I am using HTML::Template to display the > data from the perl/cgi script. > > For the first time loading the data is displayed properly. then for every > reload the data displayed on the template gets repeatedly displayed. (i.e, > it gets accumulated. for 5 times reload 5 sets of data is displayed in the > template). > > Actually this problem is not seen on cgi/perl environment. Only with > mod_perl this problem occurs. > > As this is also related with HTML::Template i posted it here. > > Thanks > Senthil ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. |
|
From: Steven B. <bau...@ya...> - 2013-01-29 13:02:07
|
Dear Sir or Madam: im Steven Bauer http://chalikidikihomes.com/diet.php?qespcobjsgfp 29.01.2013 7:02:03 |
|
From: Philip S T. <phi...@gm...> - 2002-06-28 05:56:04
|
On Fri, 28 Jun 2002, Glenn Morgan wrote: > I am using HTML::Template with PageKit and having a problem with > <tmpl_var> substitutions in javascript quoted strings. See below: > > <button onclick="javascript: js_str='<tmpl_var > name="tmpl_str">;"></button> > > If tmpl_str="It's a wonderful life" > > Then my resultant html is > > <button onclick="javascript: js_str='It's a wonderful life'";></button> Interesting. Looks like an escape=quotemeta may be in order here. This seems like something others might encounter at some point, so maybe it should be added to HTML::Template. Philip |
|
From: David K. <da...@gi...> - 2002-06-28 12:46:41
Attachments:
JSEscape.patch.txt
|
"Glenn Morgan" <Gl...@Mo...> wrote: > > I am using HTML::Template with PageKit and having a problem with > <tmpl_var> substitutions in javascript quoted strings...[snip] > > Unfortunately, > > 1) I am working with db data and am not aware of what chars data values > contain. > > 2) I am using the same data values in different places within the same > template and do not want escaped quotes in all cases. > > These two cases make it very messy to filter my datasets and escape > here, there and everywhere. > > Any ideas? Is there a simple solution or would a escape=quotes patch be > the way to go? i have had this problem, too. in addition to single and double quotes, Javascript literal strings cannot contain carriage returns, linefeeds, and (depending on the browser) tabs, either. and i also had output HTML that needed the value both ways, depending on where it was used in the document. in my case, i needed the value "JS-ESCAPED" to populate a data validation function, and HTML-ESCAPED elsewhere in the document for display. so i patched HTML::Template (v. 2.4) to add escape="JS" for that project. I never submitted the patch because 2.5 had already been released, and i kept meaning to make the patch for that latest version, but here, if it helps, is the patch i made for 2.4. maybe Sam will incorporate the patch in the next release, since we now share a common ex-boss :-) -dave |