Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

TT PLUGIN_PATH

by jatill (Beadle)
on Apr 11, 2005 at 10:02 UTC ( [id://446602]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

jatill has asked for the wisdom of the Perl Monks concerning the following question:

I have a homegrown plugin module for template toolkit that lives in /my/directory/My/Plugin.pm. What would I need to set the PLUGIN_PATH to in order to be able to [% USE My::Plugin %] in my templates? Also, if this pluging module does stuff that non-templates want to access too, would I be better off creating 2 modules (one with the subs, and 1 as a wrapper for the Plugin), or just call the subs directly from the Plugin module?

Replies are listed 'Best First'.
Re: TT PLUGIN_PATH
by Taulmarill (Deacon) on Apr 11, 2005 at 10:19 UTC
    a simple use lib qw(/my/directory); in your perl-script should do the trick.

    --edit--
    oh, yes, and your module has to be somewhere under Template::Plugin, otherwise TT2 is not recognizing it as a plugin. see the Documentation.
Re: TT PLUGIN_PATH
by matthewb (Curate) on Apr 11, 2005 at 12:38 UTC

    You can include plugins you have defined yourself that are outside of @INC by specifying a relative (to the program that constructs a new Template object) path.

    Supposing the following output of ls -R:

    .: Local index.pl ./Local: MyPlugin.pm

    ...where one might use the module Local/MyPlugin.pm with ``use Local::MyPlugin;'', an argument to the constructor of ``PLUGIN_BASE => 'Local','' would allow you to say ``[% USE MyPlugin %]''.

    A trivial example (using the proposed directory structure) may be illustrated, thus:

    There's a book which explains all this very nicely, personally I found it easier-going than browsing the docs.

    As for whether you should use your plugin-defining module elsewhere in your application, I can't see an obvious case where you'd want to use code that inherits from Template::Plugin::Base outside of the context of processing templates but, if you can, there's no particular reason you cannot. I would argue that it makes sense to keep your plugin logic packaged separately, if only to make its purpose obvious to a future maintainer.


    MB

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://446602]
Approved by Corion
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.