line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Typist::Template; |
2
|
1
|
|
|
1
|
|
1001
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw( $VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
$VERSION = 0.04; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use base qw( Class::ErrorHandler ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Typist::Builder; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
11
|
1
|
|
|
1
|
|
4
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
401
|
|
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
1
|
|
sub new { bless {__text => $_[1]}, $_[0] } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub load { |
16
|
0
|
|
|
0
|
1
|
|
my ($class, $file) = @_; |
17
|
0
|
|
|
|
|
|
my @paths = |
18
|
|
|
|
|
|
|
($file, map File::Spec->catfile($_, $file), Typist->instance->tmpl_path); |
19
|
0
|
|
|
|
|
|
my $path; |
20
|
0
|
|
|
|
|
|
for my $p (@paths) { |
21
|
0
|
0
|
0
|
|
|
|
$path = $p, last if -e $p && -r _; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
0
|
|
|
|
|
$path = $file unless defined $path; # let missing file fall to open error. |
24
|
0
|
|
|
|
|
|
local *FH; |
25
|
0
|
0
|
|
|
|
|
open FH, $path |
26
|
|
|
|
|
|
|
or return $class->error( |
27
|
|
|
|
|
|
|
Typist->translate("Load of template '[_1]' failed: [_2]", $path, "$!")); |
28
|
0
|
|
|
|
|
|
local $/; |
29
|
0
|
|
|
|
|
|
my $text = ; |
30
|
0
|
|
|
|
|
|
my $tmpl = $class->new($text); |
31
|
0
|
|
|
|
|
|
close FH; |
32
|
0
|
|
|
|
|
|
$tmpl; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub build { |
36
|
0
|
|
|
0
|
1
|
|
my $tmpl = shift; |
37
|
0
|
|
|
|
|
|
my ($ctx, $cond) = @_; |
38
|
0
|
|
|
|
|
|
my $tokens = $tmpl->{__tokens}; |
39
|
0
|
|
|
|
|
|
my $build = Typist::Builder->new; |
40
|
0
|
0
|
|
|
|
|
unless ($tokens) { |
41
|
0
|
|
|
|
|
|
my $text = $tmpl->{__text}; |
42
|
0
|
0
|
|
|
|
|
$tokens = $build->compile($ctx, $text) |
43
|
|
|
|
|
|
|
or return |
44
|
|
|
|
|
|
|
$tmpl->error( |
45
|
|
|
|
|
|
|
Typist->translate( |
46
|
|
|
|
|
|
|
"Parse error in template '[_1]': [_2]", $tmpl->filename, |
47
|
|
|
|
|
|
|
$build->errstr |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
); |
50
|
0
|
|
|
|
|
|
$tmpl->{__tokens} = $tokens; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
|
|
|
|
defined(my $res = $build->build($ctx, $tokens, $cond)) |
53
|
|
|
|
|
|
|
or return |
54
|
|
|
|
|
|
|
$tmpl->error( |
55
|
|
|
|
|
|
|
Typist->translate( |
56
|
|
|
|
|
|
|
"Build error in template '[_1]': [_2]", |
57
|
|
|
|
|
|
|
$tmpl->filename, |
58
|
|
|
|
|
|
|
$build->errstr |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
); |
61
|
0
|
|
|
|
|
|
$res; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |