Sling/URL.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 100% 77 / 77 CC 10 SCAR 10.2
CC
10
Cov
100%
properties_array_to_string
4.0
url_input_sanitize
4.0
add_leading_slash
3.0
CRAP 2.8
« Sling/ContentUtil.pm ↑ Summary Sling/JsonQueryServlet.pm »
1 #!/usr/bin/perl -w
2  
3 package Apache::Sling::URL;
4  
5 17 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 require Exporter;
10  
11 17 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 17 our @EXPORT_OK = ();
14  
15 17 our $VERSION = '0.27';
16  
17 #{{{sub add_leading_slash
18  
19 3 ▶sub add_leading_slash {
Subroutine add_leading_slash: called CC=3 SCAR=11.0
Pod documented
20 3 my ($value) = @_;
21 3 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 1 3
22 2 ▶ if ( $value !~ /^\//msx ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ m[^/]msx) 1 1 2
23 1 $value = "/$value";
24 }
25 }
26 3 return ($value);
27 }
28  
29 #}}}
30  
31 #{{{sub strip_leading_slash
32  
33 8 ▶sub strip_leading_slash {
Subroutine strip_leading_slash: called CC=2 SCAR=6.9
Pod documented
34 8 my ($value) = @_;
35 8 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 6 8
36 2 $value =~ s/^\///msx;
37 }
38 8 return ($value);
39 }
40  
41 #}}}
42  
43 #{{{sub properties_array_to_string
44  
45 12 ▶sub properties_array_to_string {
Subroutine properties_array_to_string: called CC=4 SCAR=13.9
Pod documented
46 12 my ($properties) = @_;
47 12 my $property_post_vars;
48 12 foreach my $property ( @{$properties} ) {
49  
50 # Escaping single quotes:
51 16 $property =~ s/'/\\'/gmsx;
52 16 $property =~ /^([^=]*)=(.*)/msx;
53 16 ▶ if ( defined $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 8 8 16
54 8 $property_post_vars .= "'$1','$2',";
55 }
56 }
57 12 ▶ if ( defined $property_post_vars ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $property_post_vars) { } 7 5 12
58 7 $property_post_vars =~ s/,$//msx;
59 }
60 else {
61 5 $property_post_vars = q{};
62 }
63 12 return $property_post_vars;
64 }
65  
66 #}}}
67  
68 #{{{sub urlencode
69  
70 1 ▶sub urlencode {
Subroutine urlencode: called CC=1 SCAR=0.0
Pod documented
71 1 my ($value) = @_;
72 1 $value =~
73 5 s/([^a-zA-Z_0-9 ])/"%" . uc(sprintf "%lx" , unpack("C", $1))/egmsx;
74 1 $value =~ tr/ /+/;
75 1 return ($value);
76 }
77  
78 #}}}
79  
80 #{{{sub url_input_sanitize
81  
82 18 ▶sub url_input_sanitize {
Subroutine url_input_sanitize: called CC=4 SCAR=13.9
Pod documented
83 18 my ($url) = @_;
84 18 ▶ $url = ( defined $url ? $url : 'http://localhost:8080' );
Branch: 1 branch
BranchTrueFalseTotal
defined $url ? : 3 15 18
85 18 ▶ $url = ( $url ne q{} ? $url : 'http://localhost:8080' );
Branch: 1 branch
BranchTrueFalseTotal
$url ne '' ? : 17 1 18
86 18 $url =~ s/(.*)\/$/$1/msx;
87 18 ▶ $url = ( $url !~ /^http/msx ? "http://$url" : "$url" );
Branch: 1 branch
BranchTrueFalseTotal
!($url =~ /^http/msx) ? : 1 17 18
88 18 return ($url);
89 }
90  
91 #}}}
92  
93 17 1;
94  
95 __END__
« Sling/ContentUtil.pm ↑ Summary Sling/JsonQueryServlet.pm »