Skip Menu |

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

Report information
The Basics
Id: 34292
Status: resolved
Priority: 0/
Queue: Text-Template

People
Owner: Nobody in particular
Requestors: cpan [...] codechild.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.44
Fixed in: 1.48



Subject: Comment within inline code
I noticed that one cannot put a comment witin a inline code block for templates if that code block contains no carriage return. For example, the following does not work: $S::name = 'Bob'; my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => "{\$name#comment}" ); print $tmpl->fill_in( PACKAGE => 'S' ); The following does work: $S::name = 'Bob'; my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => "{\$name#comment\n}" ); print $tmpl->fill_in( PACKAGE => 'S' ); As a workaround, I will be doing something like the following: $S::name = 'Bob'; $text = "{\$name#comment}"; $text =~ s/\}/\n\}/g; my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => $text ); print $tmpl->fill_in( PACKAGE => 'S' ); It would be nice if I didn't have to manually add a \n before every } though.
On Thu Mar 20 16:10:48 2008, CODECHILD wrote: Show quoted text
> I noticed that one cannot put a comment witin a inline code block for > templates if that code block contains no carriage return. > > For example, the following does not work: > $S::name = 'Bob'; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => > "{\$name#comment}" ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > The following does work: > $S::name = 'Bob'; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => > "{\$name#comment\n}" ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > As a workaround, I will be doing something like the following: > $S::name = 'Bob'; > $text = "{\$name#comment}"; > $text =~ s/\}/\n\}/g; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => $text ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > It would be nice if I didn't have to manually add a \n before every } > though.
Potential fix ( which I will be using till the module is changed ): Change line 308.. from the following: "package $fi_eval_package; $fi_prepend;\n$fi_lcomment\n$fi_text;"; to: "package $fi_eval_package; $fi_prepend;\n$fi_lcomment\n$fi_text\n;"; Note that all this does, obviously enough, is changed the compiled tempalte from: [code]#comment; to: [code]#comment ; This is semantically the same as: [code];#comment Saying it is semantically the same because I verified perl pre-compilation by using perl -MO=Deparse... --- Ultimately it seems to be an oddity with eval eval("print 'test'#comment"); # works eval("print 'test'#comment;"); # doesn't work eval("print 'test'#comment\n;"); # works eval("print 'test'#comment;\n"); # works Note that there seems to be a danger with the last form, because it fails if you put a command after the \n within the eval. The third form seems to be the safe solution.
On Thu Mar 20 16:10:48 2008, CODECHILD wrote: Show quoted text
> I noticed that one cannot put a comment witin a inline code block for > templates if that code block contains no carriage return.
Hi. I realize this reply is extremely late. I have taken over maintainership of Text::Template and have been working through the bug reports as I get time. This issue it seems was fixed in perl 5.18 as the example you give does work in 5.18. It does not work in 5.16 or earlier. Nevertheless, its simple enough to fix with the solution you provided. I will be committing a fix and this will finally be fixed in Text::Template v1.48 Thanks! Show quoted text
> > For example, the following does not work: > $S::name = 'Bob'; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => > "{\$name#comment}" ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > The following does work: > $S::name = 'Bob'; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => > "{\$name#comment\n}" ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > As a workaround, I will be doing something like the following: > $S::name = 'Bob'; > $text = "{\$name#comment}"; > $text =~ s/\}/\n\}/g; > my $tmpl = Text::Template->new( TYPE => 'STRING', SOURCE => $text ); > print $tmpl->fill_in( PACKAGE => 'S' ); > > It would be nice if I didn't have to manually add a \n before every } > though.
-- Regards, Michael Schout