Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: kbrint [...] rufus.net
Cc:
AdminCc:

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



Subject: [PATCH] BROKEN returns undef not handled correctly
Download (untitled) / with headers
text/plain 1019b
I believe I've found a discrepancy between the documentation for Text::Template and its implementation. Specifically: "BROKEN" ... If the "BROKEN" function returns "undef", "Text::Template" will immediately abort processing the template and return the text that it has accumulated so far. ... However, the code always returns undef: if ($fi_eval_err) { $fi_res = $fi_broken->(...); if (defined $fi_res) { ## kb: removed } else { ## kb: this always returns undef! return $fi_res; # Undefined means abort processing } I believe you meant to use this, which will contain the "text that it has accumulated so far" as per the perldoc: } else { return $fi_r; } Since the current behavior for undef can be had equally well by returning an empty string, I think this is a case where the module should be adjusted to have the documented behavior for undef.
Subject: text-template.patch
Index: t/14-broken.t =================================================================== --- t/14-broken.t (.../vendor/1.44) (revision 7) +++ t/14-broken.t (.../branches/undef-fix) (revision 7) @@ -3,7 +3,7 @@ use Text::Template; -print "1..5\n"; +print "1..6\n"; $n=1; @@ -80,3 +80,16 @@ $n++; } +# (6) BROKEN sub handles undef + +{ my $r = Text::Template->new(TYPE => 'string', + SOURCE => 'abc{1/0}defg', + )->fill_in(BROKEN => sub { undef }); + if ($r eq qq{abc}) + { + print "ok $n\n"; + } else { + print "not ok $n\n# $r ne 'abc'\n"; + } + $n++; +} Index: lib/Text/Template.pm =================================================================== --- lib/Text/Template.pm (.../vendor/1.44) (revision 7) +++ lib/Text/Template.pm (.../branches/undef-fix) (revision 7) @@ -339,7 +339,7 @@ $fi_r .= $fi_res; } } else { - return $fi_res; # Undefined means abort processing + return $fi_r; # Undefined means abort processing } } else { if (defined $fi_ofh) {
Download (untitled) / with headers
text/plain 259b
Sorry for the ridiculously slow response to this. I've recently obtained COMAINT on Text::Template and am working through its RT queue as I get time. I agree this doesn't match the documented behavior and will be fixed in v1.48. -- 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.