line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amazon::API::Template; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
759
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
111
|
|
4
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
127
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
459
|
use parent qw( Exporter ); |
|
4
|
|
|
|
|
315
|
|
|
4
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK |
9
|
|
|
|
|
|
|
= qw( to_template_var fetch_template render_template html2pod ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [@EXPORT_OK] ); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
871
|
use Amazon::API::Constants qw(:chars :booleans); |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
804
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
28
|
use ReadonlyX; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
195
|
|
16
|
4
|
|
|
4
|
|
2615
|
use Pod::HTML2Pod; |
|
4
|
|
|
|
|
171667
|
|
|
4
|
|
|
|
|
54
|
|
17
|
4
|
|
|
4
|
|
869
|
use English qw(-no_match_vars); |
|
4
|
|
|
|
|
1660
|
|
|
4
|
|
|
|
|
34
|
|
18
|
4
|
|
|
4
|
|
1484
|
use Fcntl qw(:seek); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
2150
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Readonly::Scalar my $TEMPLATE_DELIMITER => q{@}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
######################################################################## |
23
|
|
|
|
|
|
|
sub to_template_var { |
24
|
|
|
|
|
|
|
######################################################################## |
25
|
2
|
|
|
2
|
0
|
1356
|
my (@vars) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @template_vars |
28
|
2
|
|
|
|
|
5
|
= map { $TEMPLATE_DELIMITER . $_ . $TEMPLATE_DELIMITER } @vars; |
|
3
|
|
|
|
|
9
|
|
29
|
|
|
|
|
|
|
|
30
|
2
|
100
|
|
|
|
9
|
return wantarray ? @template_vars : $template_vars[0]; |
31
|
|
|
|
|
|
|
} ## end sub to_template_var |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
######################################################################## |
34
|
|
|
|
|
|
|
sub fetch_template { |
35
|
|
|
|
|
|
|
######################################################################## |
36
|
0
|
|
|
0
|
0
|
|
my ( $fh, $template_start ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
seek $fh, $template_start, SEEK_SET; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $template; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
local $RS = undef; |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$template = <$fh>; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return $template; |
48
|
|
|
|
|
|
|
} ## end sub fetch_template |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
######################################################################## |
51
|
|
|
|
|
|
|
sub render_template { |
52
|
|
|
|
|
|
|
######################################################################## |
53
|
0
|
|
|
0
|
0
|
|
my ( $template, $parameters ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
foreach my $p ( keys %{$parameters} ) { |
|
0
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
next if $p !~ /^$TEMPLATE_DELIMITER/xsm; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
0
|
|
|
|
my $val = $parameters->{$p} || $EMPTY; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
while ( $template =~ s/$p/$val/xsm ) { } |
61
|
|
|
|
|
|
|
} ## end foreach my $p ( keys %{$parameters...}) |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $template; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
######################################################################## |
67
|
|
|
|
|
|
|
sub html2pod { |
68
|
|
|
|
|
|
|
######################################################################## |
69
|
0
|
|
|
0
|
0
|
|
my ($html) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
0
|
|
|
|
my $pod = Pod::HTML2Pod::convert( |
72
|
|
|
|
|
|
|
a_href => $TRUE, |
73
|
|
|
|
|
|
|
a_name => $TRUE, |
74
|
|
|
|
|
|
|
content => $html // $EMPTY, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$pod =~ s/^=pod//xsm; |
78
|
0
|
|
|
|
|
|
$pod =~ s/^=cut//xsm; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$pod =~ s/^\#.*$//gxsm; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$pod = "\n$pod\n"; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$pod =~ s/\A\n+/\n/xsm; |
85
|
0
|
|
|
|
|
|
$pod =~ s/\n+\z/\n/xsm; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $pod; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |