Filename | /usr/share/perl5/URI.pm |
Statements | Executed 21 statements in 1.57ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 13µs | 49µs | BEGIN@24 | URI::
1 | 1 | 1 | 12µs | 25µs | BEGIN@3 | URI::
1 | 1 | 1 | 9µs | 18µs | BEGIN@4 | URI::
1 | 1 | 1 | 8µs | 20µs | BEGIN@128 | URI::
1 | 1 | 1 | 4µs | 4µs | BEGIN@21 | URI::
1 | 1 | 1 | 3µs | 3µs | BEGIN@22 | URI::
0 | 0 | 0 | 0s | 0s | STORABLE_freeze | URI::
0 | 0 | 0 | 0s | 0s | STORABLE_thaw | URI::
0 | 0 | 0 | 0s | 0s | __ANON__[:24] | URI::
0 | 0 | 0 | 0s | 0s | __ANON__[:25] | URI::
0 | 0 | 0 | 0s | 0s | __ANON__[:26] | URI::
0 | 0 | 0 | 0s | 0s | _init | URI::
0 | 0 | 0 | 0s | 0s | _init_implementor | URI::
0 | 0 | 0 | 0s | 0s | _no_scheme_ok | URI::
0 | 0 | 0 | 0s | 0s | _obj_eq | URI::
0 | 0 | 0 | 0s | 0s | _scheme | URI::
0 | 0 | 0 | 0s | 0s | _uric_escape | URI::
0 | 0 | 0 | 0s | 0s | abs | URI::
0 | 0 | 0 | 0s | 0s | as_iri | URI::
0 | 0 | 0 | 0s | 0s | as_string | URI::
0 | 0 | 0 | 0s | 0s | canonical | URI::
0 | 0 | 0 | 0s | 0s | clone | URI::
0 | 0 | 0 | 0s | 0s | eq | URI::
0 | 0 | 0 | 0s | 0s | fragment | URI::
0 | 0 | 0 | 0s | 0s | has_recognized_scheme | URI::
0 | 0 | 0 | 0s | 0s | implementor | URI::
0 | 0 | 0 | 0s | 0s | new | URI::
0 | 0 | 0 | 0s | 0s | new_abs | URI::
0 | 0 | 0 | 0s | 0s | opaque | URI::
0 | 0 | 0 | 0s | 0s | path | URI::
0 | 0 | 0 | 0s | 0s | rel | URI::
0 | 0 | 0 | 0s | 0s | scheme | URI::
0 | 0 | 0 | 0s | 0s | secure | URI::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package URI; | ||||
2 | |||||
3 | 2 | 24µs | 2 | 38µs | # spent 25µs (12+13) within URI::BEGIN@3 which was called:
# once (12µs+13µs) by LWP::UserAgent::BEGIN@10 at line 3 # spent 25µs making 1 call to URI::BEGIN@3
# spent 13µs making 1 call to strict::import |
4 | 2 | 93µs | 2 | 28µs | # spent 18µs (9+10) within URI::BEGIN@4 which was called:
# once (9µs+10µs) by LWP::UserAgent::BEGIN@10 at line 4 # spent 18µs making 1 call to URI::BEGIN@4
# spent 10µs making 1 call to warnings::import |
5 | |||||
6 | 1 | 400ns | our $VERSION = "1.64"; | ||
7 | |||||
8 | 1 | 200ns | our ($ABS_REMOTE_LEADING_DOTS, $ABS_ALLOW_RELATIVE_SCHEME, $DEFAULT_QUERY_FORM_DELIMITER); | ||
9 | |||||
10 | 1 | 200ns | my %implements; # mapping from scheme to implementor class | ||
11 | |||||
12 | # Some "official" character classes | ||||
13 | |||||
14 | 1 | 100ns | our $reserved = q(;/?:@&=+$,[]); | ||
15 | 1 | 100ns | our $mark = q(-_.!~*'()); #'; emacs | ||
16 | 1 | 1µs | our $unreserved = "A-Za-z0-9\Q$mark\E"; | ||
17 | 1 | 500ns | our $uric = quotemeta($reserved) . $unreserved . "%"; | ||
18 | |||||
19 | 1 | 100ns | our $scheme_re = '[a-zA-Z][a-zA-Z0-9.+\-]*'; | ||
20 | |||||
21 | 2 | 18µs | 1 | 4µs | # spent 4µs within URI::BEGIN@21 which was called:
# once (4µs+0s) by LWP::UserAgent::BEGIN@10 at line 21 # spent 4µs making 1 call to URI::BEGIN@21 |
22 | 2 | 75µs | 1 | 3µs | # spent 3µs within URI::BEGIN@22 which was called:
# once (3µs+0s) by LWP::UserAgent::BEGIN@10 at line 22 # spent 3µs making 1 call to URI::BEGIN@22 |
23 | |||||
24 | # spent 49µs (13+36) within URI::BEGIN@24 which was called:
# once (13µs+36µs) by LWP::UserAgent::BEGIN@10 at line 28 | ||||
25 | '==' => sub { _obj_eq(@_) }, | ||||
26 | '!=' => sub { !_obj_eq(@_) }, | ||||
27 | 1 | 10µs | 1 | 36µs | fallback => 1, # spent 36µs making 1 call to overload::import |
28 | 1 | 401µs | 1 | 49µs | ); # spent 49µs making 1 call to URI::BEGIN@24 |
29 | |||||
30 | # Check if two objects are the same object | ||||
31 | sub _obj_eq { | ||||
32 | return overload::StrVal($_[0]) eq overload::StrVal($_[1]); | ||||
33 | } | ||||
34 | |||||
35 | sub new | ||||
36 | { | ||||
37 | my($class, $uri, $scheme) = @_; | ||||
38 | |||||
39 | $uri = defined ($uri) ? "$uri" : ""; # stringify | ||||
40 | # Get rid of potential wrapping | ||||
41 | $uri =~ s/^<(?:URL:)?(.*)>$/$1/; # | ||||
42 | $uri =~ s/^"(.*)"$/$1/; | ||||
43 | $uri =~ s/^\s+//; | ||||
44 | $uri =~ s/\s+$//; | ||||
45 | |||||
46 | my $impclass; | ||||
47 | if ($uri =~ m/^($scheme_re):/so) { | ||||
48 | $scheme = $1; | ||||
49 | } | ||||
50 | else { | ||||
51 | if (($impclass = ref($scheme))) { | ||||
52 | $scheme = $scheme->scheme; | ||||
53 | } | ||||
54 | elsif ($scheme && $scheme =~ m/^($scheme_re)(?::|$)/o) { | ||||
55 | $scheme = $1; | ||||
56 | } | ||||
57 | } | ||||
58 | $impclass ||= implementor($scheme) || | ||||
59 | do { | ||||
60 | require URI::_foreign; | ||||
61 | $impclass = 'URI::_foreign'; | ||||
62 | }; | ||||
63 | |||||
64 | return $impclass->_init($uri, $scheme); | ||||
65 | } | ||||
66 | |||||
67 | |||||
68 | sub new_abs | ||||
69 | { | ||||
70 | my($class, $uri, $base) = @_; | ||||
71 | $uri = $class->new($uri, $base); | ||||
72 | $uri->abs($base); | ||||
73 | } | ||||
74 | |||||
75 | |||||
76 | sub _init | ||||
77 | { | ||||
78 | my $class = shift; | ||||
79 | my($str, $scheme) = @_; | ||||
80 | # find all funny characters and encode the bytes. | ||||
81 | $str = $class->_uric_escape($str); | ||||
82 | $str = "$scheme:$str" unless $str =~ /^$scheme_re:/o || | ||||
83 | $class->_no_scheme_ok; | ||||
84 | my $self = bless \$str, $class; | ||||
85 | $self; | ||||
86 | } | ||||
87 | |||||
88 | |||||
89 | sub _uric_escape | ||||
90 | { | ||||
91 | my($class, $str) = @_; | ||||
92 | $str =~ s*([^$uric\#])* URI::Escape::escape_char($1) *ego; | ||||
93 | utf8::downgrade($str); | ||||
94 | return $str; | ||||
95 | } | ||||
96 | |||||
97 | |||||
98 | sub implementor | ||||
99 | { | ||||
100 | my($scheme, $impclass) = @_; | ||||
101 | if (!$scheme || $scheme !~ /\A$scheme_re\z/o) { | ||||
102 | require URI::_generic; | ||||
103 | return "URI::_generic"; | ||||
104 | } | ||||
105 | |||||
106 | $scheme = lc($scheme); | ||||
107 | |||||
108 | if ($impclass) { | ||||
109 | # Set the implementor class for a given scheme | ||||
110 | my $old = $implements{$scheme}; | ||||
111 | $impclass->_init_implementor($scheme); | ||||
112 | $implements{$scheme} = $impclass; | ||||
113 | return $old; | ||||
114 | } | ||||
115 | |||||
116 | my $ic = $implements{$scheme}; | ||||
117 | return $ic if $ic; | ||||
118 | |||||
119 | # scheme not yet known, look for internal or | ||||
120 | # preloaded (with 'use') implementation | ||||
121 | $ic = "URI::$scheme"; # default location | ||||
122 | |||||
123 | # turn scheme into a valid perl identifier by a simple transformation... | ||||
124 | $ic =~ s/\+/_P/g; | ||||
125 | $ic =~ s/\./_O/g; | ||||
126 | $ic =~ s/\-/_/g; | ||||
127 | |||||
128 | 2 | 938µs | 2 | 31µs | # spent 20µs (8+11) within URI::BEGIN@128 which was called:
# once (8µs+11µs) by LWP::UserAgent::BEGIN@10 at line 128 # spent 20µs making 1 call to URI::BEGIN@128
# spent 12µs making 1 call to strict::unimport |
129 | # check we actually have one for the scheme: | ||||
130 | unless (@{"${ic}::ISA"}) { | ||||
131 | # Try to load it | ||||
132 | eval "require $ic"; | ||||
133 | die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/; | ||||
134 | return undef unless @{"${ic}::ISA"}; | ||||
135 | } | ||||
136 | |||||
137 | $ic->_init_implementor($scheme); | ||||
138 | $implements{$scheme} = $ic; | ||||
139 | $ic; | ||||
140 | } | ||||
141 | |||||
142 | |||||
143 | sub _init_implementor | ||||
144 | { | ||||
145 | my($class, $scheme) = @_; | ||||
146 | # Remember that one implementor class may actually | ||||
147 | # serve to implement several URI schemes. | ||||
148 | } | ||||
149 | |||||
150 | |||||
151 | sub clone | ||||
152 | { | ||||
153 | my $self = shift; | ||||
154 | my $other = $$self; | ||||
155 | bless \$other, ref $self; | ||||
156 | } | ||||
157 | |||||
158 | |||||
159 | sub _no_scheme_ok { 0 } | ||||
160 | |||||
161 | sub _scheme | ||||
162 | { | ||||
163 | my $self = shift; | ||||
164 | |||||
165 | unless (@_) { | ||||
166 | return undef unless $$self =~ /^($scheme_re):/o; | ||||
167 | return $1; | ||||
168 | } | ||||
169 | |||||
170 | my $old; | ||||
171 | my $new = shift; | ||||
172 | if (defined($new) && length($new)) { | ||||
173 | Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o; | ||||
174 | $old = $1 if $$self =~ s/^($scheme_re)://o; | ||||
175 | my $newself = URI->new("$new:$$self"); | ||||
176 | $$self = $$newself; | ||||
177 | bless $self, ref($newself); | ||||
178 | } | ||||
179 | else { | ||||
180 | if ($self->_no_scheme_ok) { | ||||
181 | $old = $1 if $$self =~ s/^($scheme_re)://o; | ||||
182 | Carp::carp("Oops, opaque part now look like scheme") | ||||
183 | if $^W && $$self =~ m/^$scheme_re:/o | ||||
184 | } | ||||
185 | else { | ||||
186 | $old = $1 if $$self =~ m/^($scheme_re):/o; | ||||
187 | } | ||||
188 | } | ||||
189 | |||||
190 | return $old; | ||||
191 | } | ||||
192 | |||||
193 | sub scheme | ||||
194 | { | ||||
195 | my $scheme = shift->_scheme(@_); | ||||
196 | return undef unless defined $scheme; | ||||
197 | lc($scheme); | ||||
198 | } | ||||
199 | |||||
200 | sub has_recognized_scheme { | ||||
201 | my $self = shift; | ||||
202 | return ref($self) !~ /^URI::_(?:foreign|generic)\z/; | ||||
203 | } | ||||
204 | |||||
205 | sub opaque | ||||
206 | { | ||||
207 | my $self = shift; | ||||
208 | |||||
209 | unless (@_) { | ||||
210 | $$self =~ /^(?:$scheme_re:)?([^\#]*)/o or die; | ||||
211 | return $1; | ||||
212 | } | ||||
213 | |||||
214 | $$self =~ /^($scheme_re:)? # optional scheme | ||||
215 | ([^\#]*) # opaque | ||||
216 | (\#.*)? # optional fragment | ||||
217 | $/sx or die; | ||||
218 | |||||
219 | my $old_scheme = $1; | ||||
220 | my $old_opaque = $2; | ||||
221 | my $old_frag = $3; | ||||
222 | |||||
223 | my $new_opaque = shift; | ||||
224 | $new_opaque = "" unless defined $new_opaque; | ||||
225 | $new_opaque =~ s/([^$uric])/ URI::Escape::escape_char($1)/ego; | ||||
226 | utf8::downgrade($new_opaque); | ||||
227 | |||||
228 | $$self = defined($old_scheme) ? $old_scheme : ""; | ||||
229 | $$self .= $new_opaque; | ||||
230 | $$self .= $old_frag if defined $old_frag; | ||||
231 | |||||
232 | $old_opaque; | ||||
233 | } | ||||
234 | |||||
235 | sub path { goto &opaque } # alias | ||||
236 | |||||
237 | |||||
238 | sub fragment | ||||
239 | { | ||||
240 | my $self = shift; | ||||
241 | unless (@_) { | ||||
242 | return undef unless $$self =~ /\#(.*)/s; | ||||
243 | return $1; | ||||
244 | } | ||||
245 | |||||
246 | my $old; | ||||
247 | $old = $1 if $$self =~ s/\#(.*)//s; | ||||
248 | |||||
249 | my $new_frag = shift; | ||||
250 | if (defined $new_frag) { | ||||
251 | $new_frag =~ s/([^$uric])/ URI::Escape::escape_char($1) /ego; | ||||
252 | utf8::downgrade($new_frag); | ||||
253 | $$self .= "#$new_frag"; | ||||
254 | } | ||||
255 | $old; | ||||
256 | } | ||||
257 | |||||
258 | |||||
259 | sub as_string | ||||
260 | { | ||||
261 | my $self = shift; | ||||
262 | $$self; | ||||
263 | } | ||||
264 | |||||
265 | |||||
266 | sub as_iri | ||||
267 | { | ||||
268 | my $self = shift; | ||||
269 | my $str = $$self; | ||||
270 | if ($str =~ s/%([89a-fA-F][0-9a-fA-F])/chr(hex($1))/eg) { | ||||
271 | # All this crap because the more obvious: | ||||
272 | # | ||||
273 | # Encode::decode("UTF-8", $str, sub { sprintf "%%%02X", shift }) | ||||
274 | # | ||||
275 | # doesn't work before Encode 2.39. Wait for a standard release | ||||
276 | # to bundle that version. | ||||
277 | |||||
278 | require Encode; | ||||
279 | my $enc = Encode::find_encoding("UTF-8"); | ||||
280 | my $u = ""; | ||||
281 | while (length $str) { | ||||
282 | $u .= $enc->decode($str, Encode::FB_QUIET()); | ||||
283 | if (length $str) { | ||||
284 | # escape next char | ||||
285 | $u .= URI::Escape::escape_char(substr($str, 0, 1, "")); | ||||
286 | } | ||||
287 | } | ||||
288 | $str = $u; | ||||
289 | } | ||||
290 | return $str; | ||||
291 | } | ||||
292 | |||||
293 | |||||
294 | sub canonical | ||||
295 | { | ||||
296 | # Make sure scheme is lowercased, that we don't escape unreserved chars, | ||||
297 | # and that we use upcase escape sequences. | ||||
298 | |||||
299 | my $self = shift; | ||||
300 | my $scheme = $self->_scheme || ""; | ||||
301 | my $uc_scheme = $scheme =~ /[A-Z]/; | ||||
302 | my $esc = $$self =~ /%[a-fA-F0-9]{2}/; | ||||
303 | return $self unless $uc_scheme || $esc; | ||||
304 | |||||
305 | my $other = $self->clone; | ||||
306 | if ($uc_scheme) { | ||||
307 | $other->_scheme(lc $scheme); | ||||
308 | } | ||||
309 | if ($esc) { | ||||
310 | $$other =~ s{%([0-9a-fA-F]{2})} | ||||
311 | { my $a = chr(hex($1)); | ||||
312 | $a =~ /^[$unreserved]\z/o ? $a : "%\U$1" | ||||
313 | }ge; | ||||
314 | } | ||||
315 | return $other; | ||||
316 | } | ||||
317 | |||||
318 | # Compare two URIs, subclasses will provide a more correct implementation | ||||
319 | sub eq { | ||||
320 | my($self, $other) = @_; | ||||
321 | $self = URI->new($self, $other) unless ref $self; | ||||
322 | $other = URI->new($other, $self) unless ref $other; | ||||
323 | ref($self) eq ref($other) && # same class | ||||
324 | $self->canonical->as_string eq $other->canonical->as_string; | ||||
325 | } | ||||
326 | |||||
327 | # generic-URI transformation methods | ||||
328 | sub abs { $_[0]; } | ||||
329 | sub rel { $_[0]; } | ||||
330 | |||||
331 | sub secure { 0 } | ||||
332 | |||||
333 | # help out Storable | ||||
334 | sub STORABLE_freeze { | ||||
335 | my($self, $cloning) = @_; | ||||
336 | return $$self; | ||||
337 | } | ||||
338 | |||||
339 | sub STORABLE_thaw { | ||||
340 | my($self, $cloning, $str) = @_; | ||||
341 | $$self = $str; | ||||
342 | } | ||||
343 | |||||
344 | 1 | 4µs | 1; | ||
345 | |||||
346 | __END__ |