Template/Runtime.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.9% 10 / 11 Podpod 100% 6 / 6 totaltotal 86.6% 52 / 60 CC 3 SCAR 4.4
CC
3
Cov
88%
make_map
3.1
escapeXML
2.0
BEGIN
1.0
CRAP 1.6
« Template/JSAdapter/JE.pm ↑ Summary Template/Parser.pm »
1 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 EJS::Template::Runtime - Default functions that can be invoked from JavaScript
8  
9 =cut
10  
11 package EJS::Template::Runtime;
12 8 ▶use base 'EJS::Template::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 our @EJS_FUNCTIONS = qw(
17 concat
18 escapeHTML
19 escapeXML
20 escapeURI
21 escapeQuote
22 );
23  
24 8 our %ESCAPES = qw(
25 raw concat
26 html escapeHTML
27 xml escapeXML
28 uri escapeURI
29 quote escapeQuote
30 );
31  
32 =head1 Methods
33  
34 =head2 make_map
35  
36 =cut
37  
38 63 ▶sub make_map {
Subroutine make_map: called CC=3 SCAR=11.2
Pod documented
39 63 my ($self) = @_;
40 63 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
6300
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
41 63 my $map = {};
42
43 63 for my $name (@EJS_FUNCTIONS) {
44 315 $map->{$name} = \&{$class.'::'.$name};
45 }
46
47 63 return $map;
48 }
49  
50 =head2 concat
51  
52 =cut
53  
54 1 ▶sub concat {
Subroutine concat: called CC=1 SCAR=0.0
Pod documented
55 1 return join('', @_);
56 }
57  
58 =head2 escapeHTML
59  
60 =cut
61  
62 8 my $html_map = {
63 '<' => '&lt;',
64 '>' => '&gt;',
65 '"' => '&quot;',
66 "'" => '&#39;',
67 '&' => '&amp;',
68 };
69  
70 2 ▶sub escapeHTML {
Subroutine escapeHTML: called CC=1 SCAR=0.0
Pod documented
71 return join('', map {
72 2 s/([<>&"'])/$html_map->{$1}/g;
73 2 $_;
74 } @_);
75 }
76  
77 =head2 escapeXML
78  
79 =cut
80  
81 8 my $xml_map = {
82 '<' => '&lt;',
83 '>' => '&gt;',
84 '"' => '&quot;',
85 "'" => '&apos;',
86 '&' => '&amp;',
87 };
88  
89 0 ▶sub escapeXML {
Subroutine escapeXML: not called CC=1 SCAR=6.9
Pod documented
90 return join('', map {
91 0 s/([<>&"'])/$xml_map->{$1}/g;
92 0 $_;
93 } @_);
94 }
95  
96 =head2 escapeURI
97  
98 =cut
99  
100 1 ▶sub escapeURI {
Subroutine escapeURI: called CC=1 SCAR=0.0
Pod documented
101 1 return join('', map {uri_escape($_)} @_);
102 }
103  
104 =head2 escapeQuote
105  
106 =cut
107  
108 1 ▶sub escapeQuote {
Subroutine escapeQuote: called CC=1 SCAR=0.0
Pod documented
109 return join('', map {
110 1 s/(["'])/\\$1/g;
111 1 $_;
112 } @_);
113 }
114  
115 =head1 SEE ALSO
116  
117 =over 4
118  
119 =item * L<EJS::Template>
120  
121 =back
122  
123 =cut
124  
125 8 1;
« Template/JSAdapter/JE.pm ↑ Summary Template/Parser.pm »