line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Writer::Parser::TT; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4755
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
6
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
84
|
|
7
|
|
|
|
|
|
|
$VERSION = '5.32'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Labyrinth::Writer::Parser::TT - Template Toolkit Renderer for Labyrinth |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Labyrinth::Writer::Parser::TT; |
16
|
|
|
|
|
|
|
my $tt = Labyrinth::Writer::Parser::TT->new(); |
17
|
|
|
|
|
|
|
$tt->parser('mytemplate.html'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This package provides the ability to parse a given template, with a given set |
22
|
|
|
|
|
|
|
of template variables using Template Toolkit. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# ------------------------------------- |
27
|
|
|
|
|
|
|
# Library Modules |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
7
|
use Template; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
35
|
|
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
8
|
use Labyrinth::Audit; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
333
|
|
32
|
2
|
|
|
2
|
|
74
|
use Labyrinth::Variables; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# ------------------------------------- |
35
|
|
|
|
|
|
|
# Variables |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %config = ( # default config info |
38
|
|
|
|
|
|
|
RELATIVE => 1, |
39
|
|
|
|
|
|
|
ABSOLUTE => 1, |
40
|
|
|
|
|
|
|
INTERPOLATE => 0, |
41
|
|
|
|
|
|
|
POST_CHOMP => 1, |
42
|
|
|
|
|
|
|
TRIM => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ------------------------------------- |
46
|
|
|
|
|
|
|
# The Subs |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item new |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Object constructor. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item parser( $template, $variables ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Parses a given template, via Template Toolkit. Returns a string of the |
59
|
|
|
|
|
|
|
parsed template. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item parse_to_file( $template, $variables, $file, $binary ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Parses a given template, via Template Toolkit. Writes the result to the named |
64
|
|
|
|
|
|
|
file, marking as binary if requested. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
|
|
|
|
|
|
my($class) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $self = bless { config => \%config }, $class; |
74
|
|
|
|
|
|
|
$self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub parser { |
78
|
|
|
|
|
|
|
my ($self, $layout, $vars) = @_; |
79
|
|
|
|
|
|
|
my $path = $settings{'templates'}; |
80
|
|
|
|
|
|
|
my $output; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# use Data::Dumper; |
83
|
|
|
|
|
|
|
# LogDebug( "layout=[$layout]" ); |
84
|
|
|
|
|
|
|
# LogDebug( "vars=".Dumper($vars) ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->{config}{INCLUDE_PATH} = $path; |
87
|
|
|
|
|
|
|
$self->{config}{EVAL_PERL} = ($settings{evalperl} || $vars->{evalperl} ? 1 : 0); |
88
|
|
|
|
|
|
|
$self->{config}{OUTPUT_PATH} = $vars->{cache}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $parser = Template->new($self->{config}); # initialise parser |
91
|
|
|
|
|
|
|
eval { $parser->process($layout,$vars,\$output) }; |
92
|
|
|
|
|
|
|
die "TT PARSER ERROR: " . $parser->error() if($@ || !$output); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return \$output; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub parse_to_file { |
98
|
|
|
|
|
|
|
my ($self, $layout, $vars, $file, $binary) = @_; |
99
|
|
|
|
|
|
|
my $path = $settings{'templates'}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# use Data::Dumper; |
102
|
|
|
|
|
|
|
LogDebug( "file=[$file], binary=[$binary]" ); |
103
|
|
|
|
|
|
|
# LogDebug( "layout=[$layout]" ); |
104
|
|
|
|
|
|
|
# LogDebug( "vars=".Dumper($vars) ); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$self->{config}{INCLUDE_PATH} = $path; |
107
|
|
|
|
|
|
|
$self->{config}{EVAL_PERL} = ($vars->{evalperl} ? 1 : 0); |
108
|
|
|
|
|
|
|
$self->{config}{OUTPUT_PATH} = $vars->{cache}; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $parser = Template->new($self->{config}); # initialise parser |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
eval { |
113
|
|
|
|
|
|
|
if($binary) { |
114
|
|
|
|
|
|
|
# parse to binary |
115
|
|
|
|
|
|
|
$parser->process($layout,$vars,$file, binmode => 1) or die $parser->error(); |
116
|
|
|
|
|
|
|
} else { |
117
|
|
|
|
|
|
|
# parse to text |
118
|
|
|
|
|
|
|
$parser->process($layout,$vars,$file) or die $parser->error(); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
die "TT PARSER ERROR: eval=$@, error=" . $parser->error if($@); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |