line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plain; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
217837
|
use 5.006000; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
315
|
|
4
|
8
|
|
|
8
|
|
51
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
275
|
|
5
|
8
|
|
|
8
|
|
56
|
use warnings; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
5706
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# XXXXX |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $default; # Holds the default template object when class methods are used. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
8
|
|
|
8
|
1
|
1031
|
my $class = shift; |
15
|
8
|
|
66
|
|
|
42
|
my $content = shift || _PT_default_content(); |
16
|
8
|
|
|
|
|
56
|
my $self = { |
17
|
|
|
|
|
|
|
'_delims' => [qw/ <% %> /], |
18
|
|
|
|
|
|
|
'_content' => $content, |
19
|
|
|
|
|
|
|
'_listsep' => "\n", |
20
|
|
|
|
|
|
|
}; |
21
|
8
|
|
|
|
|
41
|
bless $self, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub list_separator { |
25
|
1
|
|
|
1
|
1
|
421
|
my $self = shift; |
26
|
1
|
50
|
0
|
|
|
8
|
if (! ref $self) { $self = $default = $default || __PACKAGE__->new() } |
|
0
|
|
|
|
|
0
|
|
27
|
1
|
50
|
|
|
|
7
|
return @_ ? $self->{_listsep} = shift : $self->{_listsep}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub delimiters { |
31
|
2
|
|
|
2
|
1
|
13
|
my $self = shift; |
32
|
2
|
50
|
0
|
|
|
8
|
if (! ref $self) { $self = $default = $default || __PACKAGE__->new() } |
|
0
|
|
|
|
|
0
|
|
33
|
2
|
100
|
|
|
|
15
|
$self->{_delims} = shift if @_ == 1; |
34
|
2
|
100
|
|
|
|
11
|
$self->{_delims} = [shift, shift] if @_ == 2; |
35
|
2
|
|
|
|
|
7
|
return $self->{_delims}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub tags { |
39
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
40
|
1
|
50
|
0
|
|
|
6
|
if (! ref $self) { $self = $default = $default || __PACKAGE__->new() } |
|
0
|
|
|
|
|
0
|
|
41
|
1
|
|
|
|
|
2
|
my ($L, $R) = @{$self->{_delims}}; |
|
1
|
|
|
|
|
6
|
|
42
|
1
|
|
|
|
|
28
|
my @list = $self->{_content} =~ m/\Q$L\E\s*(.*?)\s*\Q$R\E/gm; |
43
|
1
|
|
|
|
|
6
|
return @list; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub fill { |
47
|
11
|
|
|
11
|
1
|
1690
|
my $self = shift; |
48
|
11
|
100
|
33
|
|
|
44
|
if (! ref $self) { $self = $default = $default || __PACKAGE__->new() } |
|
1
|
|
|
|
|
9
|
|
49
|
11
|
|
|
|
|
20
|
my $args = shift; |
50
|
11
|
|
|
|
|
21
|
my $replace = shift; |
51
|
11
|
|
|
|
|
17
|
my ($L, $R) = @{$self->{_delims}}; |
|
11
|
|
|
|
|
48
|
|
52
|
11
|
|
|
|
|
28
|
my $text = $self->{_content}; |
53
|
11
|
|
|
|
|
344
|
$text =~ s/\Q$L\E\s*(.*?)\s*\Q$R\E/$self->_expand($1,$args)/egm; |
|
12
|
|
|
|
|
52
|
|
54
|
11
|
100
|
|
|
|
53
|
$self->{_content} = $text if $replace; |
55
|
11
|
|
|
|
|
41
|
return \$text; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Private Methods |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _expand { |
62
|
12
|
|
|
12
|
|
29
|
my $self = shift; |
63
|
12
|
|
|
|
|
39
|
my ($key, $hashr) = @_; |
64
|
12
|
|
|
|
|
30
|
my $value = $hashr->{$key}; |
65
|
|
|
|
|
|
|
|
66
|
12
|
50
|
|
|
|
53
|
return '' unless defined $value; |
67
|
|
|
|
|
|
|
|
68
|
12
|
|
|
|
|
35
|
for (ref $value) { |
69
|
12
|
100
|
|
|
|
41
|
/CODE/ and do { return $value->() }; |
|
1
|
|
|
|
|
5
|
|
70
|
11
|
100
|
|
|
|
38
|
/ARRAY/ and do { return join $self->{_listsep}, @$value }; |
|
2
|
|
|
|
|
15
|
|
71
|
9
|
50
|
|
|
|
29
|
/SCALAR/ and do { return $$value }; |
|
0
|
|
|
|
|
0
|
|
72
|
9
|
50
|
|
|
|
47
|
/^$/ and do { return $value }; |
|
9
|
|
|
|
|
52
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Private class methods |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _PT_default_content { |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
2
|
|
5
|
my $FH; |
83
|
2
|
|
|
|
|
7
|
my $pkg = caller; |
84
|
|
|
|
|
|
|
|
85
|
8
|
|
|
8
|
|
54
|
no strict 'refs'; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
1304
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# if DATA exists in the calling package use that. |
88
|
2
|
50
|
33
|
|
|
4
|
if ( exists ${ $pkg . '::' }{DATA} and defined *{${$pkg . '::'}{DATA}}{IO}) { |
|
2
|
50
|
33
|
|
|
36
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
89
|
0
|
|
|
|
|
0
|
$FH = *{${$pkg . '::'}{DATA}}{IO}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# else if DATA exists in main, use that. |
92
|
|
|
|
|
|
|
} elsif ( exists $main::{DATA} and defined *main::DATA{IO} ){ |
93
|
2
|
|
|
|
|
7
|
$FH = *main::DATA{IO}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# else use <> |
96
|
|
|
|
|
|
|
} else { |
97
|
0
|
|
|
|
|
0
|
$FH = \*ARGV; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
4
|
do { undef $/; <$FH> }; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
97
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
################################################################################ |
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |