Skip Menu |
 

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

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

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

Bug Information
Severity: Important
Broken in:
  • 1.46
  • 1.44
  • 1.45
Fixed in: 1.48



Subject: FILENAME parameter has no effect.
Download (untitled) / with headers
text/plain 2.3k
Frankly, FILENAME parameter is not documented. Anyway, it is lack of documentation and error. Let us look at _param function usage in Text/Template.pm: $ grep '_param(' Template.pm my $stype = uc(_param('type', %a) || "FILE"); my $source = _param('source', %a); my $untaint = _param('untaint', %a); my $prepend = _param('prepend', %a); my $alt_delim = _param('delimiters', %a); my $broken = _param('broken', %a); my $delims = _param('delimiters', %fi_a); my $fi_varhash = _param('hash', %fi_a); my $fi_package = _param('package', %fi_a) ; _param('broken', %fi_a) || $fi_self->{BROKEN} || \&_default_broken; my $fi_broken_arg = _param('broken_arg', %fi_a) || []; my $fi_safe = _param('safe', %fi_a); my $fi_ofh = _param('output', %fi_a); my $fi_filename = _param('filename') || $fi_self->{FILENAME} || 'template'; my $fi_prepend = _param('prepend', %fi_a); my $package = _param('package', @_); Note: the function 15 times is called with TWO arguments, and only once it is called with ONE argument: my $fi_filename = _param('filename') || $fi_self->{FILENAME} || 'template'; Looking at _param definition: sub _param { my $kk; my ($k, %h) = @_; for $kk ($k, "\u$k", "\U$k", "-$k", "-\u$k", "-\U$k") { return $h{$kk} if exists $h{$kk}; } return; } it is clear that function must be called with TWO arguments. Being called with one argument if will always return undef. Problem line again (at Template.pm line 257): my $fi_filename = _param('filename') || $fi_self->{FILENAME} || 'template'; It should be written as my $fi_filename = _param('filename', %fi_a) || $fi_self->{FILENAME} || 'template'; like lines just above: my $fi_safe = _param('safe', %fi_a); my $fi_ofh = _param('output', %fi_a); Being fixed in such a way, FILENAME parameter works as expected. Please note that parameter is not documented bu should be. Usage case is simple: caller code (for any reason) can read the template from a file, and so (because file is already read) use fill_in_string function (or its functional analogs) to process the template. If any program fragment is broken, error messages will look like ... at template line N Caller code knows the file name and could specify it: $result = fill_in_string( $template, FILENAME => 'file.txt' ); to make error messages better: ... at file.txt line N Unfortunately, FILENAME parameter has no effect now.
Download (untitled) / with headers
text/plain 101b
Documented, fixed, and added a test case. This will be in v1.48 Thanks! -- 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.