/usr/share/perl5/MIME/Lite/TT.pm is in libmime-lite-tt-perl 0.02-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | package MIME::Lite::TT;
use strict;
use vars qw($VERSION);
$VERSION = '0.02';
use MIME::Lite;
use Template;
use Carp ();
sub new {
my ($class, %options) = @_;
%options = $class->_before_process(%options);
if ( my $template = delete $options{Template} ) {
my $tmpl_options = delete $options{TmplOptions} || {};
my %config = (ABSOLUTE => 1,
RELATIVE => 1,
%$tmpl_options,
);
if ( $options{TmplUpgrade}) {
$config{LOAD_TEMPLATES} = [MIME::Lite::TT::Provider->new(\%config)];
}
my $tt = Template->new(\%config);
my $tmpl_params = delete $options{TmplParams} || {};
$tt->process($template, $tmpl_params, \$options{Data})
or Carp::croak $tt->error;
}
%options = $class->_after_process(%options);
MIME::Lite->new(%options);
}
sub _before_process {
my $class = shift;
@_;
}
sub _after_process {
my $class = shift;
@_;
}
package MIME::Lite::TT::Provider;
use strict;
use base qw(Template::Provider);
sub _load {
my $self = shift;
my ($data, $error) = $self->SUPER::_load(@_);
if(defined $data) {
$data->{text} = utf8_upgrade($data->{text});
}
return ($data, $error);
}
sub utf8_upgrade {
my @list = map pack('U*', unpack 'U0U*', $_), @_;
return wantarray ? @list : $list[0];
}
1;
__END__
=head1 NAME
MIME::Lite::TT - TT enabled MIME::Lite wrapper
=head1 SYNOPSIS
use MIME::Lite::TT;
my $msg = MIME::Lite::TT->new(
From => 'me@myhost.com',
To => 'you@yourhost.com',
Subject => 'Hi',
Template => \$template,
TmplParams => \%params,
TmplOptions => \%options,
);
$msg->send();
=head1 DESCRIPTION
MIME::Lite::TT is the wrapper of MIME::Lite which enabled Template::Toolkit as a template of email.
=head1 ADITIONAL OPTIONS
=head2 Template
The same value passed to the 1st argument of the process method of Template::Toolkit is set to this option.
=head2 TmplParams
The parameter of a template is set to this option.
This parameter must be the reference of hash.
=head2 TmplOptions
configuration of Template::Toolkit is set to this option.
ABSOLUTE and RELATIVE are set to 1 by the default.
=head2 TmplUpgrade
template is force upgraded. (means utf-8 flag turns on)
=head1 SAMPLE
use MIME::Lite::TT;
my $template = <<TEMPLATE;
This is template.
my name is [% name %].
TEMPLATE
my %params = (name => 'horiuchi');
my %options = (EVAL_PERL=>1);
my $msg = MIME::Lite::TT->new(
From => 'me@myhost.com',
To => 'you@yourhost.com',
Subject => 'hi',
Template => \$template,
TmplParams => \%params,
TmplOptions => \%options,
);
$msg->send();
=head1 AUTHOR
Author E<lt>horiuchi@vcube.comE<gt>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<MIME::Lite>,L<Template>
=cut
|