line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Recall::Base;
|
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
29
|
use strict;
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
145
|
|
4
|
4
|
|
|
4
|
|
20
|
no warnings;
|
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1515
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION='0.08';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub render {
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
0
|
12
|
my ( $class, $template, $hash_ref, $delims ) = @_;
|
13
|
|
|
|
|
|
|
|
14
|
8
|
50
|
|
|
|
14
|
if ( not defined ($template) ) {
|
15
|
0
|
|
|
|
|
0
|
die "Template::Recall::Base::render() 'template' parameter not present";
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
|
18
|
8
|
50
|
33
|
|
|
51
|
my $user_delims = ref $delims && $#{$delims} == 1 ? 1 : 0;
|
19
|
|
|
|
|
|
|
|
20
|
8
|
50
|
|
|
|
18
|
if (ref $hash_ref) {
|
21
|
|
|
|
|
|
|
|
22
|
8
|
|
|
|
|
35
|
while ( my ($key, $value) = each %$hash_ref) {
|
23
|
8
|
50
|
|
|
|
24
|
if ( $user_delims ) {
|
24
|
8
|
|
|
|
|
24
|
my $d = $delims->[0] . '\s*' . $key . '\s*' . $delims->[1];
|
25
|
8
|
|
|
|
|
141
|
$template =~ s/$d/$value/g;
|
26
|
|
|
|
|
|
|
}
|
27
|
|
|
|
|
|
|
else { # exactly specified delims
|
28
|
0
|
|
|
|
|
0
|
$template =~ s/$key/$value/g;
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
} # while
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} # if
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Do trimming, if so flagged
|
36
|
8
|
100
|
|
|
|
26
|
return trim($class->{'trim'}, $template) if defined $class->{'trim'};
|
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
33
|
return $template;
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} # render()
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Trim output if specified
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub trim {
|
48
|
4
|
|
|
4
|
0
|
5
|
my ($trim, $template) = @_;
|
49
|
|
|
|
|
|
|
|
50
|
4
|
50
|
|
|
|
7
|
return $template if !defined($trim);
|
51
|
|
|
|
|
|
|
|
52
|
4
|
100
|
66
|
|
|
20
|
if ($trim eq 'left' or $trim eq 'l') {
|
53
|
1
|
|
|
|
|
3
|
$template =~ s/^\s+//g;
|
54
|
1
|
|
|
|
|
4
|
return $template;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
3
|
100
|
66
|
|
|
11
|
if ($trim eq 'right' or $trim eq 'r') {
|
58
|
1
|
|
|
|
|
4
|
$template =~ s/\s+$//g;
|
59
|
1
|
|
|
|
|
4
|
return $template;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
2
|
50
|
33
|
|
|
11
|
if ($trim eq 'both' or $trim eq 'b') {
|
63
|
2
|
|
|
|
|
9
|
$template =~ s/^\s+|\s+$//g;
|
64
|
2
|
|
|
|
|
7
|
return $template;
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} # trim()
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1;
|