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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: text/plain
Charset: utf8
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 798
Download (untitled) / with headers
text/plain 798b
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.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-23846-1206108622-1882.34292-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 1809
Download (untitled) / with headers
text/plain 1.7k
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.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-15565-1514997956-463.34292-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1371
Download (untitled) / with headers
text/plain 1.3k
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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.