Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: GANGLION [...] cpan.org
Cc:
AdminCc:

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



Subject: T::T::Preprocess, &pp called only once, $_ contains entire template
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: 1394
Download (untitled) / with headers
text/plain 1.3k
As tested, the code ref given to the PREPROCESSOR option is called only once, at which time $_ contains the entire template code. According to the docs: The preprocessor subroutine will be called repeatedly, once for each program fragment. The program fragment will be in $_. The subroutine should modify the contents of $_ and return. Text::Template::Preprocess will then execute contents of $_ and insert the result into the appropriate part of the template. Distribution: Debian Linux (Etch), Perl v5.8.0 built for i686-linux- thread-multi Test results: $ perl -w test_frag2 got the whole thing Form start joel Some stuff 48 Some more stuff 20000 End of stuff fragments counted: 1 Test code: #!/usr/bin/env perl use 5.008; use warnings; use Text::Template::Preprocess; my $count = 0;; my $template = Text::Template::Preprocess->new( TYPE => 'STRING', SOURCE => &template, ); #($name,$age,$income) = qw( joel 48 20000 ); # ??? XX my $hash = { name => 'joel', age => 48, income => 20000}; my $text = $template->fill_in( HASH => $hash, PREPROCESSOR => \&preprocess, ); print $text; print "fragments counted: $count\n"; sub preprocess { ++$count, $_ eq &template and print "got the whole thing\n"; }; sub template { <<'TEMPLATE'}; Form start { $name } Some stuff { $age } Some more stuff { $income } End of stuff TEMPLATE
MIME-Version: 1.0
Subject: &pp called only once, $_ contains entire template
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-8709-1197721617-1488.31560-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
From: joelz [...] pobox.com
X-RT-Original-Encoding: utf-8
Content-Length: 42
I am using version 1.44 of Text::Template.
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-8709-1197721617-1488.31560-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
References: <rt-3.6.HEAD-8709-1197721617-1488.31560-0-0 [...] rt.cpan.org>
Message-Id: <rt-3.6.HEAD-8692-1197724545-385.31560-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
From: joelz [...] pobox.com
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 376
Download (untitled) / with headers
text/plain 376b
Hi again. What I am trying to do is to use preprocessing magic so that if if a lone bare word appeared in a template { grammar } it will be substituted for the contents of file ./grammar to or the data from a script ./emit_grammar. The preprocessor checks for this, and rewrites 'grammar' into '$grammar', sets $grammar to the value, pulling the data into the form.
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-21172-1515019436-458.31560-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: 226
Download (untitled) / with headers
text/plain 226b
As far as I can tell, the way it behaves is the way MJD intended it to. Given this has been in production for so long at this point, I'm reluctant to change the way preprocess works at this point. -- Regards, Michael Schout
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-18854-1518100156-1156.31560-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: 109
Download (untitled) / with headers
text/plain 109b
Migrated to github issues: https://github.com/mschout/perl-text-template/issues/6 -- 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.