Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Distributing/Accessing Template::Toolkit Templates

by three18ti (Scribe)
on Nov 05, 2013 at 06:20 UTC ( #1061248=perlquestion: print w/ replies, xml ) Need Help??
three18ti has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I would like to include some templates with a Module I am developing, but I'm not sure how I would include them such that when the module is installed the templates are accessible.

I use Dist::Zilla to mint the skeleton and build/test/release the module.

So if I put my templates in lib/Foo/Templates/*.tt, what parameter to I feed my Template->new to to tell it to search in the $default_locations/Foo/Templates/? Ideally, I would prefer not to have to specify all the locations, because there are a number of pitfalls with that solution (what if module is installed in non standard location, what if a windows user installs the module, etc.)

I think this is what tells it to search my local build directory:

my $tt = Template->new({ INCLUDE_PATH => ['lib/Foo/Templates'], }) || die "$Template::ERROR\n";

Thanks Monks!

Comment on Distributing/Accessing Template::Toolkit Templates
Download Code
Replies are listed 'Best First'.
Re: Distributing/Accessing Template::Toolkit Templates
by GrandFather (Sage) on Nov 05, 2013 at 08:26 UTC

    If you install the templates in a directory relative to the directory containing your module then you can use %INC to get the path:

    use warnings; use strict; use Foo; (my $fooDir = $INC{'Foo.pm'}) =~ s/Foo\.pm$//; my $tmplDir = "${fooDir}Templates";
    True laziness is hard work

      Hey, that's pretty clever. Are there any pitfals with this method? File::ShareDir seems like it might be the better option, unless for some reason you're limited in the modules you can use...

      Thanks for the reply!

        I'd go with File::Share. I was unaware of it. It looks a better fit for your distribution problem.

        True laziness is hard work
Re: Distributing/Accessing Template::Toolkit Templates (File::ShareDir)
by Anonymous Monk on Nov 05, 2013 at 08:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1061248]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2015-07-31 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls