Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Distributing/Accessing Template::Toolkit Templates

by three18ti (Monk)
on Nov 05, 2013 at 06:20 UTC ( [id://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!

Replies are listed 'Best First'.
Re: Distributing/Accessing Template::Toolkit Templates
by GrandFather (Saint) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-24 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found