blib/lib/URI/Escape/XS.pm

filter: Statementstmt 66.2% 47 / 71 Branchbran 68.7% 11 / 16 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 63.6% 7 / 11 Podpod 100% 2 / 2 totaltotal 59.8% 67 / 112 CC 11 SCAR 15.0
CC
11
Cov
61%
uri_escape
6.2
__ANON__
6.0
__ANON__
6.0
CRAP 4.5
↑ Summary XS.xs »
1 package URI::Escape::XS;
2 #
3 # $Id: XS.pm,v 0.15 2026/11/10 15:10:37 dankogai Exp $
4 #
5 8 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 our $VERSION = '0.15';
9  
10 8 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 our @EXPORT = qw(encodeURIComponent decodeURIComponent
12 encodeURIComponentIDN decodeURIComponentIDN);
13 8 our @EXPORT_OK = qw(uri_escape uri_unescape);
14  
15 8 require XSLoader;
16 8 XSLoader::load('URI::Escape::XS', $VERSION);
17  
18  
19 2 ▶sub uri_unescape {
Subroutine uri_unescape: called CC=2 SCAR=6.9
Pod documented
20 wantarray
21 2 ▶ ? map { decodeURIComponent($_) } @_
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
22 : decodeURIComponent(shift)
23 }
24  
25 {
26 8 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 8 my %escapes = map { chr($_) => sprintf("%%%02X", $_) } (0..255);
28 8 my %regexp;
29 7 ▶ sub uri_escape {
Subroutine uri_escape: called CC=6 SCAR=18.3
Pod documented
30 7 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 7 7
31 7 my ($text, $patn) = @_;
32 7 ▶ return undef unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 1 6 7
33 6 $text .= ''; # RT#39344 -- force string
34 6 ▶ if (defined $patn){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $patn) { } 1 5 6
35 1 ▶ unless (exists $regexp{$patn}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $regexp{$patn}) 1 0 1
36 1 my $re;
37 1 eval {
38 1 $re = qr/[$patn]/;
39 };
40 1 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
41 0 require Carp;
42 0 Carp::croak(__PACKAGE__, $@);
43 }
44 1 $regexp{$patn} = $re;
45 }
46 1 $text =~ s/($regexp{$patn})/$escapes{$1}/ge;
47 1 return $text;
48 } else {
49 5 return _uri_escape($text);
50 }
51 }
52 }
53  
54  
55 8 eval { require Net::LibIDN };
56 8 ▶if ( !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@) { } 0 8 8
57 0 require Encode;
58 0 ▶ *decodeURIComponentIDN = sub ($) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
59 0 my $uri = Encode::decode_utf8( decodeURIComponent(shift) );
60 0 $uri =~ s{\A (https?://)([^/:]+)(:[\d]+)?(.*) }
61 {
62 0 ▶ $1
Condition0%0/2
$3 || ''
l!l
00
MC/DC0%0/1
$3 || ''
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
63 . Encode::decode_utf8(
64 Net::LibIDN::idn_to_unicode($2, 'utf-8')
65 )
66 . ($3||'')
67 . $4;
68 }msex;
69 0 return $uri;
70 0 };
71  
72 0 ▶ *encodeURIComponentIDN = sub ($) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
73 0 my $uri = shift;
74 0 $uri =~ s{\A (https?)://([^/:]+)(:[\d]+)?(.*) }
75 {
76 0 ▶ $1 . ":%2F%2F"
Condition0%0/2
$3 || ''
l!l
00
MC/DC0%0/1
$3 || ''
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
77 . Net::LibIDN::idn_to_ascii($2, 'utf-8') . ($3||'')
78 . encodeURIComponent($4);
79 }msex;
80 0 return $uri;
81 0 };
82  
83 }
84 else {
85 8 eval { require Net::IDN::Encode };
86 8 ▶ if ( !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 8 8
87 0 require Encode;
88 0 ▶ *decodeURIComponentIDN = sub ($) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
89 0 my $uri = Encode::decode_utf8( decodeURIComponent(shift) );
90 0 $uri =~ s{\A (https?://)([^/:]+)(:[\d]+)?(.*) }
91 {
92 0 ▶ $1
Condition0%0/2
$3 || ''
l!l
00
MC/DC0%0/1
$3 || ''
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
93 . Net::IDN::Encode::domain_to_unicode($2) . ($3||'')
94 . $4;
95 }msex;
96 0 return $uri;
97 0 };
98  
99 0 ▶ *encodeURIComponentIDN = sub ($) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
100 0 my $uri = shift;
101 0 $uri =~ s{\A (https?)://([^/:]+)(:[\d]+)?(.*) }
102 {
103 0 ▶ $1 . ":%2F%2F"
Condition0%0/2
$3 || ''
l!l
00
MC/DC0%0/1
$3 || ''
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
104 . Net::IDN::Encode::domain_to_ascii($2) . ($3||'')
105 . encodeURIComponent($4);
106 }msex;
107 0 return $uri;
108 0 };
109 }
110 }
111 8 1;
112 __END__
↑ Summary XS.xs »