I have started creating a Perl package that contains a default email template.
The MANIFEST looks something like:
SendMyEmail.pm
SendMyEmail/defualt_email.tt
Currently I know where the module (and the template) are - but does the module itself know where on disk it is? So could the module find the default template without my help?
# This is what I would like to do.
package SendMyEmail;
sub new {
my ($self, $template) = @_;
$template ||= $dir_of_SendMyEmail .'/SendMyEmail/default_email.tt'; # ??
}
Is there a better way of including a templates text, or a better place to put the template?
Any references to CPAN modules that do something similar would be welcome.
Thanks in advance.
instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules. It is a little interface to ExtUtils::Installed to examine locally* installed modules, validate your packlists and even create a tarball from an installed module.
There are two main ways of loading a module in Perl. You can do it at compile time and at run time. The perl1 compiler (yes, there is a compiler although it's interpreted language) loads files, compiles them, then switches to run time to run the compiled code.
You'll find them in /usr/lib/perl/{VERSION}/ as well as /usr/lib64/perl/{VERSION}/ . {VERSION} corresponding to the version of Perl. You can get it with perl --version .
Each perl file has access to the variable __FILE__
which tells it its full path. Something like this should do the trick:
my $DEFAULT_TEMPLATE;
BEGIN {
$DEFAULT_TEMPLATE = __FILE__;
$DEFAULT_TEMPLATE =~ s,\.pm$,/default_email.tt,;
}
Still, if all you want is to bundle 'data' files with your modules then take a look at File::ShareDir which provides a way for doing that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With