blib/lib/HTML/CallJS.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 96.6% 29 / 30 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package HTML::CallJS;
2 3 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = "0.02";
7  
8 3 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our @EXPORT = qw(call_js);
13  
14 3 my $JSON = JSON::XS->new()->ascii(1)->allow_nonref();
15  
16 3 my %_ESCAPE = (
17 '+' => '\\u002b', # do not eval as UTF-7
18 '&' => '\\u0026',
19 '<' => '\\u003c', # do not eval as HTML
20 '>' => '\\u003e', # ditto.
21 );
22  
23 3 ▶sub call_js {
Subroutine call_js: called CC=1 SCAR=0.0
Pod undocumented
24 3 my ($func, $data) = @_;
25  
26 3 my $json = $JSON->encode($data);
27 3 $json =~ s!([&+<>])!$_ESCAPE{$1}!g;
28  
29 3 join('',
30 q{<script class="call_js" type="text/javascript">},
31 $func,
32 '(',
33 $json,
34 ')',
35 q{</script>}
36 );
37 }
38  
39  
40 3 1;
41 __END__
↑ Summary