Skip Menu |

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

Report information
The Basics
Id: 106894
Status: resolved
Priority: 0/
Queue: Template-Plugin-Latex

People
Owner: EHUELS [...] cpan.org
Requestors: tsibley [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 3.06
  • 3.07
  • 3.08
  • 3.09
Fixed in: (no value)



Subject: TEXINPUTS set incorrectly when used with Catalyst::View::TT or any coderef in INCLUDE_PATH
Template::Provider (the default template provider for TT) supports dynamic INCLUDE_PATH values by pushing coderefs into INCLUDE_PATH. At template lookup time, it calls any coderefs it comes across. Catalyst::View::TT makes use of this feature to support locally-overridden INCLUDE_PATHs. When I create a Latex view for a Catalyst app using Catalyst::View::TT and passing CLASS => 'Template::Latex' in the configuration hash, the TEXINPUTS variable isn't set correctly in Template::Plugin::Latex because the coderef gets stringified. The end result of all this is that \input{} doesn't work with paths relative to the template file itself. A workaround is to use TT's INCLUDE directive instead, although that does end up parsing the included file as a template instead of slurping it in as raw TeX. A quick fix for Template::Plugin::Latex is to handle coderefs in INCLUDE_PATH inside _setup_texinput_paths. However, I suspect there is a better API for this that the Template $context object provides in order to hide the implementation details of INCLUDE_PATH from plugins like Latex.
On Fri Sep 04 17:40:14 2015, TSIBLEY wrote: Show quoted text
> Template::Provider (the default template provider for TT) supports > dynamic INCLUDE_PATH values by pushing coderefs into INCLUDE_PATH. At > template lookup time, it calls any coderefs it comes across. >
Thanks for your report! With the release of 3.07, quite a bit of handling of TT arguments in Template::Latex's constructor was refactored. Can you test and see if it works now? If not, it would be really helpful to have a minimal reproduction case to test a solution against. Thanks!
On Sun Jul 10 06:53:42 2016, EHUELS wrote: Show quoted text
> With the release of 3.07, quite a bit of handling of TT arguments in > Template::Latex's constructor was refactored. Can you test and see if > it works now?
Nope, none of the changes in 3.07 apply to this bug. The changes only affect how executable paths are determined. Show quoted text
> If not, it would be really helpful to have a minimal reproduction case > to test a solution against.
I'm not able to provide a proper test file at the moment, but consider the demonstration in the attached file.
Subject: dynamic-include-path.t
use Template; use Data::Printer; my $t = Template->new( CLASS => "Template::Latex", INCLUDE_PATH => [ "static", sub { [qw[ dynamic1 dynamic2 ]] }, ], ); # Template::Plugin::Latex::_setup_texinput_paths tries to handle processing # INCLUDE_PATH itself, but gets it wrong because it assumes every value is a # string. Template::Provider supports objects and coderefs to dynamically # provide a list of paths. The Template::Provider "paths" method correctly # processes INCLUDE_PATH. Template::Plugin::Latex should be iterating over the # providers in $context->{LOAD_TEMPLATES} and calling ->paths on each to # construct the list of strings to process in _setup_texinput_paths. p $t->context->plugin("Latex")->can("_setup_texinput_paths")->($t->context); p $t->context->{LOAD_TEMPLATES}[0]->paths; __END__ Printing in line 19 of dynamic-include-path.t: \ [ [0] "", [1] "static", [2] sub { ['dynamic1', 'dynamic2']; } ] Printing in line 20 of dynamic-include-path.t: \ [ [0] "static", [1] "dynamic1", [2] "dynamic2" ]
Consider this patch which fixes the behaviour I'm observing. When applied, it makes the output of the dynamic-include-path.t I sent correct: Printing in line 19 of dynamic-include-path.t: \ [ [0] "", [1] "static", [2] "dynamic1", [3] "dynamic2" ] Printing in line 20 of dynamic-include-path.t: \ [ [0] "static", [1] "dynamic1", [2] "dynamic2" ]
Subject: 0001-Ask-Template-Provider-for-a-list-of-include-paths-in.patch
From 3a016d6620f8ec77744930f54327186ad7f92460 Mon Sep 17 00:00:00 2001 From: Thomas Sibley <tsibley@cpan.org> Date: Wed, 13 Jul 2016 11:32:18 -0700 Subject: [PATCH] Ask Template::Provider for a list of include paths instead of processing ourselves INCLUDE_PATH is allowed to contain non-string values such as coderefs and objects which dynamically provide paths. Template::Provider, the base class for all providers, gives us a "paths" method to properly process INCLUDE_PATH into a simple list of strings. Previously coderefs and objects were passed through unevaluated and LaTeX::Driver stringified them leading to paths like "CODE(0xDEADBEEF)" ending up in TEXINPUTS. One such popular user of coderefs in INCLUDE_PATH is Catalyst::View::TT. --- lib/Template/Plugin/Latex.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Template/Plugin/Latex.pm b/lib/Template/Plugin/Latex.pm index e2c4d2c..7fce4b7 100644 --- a/lib/Template/Plugin/Latex.pm +++ b/lib/Template/Plugin/Latex.pm @@ -184,8 +184,13 @@ sub _tt_latex_filter { sub _setup_texinput_paths { my ($context) = @_; my $template_name = $context->stash->get('template.name'); - my $include_path = $context->config->{INCLUDE_PATH} || []; - $include_path = [ $include_path ] unless ref $include_path; + my $include_path = []; + + # Ask each Template::Provider object for a list of paths. This properly + # handles coderefs and objects in INCLUDE_PATH. + for my $provider (@{ $context->{LOAD_TEMPLATES} }) { + push @$include_path, @{ $provider->paths || [] }; + } my @texinput_paths = (""); foreach my $path (@$include_path) { -- 2.8.3
I can provide a pull request against https://github.com/Template-Toolkit-Latex/Template-Latex with that patch if you'd like (it's also apply-able with `git am`). Unfortunately I can't add a proper test case for right now in the style of the other tests.
Fixed in version 3.10 uploaded just a second ago.