API/Template.pm

filter: Statementstmt 67.2% 41 / 61 Branchbran 33.3% 2 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 4 totaltotal 57.2% 55 / 96 CC 7 SCAR 17.3
CC
7
Cov
59%
render_template
20.0
fetch_template
6.0
html2pod
6.0
CRAP 5.7
« API/EndpointContext/Compiler.pm ↑ Summary API/BuildInfo.pm »
1 package Amazon::API::Template;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Amazon::API::Constants qw(:chars :booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Amazon::API::Utils qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Pod::HTML2Pod;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Fcntl qw(:seek);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 Readonly::Scalar my $TEMPLATE_DELIMITER => q{@};
16  
17 1 ▶use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our @EXPORT_OK = qw( to_template_var fetch_template render_template html2pod );
20  
21 1 our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
22  
23 ########################################################################
24 2 ▶sub to_template_var {
Subroutine to_template_var: called CC=2 SCAR=6.9
Pod undocumented
25 ########################################################################
26 2 my (@vars) = @_;
27  
28 2 my @template_vars = map { $TEMPLATE_DELIMITER . $_ . $TEMPLATE_DELIMITER } @vars;
29  
30 2 ▶ return wantarray ? @template_vars : $template_vars[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
31 }
32  
33 ########################################################################
34 0 ▶sub fetch_template {
Subroutine fetch_template: not called CC=2 SCAR=17.9
Pod undocumented
35 ########################################################################
36 0 my ( $fh, $template_start ) = @_;
37  
38 0 ▶ if ( defined $template_start ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $template_start) 0 0 0
39 0 seek $fh, $template_start, SEEK_SET;
40 }
41  
42 0 return slurp($fh);
43 }
44  
45 ########################################################################
46 0 ▶sub render_template {
Subroutine render_template: not called CC=4 SCAR=30.0
Pod undocumented
47 ########################################################################
48 0 my ( $template, $parameters ) = @_;
49  
50 0 foreach my $p ( keys %{$parameters} ) {
51  
52 0 ▶ next if $p !~ /^$TEMPLATE_DELIMITER/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ /^$TEMPLATE_DELIMITER/msx 0 0 0
53  
54 0 ▶ my $val = $parameters->{$p} || $EMPTY;
Condition0%0/3
$parameters->{$p} || $Amazon::API::Template::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$parameters->{$p} || $Amazon::API::Template::EMPTY
$parameters->{$p} $Amazon::API::Template::EMPTY
Truth table0%0/3
A || B
A= $parameters->{$p}B= $Amazon::API::Template::EMPTY
ABresult
1X1
011
000
55  
56 0 $template =~ s/$p/$val/xsmg;
57 }
58  
59 0 return $template;
60 }
61  
62 ########################################################################
63 0 ▶sub html2pod {
Subroutine html2pod: not called CC=2 SCAR=17.9
Pod undocumented
64 ########################################################################
65 0 my ($html) = @_;
66  
67 0 ▶ my $pod = Pod::HTML2Pod::convert(
Condition0%0/3
$html // $Amazon::API::Template::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$html // $Amazon::API::Template::EMPTY
$html $Amazon::API::Template::EMPTY
Truth table0%0/3
A // B
A= $htmlB= $Amazon::API::Template::EMPTY
ABresult
1X1
011
000
68 a_href => $TRUE,
69 a_name => $TRUE,
70 content => $html // $EMPTY,
71 );
72  
73 0 $pod =~ s/^=pod//xsm;
74 0 $pod =~ s/^=cut//xsm;
75  
76 0 $pod =~ s/^\#.*$//gxsm;
77  
78 0 $pod = "\n$pod\n";
79  
80 0 $pod =~ s/\A\n+/\n/xsm;
81 0 $pod =~ s/\n+\z/\n/xsm;
82  
83 0 return $pod;
84 }
85  
86 1 1;
87  
88 __END__
« API/EndpointContext/Compiler.pm ↑ Summary API/BuildInfo.pm »