line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Tmpl; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
622581
|
use strict; |
|
24
|
|
|
|
|
59
|
|
|
24
|
|
|
|
|
1473
|
|
4
|
24
|
|
|
24
|
|
140
|
use warnings; |
|
24
|
|
|
|
|
49
|
|
|
24
|
|
|
|
|
1006
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
135
|
use constant TEMPLATE_TRUE => '1'; |
|
24
|
|
|
|
|
51
|
|
|
24
|
|
|
|
|
2331
|
|
7
|
24
|
|
|
24
|
|
130
|
use constant TEMPLATE_FALSE => '0'; |
|
24
|
|
|
|
|
40
|
|
|
24
|
|
|
|
|
3466
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.33'; |
10
|
|
|
|
|
|
|
|
11
|
24
|
|
|
24
|
|
137
|
use Exporter; |
|
24
|
|
|
|
|
50
|
|
|
24
|
|
|
|
|
11668
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require DynaLoader; |
14
|
|
|
|
|
|
|
require AutoLoader; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(DynaLoader Exporter); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw(TEMPLATE_TRUE |
19
|
|
|
|
|
|
|
TEMPLATE_FALSE); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
bootstrap Text::Tmpl $VERSION; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
############################################################################### |
26
|
|
|
|
|
|
|
## new |
27
|
|
|
|
|
|
|
## Purpose: |
28
|
|
|
|
|
|
|
## Provide a more familiar constructor for OO Perl people |
29
|
|
|
|
|
|
|
## Usage: |
30
|
|
|
|
|
|
|
## $context = new Text::Tmpl; |
31
|
|
|
|
|
|
|
## Return Values: |
32
|
|
|
|
|
|
|
## Returns a context object (as created by Text::Tmpl::init() |
33
|
|
|
|
|
|
|
############################################################################### |
34
|
|
|
|
|
|
|
sub new { |
35
|
122
|
|
50
|
122
|
1
|
115999
|
my $class = shift || return undef; |
36
|
|
|
|
|
|
|
|
37
|
122
|
|
33
|
|
|
540
|
$class = ref($class) || $class; |
38
|
|
|
|
|
|
|
|
39
|
122
|
|
|
|
|
7984
|
my $self = Text::Tmpl::init(); |
40
|
122
|
50
|
|
|
|
1152
|
if (! $self) { |
41
|
0
|
|
|
|
|
0
|
return undef; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
122
|
|
|
|
|
221
|
bless($self, $class); |
45
|
122
|
|
|
|
|
307
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
### end new ################################################################### |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
############################################################################### |
51
|
|
|
|
|
|
|
## new |
52
|
|
|
|
|
|
|
## Purpose: |
53
|
|
|
|
|
|
|
## Backwards-compatibility with versions prior to 0.22 - don't use it! |
54
|
|
|
|
|
|
|
## Usage: |
55
|
|
|
|
|
|
|
## $template->destroy(); |
56
|
|
|
|
|
|
|
## Return Values: |
57
|
|
|
|
|
|
|
## None |
58
|
|
|
|
|
|
|
############################################################################### |
59
|
|
|
|
|
|
|
sub destroy { |
60
|
1
|
|
|
1
|
0
|
485
|
my $self = shift; |
61
|
1
|
|
|
|
|
6
|
$self->DESTROY(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
### end DESTROY ############################################################### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
############################################################################### |
67
|
|
|
|
|
|
|
## set_values |
68
|
|
|
|
|
|
|
## Purpose: |
69
|
|
|
|
|
|
|
## Load a hash table into a template |
70
|
|
|
|
|
|
|
## Usage: |
71
|
|
|
|
|
|
|
## $context->set_values({ 'var1' => 'value1', |
72
|
|
|
|
|
|
|
## 'var2' => 'value2' }); |
73
|
|
|
|
|
|
|
## Return Values: |
74
|
|
|
|
|
|
|
## Returns 1 on success, 0 on failure. |
75
|
|
|
|
|
|
|
############################################################################### |
76
|
|
|
|
|
|
|
sub set_values { |
77
|
5
|
|
|
5
|
1
|
4910
|
my $self = shift; |
78
|
5
|
50
|
|
|
|
33
|
if (! ref $self) { |
79
|
0
|
|
|
|
|
0
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
5
|
|
|
|
|
10
|
my($hashref) = shift; |
82
|
5
|
100
|
|
|
|
18
|
if ((ref $hashref) ne 'HASH') { |
83
|
1
|
|
|
|
|
3
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
4
|
|
|
|
|
7
|
foreach my $key (keys %{$hashref}) { |
|
4
|
|
|
|
|
444
|
|
87
|
2505
|
|
|
|
|
3043
|
my $ret = 1; |
88
|
2505
|
100
|
|
|
|
4896
|
if (defined $hashref->{$key}) { |
89
|
2504
|
|
|
|
|
7489
|
$ret = $self->set_value($key, $hashref->{$key}); |
90
|
|
|
|
|
|
|
} |
91
|
2505
|
50
|
|
|
|
4937
|
if (! $ret) { |
92
|
0
|
|
|
|
|
0
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
4
|
|
|
|
|
353
|
return 1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
### end set_values ############################################################ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |