line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WSST::CodeTemplate; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
21507
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
1718
|
use Template; |
|
2
|
|
|
|
|
51362
|
|
|
2
|
|
|
|
|
714
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.1'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
2
|
|
|
2
|
1
|
34787
|
my $class = shift; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
|
|
6
|
my $self = {@_}; |
12
|
2
|
|
100
|
|
|
15
|
$self->{tmpl_dirs} ||= []; |
13
|
2
|
|
100
|
|
|
9
|
$self->{vars} ||= {}; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
6
|
bless($self, $class); |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
7
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get { |
21
|
4
|
|
|
4
|
1
|
928
|
my $self = shift; |
22
|
4
|
|
|
|
|
12
|
my $key = shift; |
23
|
4
|
|
|
|
|
19
|
return $self->{vars}->{$key}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub set { |
27
|
2
|
|
|
2
|
1
|
199
|
my $self = shift; |
28
|
2
|
|
|
|
|
4
|
%{$self->{vars}} = (%{$self->{vars}}, @_); |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
9
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub expand { |
32
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
33
|
1
|
|
|
|
|
3
|
my $name = shift; |
34
|
1
|
|
|
|
|
4
|
my %local_vars = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
5
|
my $tmpl = $self->new_template($name); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
550
|
my $vars = {%{$self->{vars}}, %local_vars}; |
|
1
|
|
|
|
|
6
|
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
my $output; |
41
|
1
|
|
|
|
|
7
|
my $res = $tmpl->process($name, $vars, \$output); |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
50664
|
die "TemplateError: $name: " . $tmpl->error() unless $res; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
5
|
foreach my $key (keys %$vars) { |
46
|
1
|
50
|
|
|
|
6
|
next if exists $local_vars{$key}; |
47
|
1
|
|
|
|
|
6
|
$self->{vars}->{$key} = $vars->{$key}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
26
|
return $output; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new_template { |
54
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
55
|
2
|
|
|
|
|
4
|
my $name = shift; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
8
|
my $conf = { |
58
|
|
|
|
|
|
|
INCLUDE_PATH => $self->{tmpl_dirs}, |
59
|
|
|
|
|
|
|
}; |
60
|
2
|
|
|
|
|
28
|
return Template->new($conf); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
WSST::CodeTemplate - CodeTemplate class of WSST |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
CodeTemplate is class encapsulating the Template Toolkit. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 new |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Constructor. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 get |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Returns template variable of the specified name. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 set |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Set template variable. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 expand |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Expand the specified template file. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 new_template |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Create new Template object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
http://code.google.com/p/wsst/ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHORS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Mitsuhisa Oshikawa |
100
|
|
|
|
|
|
|
Yusuke Kawasaki |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Copyright 2008 WSS Project Team |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
1; |