blib/lib/Poet/Util/Web.pm

filter: Statementstmt 69.2% 27 / 39 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 65.4% 36 / 55 CC 3 SCAR 14.3
CC
3
Cov
63%
make_uri
12.0
html_escape
2.0
js_escape
2.0
CRAP 4.2
« blib/lib/Poet/Server.pm ↑ Summary blib/lib/Poet/t/Run.pm »
1 package Poet::Util::Web;
2 3 $Poet::Util::Web::VERSION = '0.16';
3 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use URI::Escape qw(uri_escape uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @EXPORT_OK = qw(html_escape js_escape make_uri uri_escape uri_unescape);
11 3 our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
12  
13 3 my %html_escape = ( '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' );
14 3 my $html_escape = qr/([&<>"])/;
15  
16 # Stolen from Javascript::Value::Escape
17 3 my %js_escape = (
18 q!\\! => 'u005c',
19 q!"! => 'u0022',
20 q!'! => 'u0027',
21 q!<! => 'u003c',
22 q!>! => 'u003e',
23 q!&! => 'u0026',
24 q!=! => 'u003d',
25 q!-! => 'u002d',
26 q!;! => 'u003b',
27 q!+! => 'u002b',
28 "\x{2028}" => 'u2028',
29 "\x{2029}" => 'u2029',
30 );
31 3 map { $js_escape{ pack( 'U', $_ ) } = sprintf( "u%04d", $_ ) } ( 0x00 .. 0x1f, 0x7f );
32  
33 0 ▶sub html_escape {
Subroutine html_escape: not called CC=1 SCAR=6.9
Pod documented
34 0 my $text = $_[0];
35 0 $text =~ s/$html_escape/$html_escape{$1}/mg;
36 0 return $text;
37 }
38  
39 0 ▶sub js_escape {
Subroutine js_escape: not called CC=1 SCAR=6.9
Pod documented
40 0 my $text = shift;
41 0 $text =~ s!([\\"'<>&=\-;\+\x00-\x1f\x7f]|\x{2028}|\x{2029})!\\$js_escape{$1}!g;
42 0 return $text;
43 }
44  
45 0 ▶sub make_uri {
Subroutine make_uri: not called CC=3 SCAR=24.8
Pod documented
46 0 my ( $base, $params ) = @_;
47  
48 0 my $uri = URI->new($base);
49 0 ▶ if ( defined($params) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 0 0
50 0 ▶ die "second argument must be a hashref" if ref($params) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params ne "HASH" 0 0 0
51 0 $uri->query_form($params);
52 }
53 0 return $uri->as_string;
54 }
55  
56 3 1;
57  
58 __END__
« blib/lib/Poet/Server.pm ↑ Summary blib/lib/Poet/t/Run.pm »