| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Eve::Template; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 1022 | use parent qw(Eve::Class); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 1299 | use utf8; | 
|  | 1 |  |  |  |  | 12 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 6 | 1 |  |  | 1 |  | 39 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 7 | 1 |  |  | 1 |  | 1448 | use autodie; | 
|  | 1 |  |  |  |  | 22002 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 8 | 1 |  |  | 1 |  | 9632 | use warnings; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 61 |  | 
| 9 | 1 |  |  | 1 |  | 1425 | use open qw(:std :utf8); | 
|  | 1 |  |  |  |  | 1866 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 10 | 1 |  |  | 1 |  | 1268 | use charnames qw(:full); | 
|  | 1 |  |  |  |  | 57997 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 354 | use Template; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 13 | 1 |  |  | 1 |  | 6 | use Template::Stash::XS; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 439 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 NAME | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | B - a template engine class. | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my $template = Eve::Template->new( | 
| 22 |  |  |  |  |  |  | path => '/some/include/path', | 
| 23 |  |  |  |  |  |  | compile_path => '/some/compile/path', | 
| 24 |  |  |  |  |  |  | expiration_interval => 60); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my $output = $template->process( | 
| 27 |  |  |  |  |  |  | file => 'helloworld.html', | 
| 28 |  |  |  |  |  |  | var_hash => $var_hash); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | B is a template engine adapter class. It adapts well | 
| 33 |  |  |  |  |  |  | known B package. | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head3 Constructor arguments | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =over 4 | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =item C | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | a path to template files | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =item C | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | a path where compiled template files will be stored | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =item C | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | determines how long (in seconds) a template is keeping cached in | 
| 50 |  |  |  |  |  |  | memory before checking if it is changed | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =item C | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | an optional hash of variables that will be additionally made available | 
| 55 |  |  |  |  |  |  | to all processed templates. | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =back | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head3 Throws | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =over 4 | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =item C | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | when the template creation was unsuccessful. | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =back | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 METHODS | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head2 B | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub init { | 
| 76 | 5 |  |  | 5 | 1 | 34 | my ($self, %arg_hash) = @_; | 
| 77 | 5 |  |  |  |  | 28 | Eve::Support::arguments( | 
| 78 |  |  |  |  |  |  | \%arg_hash, | 
| 79 |  |  |  |  |  |  | my ($path, $compile_path, $expiration_interval), | 
| 80 |  |  |  |  |  |  | my $var_hash = {}); | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 5 |  |  |  |  | 306 | $self->{'template'} = Template->new({ | 
| 83 |  |  |  |  |  |  | INCLUDE_PATH => $path, | 
| 84 |  |  |  |  |  |  | COMPILE_DIR => $compile_path, | 
| 85 |  |  |  |  |  |  | STAT_TTL => $expiration_interval, | 
| 86 |  |  |  |  |  |  | ENCODING => 'utf8', | 
| 87 |  |  |  |  |  |  | STASH => Template::Stash::XS->new($var_hash)}); | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 5 | 100 |  |  |  | 20 | if (not defined $self->{'template'}) { | 
| 90 | 1 |  |  |  |  | 21 | Eve::Error::Template->throw(message => $Template::ERROR); | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 4 |  |  |  |  | 113 | return; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head2 B | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Process the template. | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head3 Arguments | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =over 4 | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =item C | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | a template file to process | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =item C | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | a variables hash to be used in the template. | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =back | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head3 Returns | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | A text assembled after processing. | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =head3 Throws | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =over 4 | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =item C | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | when the processing was unsuccessful. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =back | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =cut | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | sub process { | 
| 131 | 3 |  |  | 3 | 1 | 1854 | my ($self, %arg_hash) = @_; | 
| 132 | 3 |  |  |  |  | 16 | Eve::Support::arguments( | 
| 133 |  |  |  |  |  |  | \%arg_hash, my ($file, $var_hash) = (\undef, {})); | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 3 |  |  |  |  | 35 | my $output; | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 3 | 100 |  |  |  | 134 | if (not defined $self->template->process( | 
| 138 |  |  |  |  |  |  | $file, $var_hash, \$output, {'binmode' => ":utf8"})) { | 
| 139 | 1 |  |  |  |  | 11 | Eve::Error::Template->throw(message => $self->template->error()); | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 2 |  |  |  |  | 73 | return $output; | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =over 4 | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =item L | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =item L | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item L | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =back | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | Copyright 2012 Igor Zinovyev. | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 162 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 163 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =head1 AUTHOR | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =over 4 | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =item L | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =back | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =cut | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | 1; |