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