URI.pm

filter: Statementstmt 96.2% 206 / 214 Branchbran 85.4% 82 / 96 Conditioncond 74.1% 23 / 31 MC/DCmcdc 42.1% 8 / 19 Subroutinesub 94.4% 34 / 36 Podpod 78.9% 15 / 19 totaltotal 88.6% 368 / 415 CC 60 SCAR 18.1
CC
60
Cov
91%
_scheme
13.5
implementor
10.4
new
8.1
CRAP 6.1
« URI/urn/isbn.pm ↑ Summary URI/file/Unix.pm »
1 package URI;
2  
3 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 59 our $VERSION = '5.40';
7  
8 # 1=version 5.10 and earlier; 0=version 5.11 and later
9 59 ▶use constant HAS_RESERVED_SQUARE_BRACKETS =>
Subroutine BEGIN: called CC=2 SCAR=6.9
10 59 ▶ $ENV{URI_HAS_RESERVED_SQUARE_BRACKETS} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'URI_HAS_RESERVED_SQUARE_BRACKETS'} ? : 1 58 59
11  
12 59 our ($ABS_REMOTE_LEADING_DOTS, $ABS_ALLOW_RELATIVE_SCHEME,
13 $DEFAULT_QUERY_FORM_DELIMITER);
14  
15 59 my %implements; # mapping from scheme to implementor class
16  
17 # Some "official" character classes
18  
19 59 our $reserved = HAS_RESERVED_SQUARE_BRACKETS ? q(;/?:@&=+$,[]) : q(;/?:@&=+$,);
20 59 our $mark = q(-_.!~*'()); #'; emacs
21 59 our $unreserved = "A-Za-z0-9\Q$mark\E";
22 59 our $uric = quotemeta($reserved) . $unreserved . "%";
23 59 our $uric4host = $uric . (HAS_RESERVED_SQUARE_BRACKETS ? '' : quotemeta(q([])));
24 59 our $uric4user
25 = quotemeta(q{!$'()*,;:._~%-+=%&})
26 . "A-Za-z0-9"
27 . (HAS_RESERVED_SQUARE_BRACKETS ? quotemeta(q([])) : '')
28 ; # RFC-3987: iuserinfo w/o UTF
29  
30 59 our $scheme_re = '[a-zA-Z][a-zA-Z0-9.+\-]*';
31  
32 # These schemes don't have an IPv6+ address part.
33 59 our $schemes_without_host_part_re = 'data|ldapi|urn|sqlite|sqlite3';
34  
35 # These schemes can have an IPv6+ authority part:
36 # file, ftp, gopher, http, https, ldap, ldaps, mms, news, nntp, nntps, pop, rlogin, rtsp, rtspu, rsync, sip, sips, snews,
37 # smtp, telnet, tn3270, ssh, sftp
38 # (all DB URIs, i.e. cassandra, couch, couchdb, etc.), except 'sqlite:', 'sqlite3:'. Others?
39 #MAINT: URI has no test coverage for DB schemes
40 #MAINT: decoupling - perhaps let each class decide itself by defining a member function 'scheme_has_authority_part()'?
41  
42 #MAINT: 'mailto:' needs special treatment for IPv* addresses / RFC 5321 (4.1.3). Until then: restore all '[', ']'
43 # These schemes need fallback to previous (<= 5.10) encoding until a specific handler is available.
44 59 our $fallback_schemes_re = 'mailto';
45  
46 59 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
47 59 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 59 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
50 693 ▶ '""' => sub { ${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 61 ▶ '==' => sub { _obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 1 ▶ '!=' => sub { !_obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 59 fallback => 1,
54 59 );
55  
56 # Check if two objects are the same object
57 63 ▶sub _obj_eq {
Subroutine _obj_eq: called CC=1 SCAR=0.0
58 63 return overload::StrVal($_[0]) eq overload::StrVal($_[1]);
59 }
60  
61 1335 ▶sub new {
Subroutine new: called CC=8 SCAR=20.9
Pod documented
62 1335 my ($class, $uri, $scheme) = @_;
63  
64 1335 ▶ $uri = defined($uri) ? "$uri" : ""; # stringify
Branch: 1 branch
BranchTrueFalseTotal
defined $uri ? : 1335 0 1335
65 # Get rid of potential wrapping
66 1335 $uri =~ s/^<(?:URL:)?(.*)>$/$1/; #
67 1335 $uri =~ s/^"(.*)"$/$1/;
68 1335 $uri =~ s/^\s+//;
69 1335 $uri =~ s/\s+$//;
70  
71 1335 my $impclass;
72 1335 ▶ if ($uri =~ m/^($scheme_re):/so) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ /^($URI::scheme_re):/so) { } 1038 297 1335
73 1038 $scheme = $1;
74 }
75 else {
76 297 ▶ if (($impclass = ref($scheme))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($impclass = ref $scheme) { } 11 286 297
elsif ($scheme and $scheme =~ /^($URI::scheme_re)(?::|$)/o) { } 142 288 430
77 11 $scheme = $scheme->scheme;
78 }
79 ▶ elsif ($scheme && $scheme =~ m/^($scheme_re)(?::|$)/o) {
Condition66%2/3
$scheme and $scheme =~ /^($URI::scheme_re)(?::|$)/o
!ll&&!rl&&r
1440142
MC/DC50%1/2
$scheme and $scheme =~ /^($URI::scheme_re)(?::|$)/o
$scheme $scheme =~ /^($URI::scheme_re)(?::|$)/o
Truth table66%2/3
A and B
A= $schemeB= $scheme =~ /^($URI::scheme_re)(?::|$)/o
ABresult
0X0
100
111
80 142 $scheme = $1;
81 }
82 }
83 1335 ▶ $impclass ||= implementor($scheme) || do {
Condition66%4/6
$impclass ||= implementor($scheme) || do { require URI::_foreign; $impclass = "URI::_foreign" }
l!l&&r!l&&!r
1113240
implementor($scheme) || do { require URI::_foreign; $impclass = 'URI::_foreign' }
l!l&&r!l&&!r
1279450
MC/DC0%0/3
$impclass ||= implementor($scheme) || do { require URI::_foreign; $impclass = "URI::_foreign" }
$impclass implementor($scheme) do { require URI::_foreign; $impclass = 'URI::_foreign' }
Truth table0%0/4
A ||= B || C
A= $impclassB= implementor($scheme)C= do { require URI::_foreign; $impclass = 'URI::_foreign' }
ABCresult
1XX1
01X1
0011
0000
84 45 require URI::_foreign;
85 45 $impclass = 'URI::_foreign';
86 };
87  
88 1335 return $impclass->_init($uri, $scheme);
89 }
90  
91  
92 1 ▶sub new_abs {
Subroutine new_abs: called CC=1 SCAR=0.0
Pod documented
93 1 my ($class, $uri, $base) = @_;
94 1 $uri = $class->new($uri, $base);
95 1 $uri->abs($base);
96 }
97  
98  
99 1333 ▶sub _init {
Subroutine _init: called CC=3 SCAR=11.2
100 1333 my $class = shift;
101 1333 my ($str, $scheme) = @_;
102  
103 # find all funny characters and encode the bytes.
104 1333 $str = $class->_uric_escape($str);
105 1333 ▶ $str = "$scheme:$str"
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /^$URI::scheme_re:/o or $class->_no_scheme_ok 0 1333 1333
Condition66%2/3
$str =~ /^$URI::scheme_re:/o or $class->_no_scheme_ok
l!l&&r!l&&!r
10382950
MC/DC0%0/2
$str =~ /^$URI::scheme_re:/o or $class->_no_scheme_ok
$str =~ /^$URI::scheme_re:/o $class->_no_scheme_ok
Truth table66%2/3
A or B
A= $str =~ /^$URI::scheme_re:/oB= $class->_no_scheme_ok
ABresult
1X1
011
000
106 unless $str =~ /^$scheme_re:/o || $class->_no_scheme_ok;
107 1333 my $self = bless \$str, $class;
108 1333 $self;
109 }
110  
111  
112 #-- Version: 5.11+
113 # Since the complete URI will be percent-encoded including '[' and ']',
114 # we selectively unescape square brackets from the authority/host part of the URI.
115 # Derived modules that implement _uric_escape() should take this into account
116 # if they do not rely on URI::_uric_escape().
117 # No unescaping is performed for the userinfo@ part of the authority part.
118 1333 ▶sub _fix_uric_escape_for_host_part {
Subroutine _fix_uric_escape_for_host_part: called CC=7 SCAR=19.5
119 1333 return if HAS_RESERVED_SQUARE_BRACKETS;
120 1327 ▶ return if $_[0] !~ /%/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /%/ 1221 106 1327
121 106 ▶ return if $_[0] =~ m{^(?:$URI::schemes_without_host_part_re):}os;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^(?:$URI::schemes_without_host_part_re):/so 4 102 106
122  
123 # until a scheme specific handler is available, fall back to previous behavior of v5.10 (i.e. 'mailto:')
124 102 ▶ if ($_[0] =~ m{^(?:$URI::fallback_schemes_re):}os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^(?:$URI::fallback_schemes_re):/so) 10 92 102
125 10 $_[0] =~ s/\%5B/[/gi;
126 10 $_[0] =~ s/\%5D/]/gi;
127 10 return;
128 }
129  
130 92 ▶ if ($_[0] =~ m{^((?:$URI::scheme_re:)?)//([^/?\#]+)(.*)$}os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ m[^((?:$URI::scheme_re:)?)//([^/?\#]+)(.*)$]so) 59 33 92
131 59 my $orig = $2;
132 59 my ($user, $host) = $orig =~ /^(.*@)?([^@]*)$/;
133 59 ▶ $user ||= '';
Condition100%2/2
$user ||= ""
l!l
1544
MC/DC100%1/1
$user ||= ""
$user
Truth table100%2/2
A
A= $user
Aresult
11
00
134 59 ▶ my $port = $host =~ s/(:\d+)$// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/(:\d+)$// ? : 7 52 59
135  
136 #MAINT: die() here if scheme indicates TCP/UDP and port is out of range [0..65535] ?
137 59 $host =~ s/\%5B/[/gi;
138 59 $host =~ s/\%5D/]/gi;
139 59 $_[0] =~ s/\Q$orig\E/$user$host$port/;
140 }
141 }
142  
143  
144 1333 ▶sub _uric_escape {
Subroutine _uric_escape: called CC=1 SCAR=0.0
145 1333 my ($class, $str) = @_;
146 1333 $str =~ s*([^$uric\#])* URI::Escape::escape_char($1) *ego;
147 1333 _fix_uric_escape_for_host_part($str);
148 1333 utf8::downgrade($str);
149 1333 return $str;
150 }
151  
152 59 my %require_attempted;
153  
154 1324 ▶sub implementor {
Subroutine implementor: called CC=10 SCAR=23.4
Pod undocumented
155 1324 my ($scheme, $impclass) = @_;
156 1324 ▶ if (!$scheme || $scheme !~ /\A$scheme_re\z/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheme and $scheme =~ /\A$URI::scheme_re\z/o) 144 1180 1324
Condition66%2/3
$scheme and $scheme =~ /\A$URI::scheme_re\z/o
!ll&&!rl&&r
14401180
MC/DC50%1/2
$scheme and $scheme =~ /\A$URI::scheme_re\z/o
$scheme $scheme =~ /\A$URI::scheme_re\z/o
Truth table66%2/3
A and B
A= $schemeB= $scheme =~ /\A$URI::scheme_re\z/o
ABresult
0X0
100
111
157 144 require URI::_generic;
158 144 return "URI::_generic";
159 }
160  
161 1180 $scheme = lc($scheme);
162  
163 1180 ▶ if ($impclass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($impclass) 0 1180 1180
164  
165 # Set the implementor class for a given scheme
166 0 my $old = $implements{$scheme};
167 0 $impclass->_init_implementor($scheme);
168 0 $implements{$scheme} = $impclass;
169 0 return $old;
170 }
171  
172 1180 my $ic = $implements{$scheme};
173 1180 ▶ return $ic if $ic;
Branch: 1 branch
BranchTrueFalseTotal
if $ic 1055 125 1180
174  
175 # scheme not yet known, look for internal or
176 # preloaded (with 'use') implementation
177 125 $ic = "URI::$scheme"; # default location
178  
179 # turn scheme into a valid perl identifier by a simple transformation...
180 125 $ic =~ s/\+/_P/g;
181 125 $ic =~ s/\./_O/g;
182 125 $ic =~ s/\-/_/g;
183  
184 59 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
185  
186 # check we actually have one for the scheme:
187 125 ▶ unless (@{"${ic}::ISA"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{"${ic}::ISA";}) 120 5 125
188 120 ▶ if (not exists $require_attempted{$ic}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $require_attempted{$ic}) 84 36 120
189 84 $require_attempted{$ic} = 1;
190  
191 # Try to load it
192 84 my $_old_error = $@;
193 84 eval "require $ic";
194 84 ▶ die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
if $@ and not $@ =~ /Can\'t locate.*in \@INC/ 0 84 84
Condition66%2/3
$@ and not $@ =~ /Can\'t locate.*in \@INC/
!ll&&!rl&&r
7590
MC/DC0%0/2
$@ and not $@ =~ /Can\'t locate.*in \@INC/
$@ not $@ =~ /Can\'t locate.*in \@INC/
Truth table66%2/3
A and not(B)
A= $@B= not $@ =~ /Can\'t locate.*in \@INC/
ABresult
0X0
100
111
195 84 $@ = $_old_error;
196 }
197 120 ▶ return undef unless @{"${ic}::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
unless @{"${ic}::ISA";} 45 75 120
198 }
199  
200 80 $ic->_init_implementor($scheme);
201 80 $implements{$scheme} = $ic;
202 80 $ic;
203 }
204  
205  
206 80 ▶sub _init_implementor {
Subroutine _init_implementor: called CC=1 SCAR=0.0
207 80 my ($class, $scheme) = @_;
208  
209 # Remember that one implementor class may actually
210 # serve to implement several URI schemes.
211 }
212  
213  
214 461 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
215 461 my $self = shift;
216 461 my $other = $$self;
217 461 bless \$other, ref $self;
218 }
219  
220 0 ▶sub TO_JSON { ${$_[0]} }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
221  
222 0 ▶sub _no_scheme_ok {0}
Subroutine _no_scheme_ok: not called CC=1 SCAR=6.9
223  
224 1666 ▶sub _scheme {
Subroutine _scheme: called CC=12 SCAR=26.0
225 1666 my $self = shift;
226  
227 1666 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1313 353 1666
228 1313 ▶ return undef unless $$self =~ /^($scheme_re):/o;
Branch: 1 branch
BranchTrueFalseTotal
unless $$self =~ /^($URI::scheme_re):/o 328 985 1313
229 985 return $1;
230 }
231  
232 353 my $old;
233 353 my $new = shift;
234 353 ▶ if (defined($new) && length($new)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new and length $new) { } 283 70 353
Condition100%3/3
defined $new and length $new
!ll&&!rl&&r
691283
MC/DC100%2/2
defined $new and length $new
defined $new length $new
Truth table100%3/3
A and B
A= defined $newB= length $new
ABresult
0X0
100
111
235 283 ▶ Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o;
Branch: 1 branch
BranchTrueFalseTotal
unless $new =~ /^$URI::scheme_re$/o 0 283 283
236 283 ▶ $old = $1 if $$self =~ s/^($scheme_re)://o;
Branch: 1 branch
BranchTrueFalseTotal
if $$self =~ s/^($URI::scheme_re)://o 24 259 283
237 283 my $newself = URI->new("$new:$$self");
238 283 $$self = $$newself;
239 283 bless $self, ref($newself);
240 }
241 else {
242 70 ▶ if ($self->_no_scheme_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_no_scheme_ok) { } 70 0 70
243 70 ▶ $old = $1 if $$self =~ s/^($scheme_re)://o;
Branch: 1 branch
BranchTrueFalseTotal
if $$self =~ s/^($URI::scheme_re)://o 70 0 70
244 70 ▶ Carp::carp("Oops, opaque part now look like scheme")
Branch: 1 branch
BranchTrueFalseTotal
if $^W and $$self =~ /^$URI::scheme_re:/o 0 70 70
Condition33%1/3
$^W and $$self =~ /^$URI::scheme_re:/o
!ll&&!rl&&r
7000
MC/DC0%0/2
$^W and $$self =~ /^$URI::scheme_re:/o
$^W $$self =~ /^$URI::scheme_re:/o
Truth table33%1/3
A and B
A= $^WB= $$self =~ /^$URI::scheme_re:/o
ABresult
0X0
100
111
245 if $^W && $$self =~ m/^$scheme_re:/o;
246 }
247 else {
248 0 ▶ $old = $1 if $$self =~ m/^($scheme_re):/o;
Branch: 1 branch
BranchTrueFalseTotal
if $$self =~ /^($URI::scheme_re):/o 0 0 0
249 }
250 }
251  
252 353 return $old;
253 }
254  
255 1160 ▶sub scheme {
Subroutine scheme: called CC=2 SCAR=6.9
Pod documented
256 1160 my $scheme = shift->_scheme(@_);
257 1160 ▶ return undef unless defined $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme 524 636 1160
258 636 lc($scheme);
259 }
260  
261 7 ▶sub has_recognized_scheme {
Subroutine has_recognized_scheme: called CC=1 SCAR=0.0
Pod documented
262 7 my $self = shift;
263 7 return ref($self) !~ /^URI::_(?:foreign|generic)\z/;
264 }
265  
266 88 ▶sub opaque {
Subroutine opaque: called CC=7 SCAR=19.5
Pod documented
267 88 my $self = shift;
268  
269 88 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 61 27 88
270 61 ▶ $$self =~ /^(?:$scheme_re:)?([^\#]*)/o or die;
Branch: 1 branch
BranchTrueFalseTotal
$$self =~ /^(?:$URI::scheme_re:)?([^\#]*)/o or die 61 0 61
271 61 return $1;
272 }
273  
274 27 ▶ $$self =~ /^($scheme_re:)? # optional scheme
Branch: 1 branch
BranchTrueFalseTotal
$$self =~ /^($URI::scheme_re:)? # optional scheme ([^\#]*) # opaque (\#.*)? # optional fragment $/sx or die 27 0 27
275 ([^\#]*) # opaque
276 (\#.*)? # optional fragment
277 $/sx or die;
278  
279 27 my $old_scheme = $1;
280 27 my $old_opaque = $2;
281 27 my $old_frag = $3;
282  
283 27 my $new_opaque = shift;
284 27 ▶ $new_opaque = "" unless defined $new_opaque;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new_opaque 1 26 27
285 27 $new_opaque =~ s/([^$uric])/ URI::Escape::escape_char($1)/ego;
286 27 utf8::downgrade($new_opaque);
287  
288 27 ▶ $$self = defined($old_scheme) ? $old_scheme : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $old_scheme ? : 26 1 27
289 27 $$self .= $new_opaque;
290 27 ▶ $$self .= $old_frag if defined $old_frag;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old_frag 5 22 27
291  
292 27 $old_opaque;
293 }
294  
295 2 ▶sub path { goto &opaque } # alias
Subroutine path: called CC=1 SCAR=0.0
Pod documented
296  
297  
298 80 ▶sub fragment {
Subroutine fragment: called CC=5 SCAR=16.1
Pod documented
299 80 my $self = shift;
300 80 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 59 21 80
301 59 ▶ return undef unless $$self =~ /\#(.*)/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $$self =~ /\#(.*)/s 33 26 59
302 26 return $1;
303 }
304  
305 21 my $old;
306 21 ▶ $old = $1 if $$self =~ s/\#(.*)//s;
Branch: 1 branch
BranchTrueFalseTotal
if $$self =~ s/\#(.*)//s 5 16 21
307  
308 21 my $new_frag = shift;
309 21 ▶ if (defined $new_frag) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_frag) 19 2 21
310 19 $new_frag =~ s/([^$uric])/ URI::Escape::escape_char($1) /ego;
311 19 utf8::downgrade($new_frag);
312 19 $$self .= "#$new_frag";
313 }
314 21 $old;
315 }
316  
317  
318 592 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
319 592 my $self = shift;
320 592 $$self;
321 }
322  
323  
324 15 ▶sub as_iri {
Subroutine as_iri: called CC=4 SCAR=13.9
Pod documented
325 15 my $self = shift;
326 15 my $str = $$self;
327 15 ▶ if ($str =~ s/%([89a-fA-F][0-9a-fA-F])/chr(hex($1))/eg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/%([89a-fA-F][0-9a-fA-F])/chr hex $1;/eg) 10 5 15
328  
329 # All this crap because the more obvious:
330 #
331 # Encode::decode("UTF-8", $str, sub { sprintf "%%%02X", shift })
332 #
333 # doesn't work before Encode 2.39. Wait for a standard release
334 # to bundle that version.
335  
336 10 require Encode;
337 10 my $enc = Encode::find_encoding("UTF-8");
338 10 my $u = "";
339 10 ▶ while (length $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 13 10 23
340 13 $u .= $enc->decode($str, Encode::FB_QUIET());
341 13 ▶ if (length $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 3 10 13
342  
343 # escape next char
344 3 $u .= URI::Escape::escape_char(substr($str, 0, 1, ""));
345 }
346 }
347 10 $str = $u;
348 }
349 15 return $str;
350 }
351  
352  
353 495 ▶sub canonical {
Subroutine canonical: called CC=7 SCAR=19.5
Pod documented
354  
355 # Make sure scheme is lowercased, that we don't escape unreserved chars,
356 # and that we use upcase escape sequences.
357  
358 495 my $self = shift;
359 495 ▶ my $scheme = $self->_scheme || "";
Condition100%2/2
$self->_scheme || ''
l!l
43263
MC/DC100%1/1
$self->_scheme || ''
$self->_scheme
Truth table100%2/2
A
A= $self->_scheme
Aresult
11
00
360 495 my $uc_scheme = $scheme =~ /[A-Z]/;
361 495 my $esc = $$self =~ /%[a-fA-F0-9]{2}/;
362 495 ▶ return $self unless $uc_scheme || $esc;
Branch: 1 branch
BranchTrueFalseTotal
unless $uc_scheme or $esc 441 54 495
Condition100%3/3
$uc_scheme or $esc
l!l&&r!l&&!r
1044441
MC/DC100%2/2
$uc_scheme or $esc
$uc_scheme $esc
Truth table100%3/3
A or B
A= $uc_schemeB= $esc
ABresult
1X1
011
000
363  
364 54 my $other = $self->clone;
365 54 ▶ if ($uc_scheme) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uc_scheme) 10 44 54
366 10 $other->_scheme(lc $scheme);
367 }
368 54 ▶ if ($esc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc) 44 10 54
369 44 $$other =~ s{%([0-9a-fA-F]{2})}
370 263 { my $a = chr(hex($1));
371 263 ▶ $a =~ /^[$unreserved]\z/o ? $a : "%\U$1"
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /^[$URI::unreserved]\z/o ? : 115 148 263
372 }ge;
373 }
374 54 return $other;
375 }
376  
377 # Compare two URIs, subclasses will provide a more correct implementation
378 17 ▶sub eq {
Subroutine eq: called CC=4 SCAR=14.2
Pod documented
379 17 my ($self, $other) = @_;
380 17 ▶ $self = URI->new($self, $other) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 17 17
381 17 ▶ $other = URI->new($other, $self) unless ref $other;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $other 8 9 17
382 17 ▶ ref($self) eq ref($other) && # same class
Branch: 1 branch
BranchTrueFalseTotal
ref $self eq ref $other and $self->canonical->as_string eq $other->canonical->as_string 17 0 17
383 $self->canonical->as_string eq $other->canonical->as_string;
384 }
385  
386 # generic-URI transformation methods
387 1 ▶sub abs { $_[0]; }
Subroutine abs: called CC=1 SCAR=0.0
Pod documented
388 1 ▶sub rel { $_[0]; }
Subroutine rel: called CC=1 SCAR=0.0
Pod documented
389  
390 7 ▶sub secure {0}
Subroutine secure: called CC=1 SCAR=0.0
Pod documented
391  
392 # help out Storable
393 1 ▶sub STORABLE_freeze {
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
394 1 my ($self) = @_;
395 1 return $$self;
396 }
397  
398 1 ▶sub STORABLE_thaw {
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
399 1 my ($self, $cloning, $str) = @_;
400 1 $$self = $str;
401 }
402  
403 59 1;
404  
405 __END__
« URI/urn/isbn.pm ↑ Summary URI/file/Unix.pm »