| 1 | package Miril::Template::Text::Template; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use autodie; | ||
| 6 | |||
| 7 | use base 'Miril::Template::Abstract'; | ||
| 8 | |||
| 9 | use Text::Template; | ||
| 10 | use File::Spec::Functions qw(catfile); | ||
| 11 | use Try::Tiny qw(try catch); | ||
| 12 | use Miril::Exception; | ||
| 13 | |||
| 14 | sub load { | ||
| 15 | my $self = shift; | ||
| 16 | my %options = @_; | ||
| 17 | |||
| 18 | my $tmpl; | ||
| 19 | |||
| 20 | try | ||
| 21 | { | ||
| 22 | $tmpl = Text::Template->new( TYPE => 'FILE', SOURCE => catfile($self->tmpl_path, $options{name}) ); | ||
| 23 | } | ||
| 24 | catch | ||
| 25 | { | ||
| 26 | Miril::Exception->throw( | ||
| 27 | message => "Could not open template file", | ||
| 28 | errorvar => $_, | ||
| 29 | ); | ||
| 30 | }; | ||
| 31 | |||
| 32 | return $tmpl->fill_in( HASH => $options{params} ); | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; |