in reply to Import Constants From File to Templates?

> I'd like to include those constants in all my templates directly from my constants module rather than importing them to my script

OK if you don't need those constants at all ...

Instead of passing the exported constants each time with ->process

>

my $tt = Template->new( { INCLUDE_PATH => $BASE_DIR . '/root/src/', INTERPOLATE => 1, } ) || die "$Template::ERROR\n"; $tt->process( $email_args{text_template},

you could make your config module export the initialized TT object

package Sam::Constants; use Template; our $tt = Template->new( # export me { INCLUDE_PATH => $BASE_DIR . '/root/src/', INTERPOLATE => 1, CONSTANTS => { ... }, VARIABLES => { ... }, } ) || die "$Template::ERROR\n";

(see also Re: Import Constants From File to Templates?)

And if things like $BASE_DIR need to be flexible, provide an import() function.

use Sam::Constants base_dir =>  "...";

edit

and if you have to manage different constructor setups, export functions which do the different construction and return the specialized $tt object.

update

package Sam::Constants; my @defaults_all = (... ); sub foo { return Template->new( @_ , @defaults_all, DEFAULTS_foo ) }; sub bar { return Template->new( @_ , @defaults_all, DEFAULTS_bar ) }; ... # other file use Sam::Constants qw/foo/; my $tt = foo(LOCAL_CFG); $tt->process();

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery