Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm |
Statements | Executed 13274028 statements in 14.8s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
255591 | 11 | 6 | 2.81s | 6.88s | clone (recurses: max depth 1, inclusive time 811ms) | Mojo::URL::
239553 | 2 | 1 | 2.73s | 19.7s | _string | Mojo::URL::
239553 | 1 | 1 | 1.55s | 9.55s | path_query | Mojo::URL::
477609 | 5 | 1 | 1.38s | 5.30s | path | Mojo::URL::
137007 | 1 | 1 | 1.29s | 8.08s | parse | Mojo::URL::
338595 | 2 | 1 | 1.29s | 2.74s | host_port | Mojo::URL::
45548 | 4 | 2 | 1.21s | 7.63s | to_abs | Mojo::URL::
381988 | 2 | 1 | 1.05s | 4.46s | _encode | Mojo::URL::
392623 | 25 | 8 | 873ms | 9.32s | new | Mojo::URL::
286926 | 2 | 1 | 802ms | 1.05s | query | Mojo::URL::
239553 | 1 | 1 | 741ms | 992ms | ihost | Mojo::URL::
707965 | 4 | 1 | 602ms | 975ms | CORE:match (opcode) | Mojo::URL::
239553 | 1 | 1 | 519ms | 702ms | protocol | Mojo::URL::
302037 | 19 | 6 | 461ms | 20.3s | __ANON__[:3] | Mojo::URL::
237236 | 1 | 1 | 383ms | 19.9s | to_string | Mojo::URL::
58250 | 1 | 1 | 111ms | 626ms | _decode | Mojo::URL::
45760 | 5 | 5 | 101ms | 143ms | is_abs | Mojo::URL::
198084 | 2 | 1 | 47.0ms | 47.0ms | CORE:subst (opcode) | Mojo::URL::
1 | 1 | 1 | 12.0ms | 174ms | BEGIN@2 | Mojo::URL::
2317 | 4 | 2 | 5.07ms | 191ms | to_unsafe_string | Mojo::URL::
1 | 1 | 1 | 1.97ms | 2.28ms | BEGIN@5 | Mojo::URL::
1 | 1 | 1 | 1.28ms | 1.47ms | BEGIN@6 | Mojo::URL::
1 | 1 | 1 | 9µs | 28µs | BEGIN@3 | Mojo::URL::
1 | 1 | 1 | 4µs | 37µs | BEGIN@7 | Mojo::URL::
0 | 0 | 0 | 0s | 0s | __ANON__[:9] | Mojo::URL::
0 | 0 | 0 | 0s | 0s | password | Mojo::URL::
0 | 0 | 0 | 0s | 0s | username | Mojo::URL::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Mojo::URL; | ||||
2 | 2 | 773µs | 2 | 174ms | # spent 174ms (12.0+162) within Mojo::URL::BEGIN@2 which was called:
# once (12.0ms+162ms) by JSON::Schema::Modern::BEGIN@23 at line 2 # spent 174ms making 1 call to Mojo::URL::BEGIN@2
# spent 137µs making 1 call to Mojo::Base::import |
3 | 302039 | 538ms | 237238 | 19.9s | # spent 20.3s (461ms+19.9) within Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] which was called 302037 times, avg 67µs/call:
# 90777 times (163ms+7.44s) by JSON::Schema::Modern::_eval_subschema at line 553 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 84µs/call
# 90777 times (144ms+6.49s) by JSON::Schema::Modern::_eval_subschema at line 554 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 73µs/call
# 47236 times (87.4ms+5.24s) by Data::Perl::Role::Collection::Hash::get at line 24 of Data/Perl/Role/Collection/Hash.pm, avg 113µs/call
# 33683 times (30.7ms+0s) by Mojo::URL::to_abs at line 127, avg 910ns/call
# 31112 times (20.9ms+0s) by Mojo::URL::clone at line 16, avg 673ns/call
# 4196 times (6.86ms+320ms) by JSON::Schema::Modern::Utilities::E at line 218 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 78µs/call
# 4037 times (8.34ms+364ms) by Mojo::URL::CORE:match at line 56, avg 92µs/call
# 46 times (57µs+2.24ms) by JSON::Schema::Modern::Document::BUILD at line 168 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 50µs/call
# 39 times (60µs+3.32ms) by Data::Perl::Role::Collection::Hash::set at line 33 of Data/Perl/Role/Collection/Hash.pm, avg 87µs/call
# 39 times (51µs+3.27ms) by Data::Perl::Role::Collection::Hash::set at line 35 of Data/Perl/Role/Collection/Hash.pm, avg 85µs/call
# 30 times (60µs+2.29ms) by JSON::Schema::Modern::Document::BUILD at line 149 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 78µs/call
# 14 times (32µs+1.14ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 67 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 83µs/call
# 12 times (35µs+734µs) by JSON::Schema::Modern::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm:685] at line 668 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 64µs/call
# 9 times (53µs+1.11ms) by JSON::Schema::Modern::add_schema at line 187 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 130µs/call
# 8 times (15µs+845µs) by JSON::Schema::Modern::_get_or_load_resource at line 823 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 108µs/call
# 8 times (9µs+536µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm:135] at line 122 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 68µs/call
# 6 times (11µs+401µs) by JSON::Schema::Modern::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm:685] at line 664 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 69µs/call
# 6 times (11µs+0s) by JSON::Schema::Modern::add_schema at line 152 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 2µs/call
# 2 times (1µs+135µs) by JSON::Schema::Modern::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm:685] at line 661 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 68µs/call
# spent 28µs (9+19) within Mojo::URL::BEGIN@3 which was called:
# once (9µs+19µs) by JSON::Schema::Modern::BEGIN@23 at line 3 # spent 19.9s making 237236 calls to Mojo::URL::to_string, avg 84µs/call
# spent 28µs making 1 call to Mojo::URL::BEGIN@3
# spent 19µs making 1 call to overload::import |
4 | |||||
5 | 2 | 658µs | 2 | 2.28ms | # spent 2.28ms (1.97+317µs) within Mojo::URL::BEGIN@5 which was called:
# once (1.97ms+317µs) by JSON::Schema::Modern::BEGIN@23 at line 5 # spent 2.28ms making 1 call to Mojo::URL::BEGIN@5
# spent 2µs making 1 call to Mojo::Base::import |
6 | 2 | 499µs | 2 | 1.48ms | # spent 1.47ms (1.28+192µs) within Mojo::URL::BEGIN@6 which was called:
# once (1.28ms+192µs) by JSON::Schema::Modern::BEGIN@23 at line 6 # spent 1.47ms making 1 call to Mojo::URL::BEGIN@6
# spent 3µs making 1 call to Mojo::Base::import |
7 | 2 | 1.33ms | 2 | 70µs | # spent 37µs (4+33) within Mojo::URL::BEGIN@7 which was called:
# once (4µs+33µs) by JSON::Schema::Modern::BEGIN@23 at line 7 # spent 37µs making 1 call to Mojo::URL::BEGIN@7
# spent 33µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 3µs | 1 | 37µs | has base => sub { Mojo::URL->new }; # spent 37µs making 1 call to Mojo::URL::has |
10 | 1 | 1µs | 1 | 45µs | has [qw(fragment host port scheme userinfo)]; # spent 45µs making 1 call to Mojo::URL::has |
11 | |||||
12 | # spent 6.88s (2.81+4.07) within Mojo::URL::clone which was called 255591 times, avg 27µs/call:
# 68091 times (794ms+1.30s) by JSON::Schema::Modern::Utilities::canonical_uri at line 192 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 31µs/call
# 45548 times (367ms+467ms) by Mojo::URL::to_abs at line 123, avg 18µs/call
# 38783 times (468ms+1.29s) by JSON::Schema::Modern::_fetch_from_uri at line 865 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 45µs/call
# 38783 times (475ms+701ms) by JSON::Schema::Modern::_fetch_from_uri at line 878 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 30µs/call
# 31112 times (297ms+-297ms) by Mojo::URL::clone at line 16, avg 0s/call
# 25562 times (317ms+474ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_id at line 90 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 31µs/call
# 7668 times (87.6ms+136ms) by JSON::Schema::Modern::_fetch_from_uri at line 898 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 29µs/call
# 15 times (124µs+118µs) by JSON::Schema::Modern::Document::BUILD at line 145 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 16µs/call
# 14 times (279µs+329µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 81 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 43µs/call
# 14 times (56µs+51µs) by JSON::Schema::Modern::Document::traverse at line 178 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 8µs/call
# once (10µs+14µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 115 of JSON/Schema/Modern/Document/OpenAPI.pm | ||||
13 | 255591 | 41.3ms | my $self = shift; | ||
14 | 255591 | 168ms | 255591 | 683ms | my $clone = $self->new; # spent 683ms making 255591 calls to Mojo::URL::new, avg 3µs/call |
15 | 255591 | 544ms | @$clone{keys %$self} = values %$self; | ||
16 | 255591 | 1.10s | 949186 | 3.39s | $clone->{$_} && ($clone->{$_} = $clone->{$_}->clone) for qw(base path query); # spent 1.59s making 255560 calls to Mojo::Path::clone, avg 6µs/call
# spent 1.53s making 187921 calls to Mojo::Parameters::clone, avg 8µs/call
# spent 141ms making 255560 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 550ns/call
# spent 101ms making 187921 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 535ns/call
# spent 20.9ms making 31112 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 673ns/call
# spent 811ms making 31112 calls to Mojo::URL::clone, avg 26µs/call, recursion: max depth 1, sum of overlapping time 811ms |
17 | 255591 | 354ms | return $clone; | ||
18 | } | ||||
19 | |||||
20 | sub host_port { | ||||
21 | 338595 | 76.9ms | my ($self, $host_port) = @_; | ||
22 | |||||
23 | 338595 | 40.7ms | if (defined $host_port) { | ||
24 | 99042 | 111ms | 99042 | 20.3ms | $self->port($1) if $host_port =~ s/:(\d+)$//; # spent 20.3ms making 99042 calls to Mojo::URL::CORE:subst, avg 205ns/call |
25 | 99042 | 66.0ms | 99042 | 198ms | my $host = url_unescape $host_port; # spent 198ms making 99042 calls to Mojo::Util::url_unescape, avg 2µs/call |
26 | 99042 | 280ms | 198084 | 110ms | return $host =~ /[^\x00-\x7f]/ ? $self->ihost($host) : $self->host($host); # spent 79.0ms making 99042 calls to Mojo::URL::host, avg 798ns/call
# spent 30.5ms making 99042 calls to Mojo::URL::CORE:match, avg 308ns/call |
27 | } | ||||
28 | |||||
29 | 239553 | 166ms | 239553 | 992ms | return undef unless defined(my $host = $self->ihost); # spent 992ms making 239553 calls to Mojo::URL::ihost, avg 4µs/call |
30 | 235958 | 439ms | 235958 | 128ms | return $host unless defined(my $port = $self->port); # spent 128ms making 235958 calls to Mojo::URL::port, avg 544ns/call |
31 | return "$host:$port"; | ||||
32 | } | ||||
33 | |||||
34 | # spent 992ms (741+252) within Mojo::URL::ihost which was called 239553 times, avg 4µs/call:
# 239553 times (741ms+252ms) by Mojo::URL::host_port at line 29, avg 4µs/call | ||||
35 | 239553 | 30.7ms | my $self = shift; | ||
36 | |||||
37 | # Decode | ||||
38 | 239553 | 27.9ms | return $self->host(join '.', map { /^xn--(.+)$/ ? punycode_decode $1 : $_ } split(/\./, shift, -1)) if @_; | ||
39 | |||||
40 | # Check if host needs to be encoded | ||||
41 | 239553 | 179ms | 239553 | 144ms | return undef unless defined(my $host = $self->host); # spent 144ms making 239553 calls to Mojo::URL::host, avg 601ns/call |
42 | 235958 | 603ms | 235958 | 108ms | return $host unless $host =~ /[^\x00-\x7f]/; # spent 108ms making 235958 calls to Mojo::URL::CORE:match, avg 456ns/call |
43 | |||||
44 | # Encode | ||||
45 | return join '.', map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split(/\./, $host, -1); | ||||
46 | } | ||||
47 | |||||
48 | 45760 | 103ms | 45760 | 42.2ms | # spent 143ms (101+42.2) within Mojo::URL::is_abs which was called 45760 times, avg 3µs/call:
# 45548 times (100ms+42.1ms) by Mojo::URL::to_abs at line 124, avg 3µs/call
# 151 times (389µs+94µs) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 120 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 3µs/call
# 46 times (75µs+25µs) by JSON::Schema::Modern::Utilities::assert_uri at line 330 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 2µs/call
# 14 times (45µs+10µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 69 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 4µs/call
# once (4µs+1µs) by Type::Tiny::__ANON__[(eval 425)[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Sub/Quote.pm:3]:16] at line 16 of (eval 425)[Sub/Quote.pm:3] # spent 42.2ms making 45760 calls to Mojo::URL::scheme, avg 922ns/call |
49 | |||||
50 | 392623 | 802ms | 529630 | 8.45s | # spent 9.32s (873ms+8.45) within Mojo::URL::new which was called 392623 times, avg 24µs/call:
# 255591 times (446ms+237ms) by Mojo::URL::clone at line 14, avg 3µs/call
# 88516 times (255ms+3.53s) by JSON::Schema::Modern::_fetch_from_uri at line 874 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 43µs/call
# 38781 times (139ms+3.44s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 215 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 92µs/call
# 2556 times (9.15ms+279ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 237 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 113µs/call
# 2556 times (7.38ms+276ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 249 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 111µs/call
# 1380 times (4.96ms+155ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:124] at line 123 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 116µs/call
# 755 times (2.13ms+153ms) by JSON::Schema::Modern::traverse at line 258 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 206µs/call
# 741 times (2.80ms+211ms) by JSON::Schema::Modern::traverse at line 235 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 288µs/call
# 741 times (2.39ms+54.3ms) by JSON::Schema::Modern::traverse at line 250 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 76µs/call
# 740 times (2.69ms+92.0ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 313 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 128µs/call
# 151 times (541µs+10.7ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 119 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 75µs/call
# 46 times (117µs+1.43ms) by JSON::Schema::Modern::Utilities::assert_uri at line 328 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 34µs/call
# 15 times (45µs+629µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm:45] at line 45 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 45µs/call
# 15 times (32µs+16µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 177 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 3µs/call
# 14 times (45µs+537µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 51 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 42µs/call
# 9 times (59µs+484µs) by JSON::Schema::Modern::add_schema at line 140 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 60µs/call
# 8 times (23µs+11µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm:38] at line 38 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm, avg 4µs/call
# once (10µs+215µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm:39] at line 39 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Document.pm
# once (6µs+67µs) by Type::Tiny::__ANON__[(eval 425)[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Sub/Quote.pm:3]:16] at line 16 of (eval 425)[Sub/Quote.pm:3]
# once (3µs+70µs) by JSON::Schema::Modern::evaluate at line 303 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
# once (2µs+59µs) by JSON::Schema::Modern::evaluate at line 323 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
# once (3µs+30µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema at line 138 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm
# once (2µs+30µs) by JSON::Schema::Modern::Document::OpenAPI::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Document/OpenAPI.pm:56] at line 56 of JSON/Schema/Modern/Document/OpenAPI.pm
# once (3µs+19µs) by JSON::Schema::Modern::_fetch_from_uri at line 861 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
# once (2µs+0s) by JSON::Schema::Modern::evaluate at line 306 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm # spent 8.08s making 137007 calls to Mojo::URL::parse, avg 59µs/call
# spent 364ms making 392623 calls to Mojo::Base::new, avg 928ns/call |
51 | |||||
52 | # spent 8.08s (1.29+6.79) within Mojo::URL::parse which was called 137007 times, avg 59µs/call:
# 137007 times (1.29s+6.79s) by Mojo::URL::new at line 50, avg 59µs/call | ||||
53 | 137007 | 37.7ms | my ($self, $url) = @_; | ||
54 | |||||
55 | # Official regex from RFC 3986 | ||||
56 | 137007 | 439ms | 141044 | 1.04s | $url =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!; # spent 672ms making 137007 calls to Mojo::URL::CORE:match, avg 5µs/call
# spent 373ms making 4037 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 92µs/call |
57 | 137007 | 117ms | 99042 | 124ms | $self->scheme($2) if defined $2; # spent 124ms making 99042 calls to Mojo::URL::scheme, avg 1µs/call |
58 | 137007 | 137ms | 137007 | 4.32s | $self->path($5) if defined $5; # spent 4.32s making 137007 calls to Mojo::URL::path, avg 32µs/call |
59 | 137007 | 37.8ms | $self->query($7) if defined $7; | ||
60 | 137007 | 170ms | 174750 | 823ms | $self->fragment(_decode(url_unescape $9)) if defined $9; # spent 626ms making 58250 calls to Mojo::URL::_decode, avg 11µs/call
# spent 141ms making 58250 calls to Mojo::Util::url_unescape, avg 2µs/call
# spent 55.3ms making 58250 calls to Mojo::URL::fragment, avg 949ns/call |
61 | 137007 | 78.3ms | if (defined(my $auth = $4)) { | ||
62 | 99042 | 134ms | 99042 | 26.7ms | $self->userinfo(_decode(url_unescape $1)) if $auth =~ s/^([^\@]+)\@//; # spent 26.7ms making 99042 calls to Mojo::URL::CORE:subst, avg 270ns/call |
63 | 99042 | 66.1ms | 99042 | 824ms | $self->host_port($auth); # spent 824ms making 99042 calls to Mojo::URL::host_port, avg 8µs/call |
64 | } | ||||
65 | |||||
66 | 137007 | 164ms | return $self; | ||
67 | } | ||||
68 | |||||
69 | sub password { (shift->userinfo // '') =~ /:(.*)$/ ? $1 : undef } | ||||
70 | |||||
71 | # spent 5.30s (1.38+3.92) within Mojo::URL::path which was called 477609 times, avg 11µs/call:
# 239553 times (580ms+117ms) by Mojo::URL::path_query at line 93, avg 3µs/call
# 137007 times (558ms+3.76s) by Mojo::URL::parse at line 58, avg 32µs/call
# 35784 times (84.4ms+15.2ms) by Mojo::URL::to_abs at line 147, avg 3µs/call
# 33683 times (87.8ms+14.0ms) by Mojo::URL::to_abs at line 135, avg 3µs/call
# 31582 times (70.7ms+13.1ms) by Mojo::URL::to_abs at line 140, avg 3µs/call | ||||
72 | 477609 | 62.2ms | my $self = shift; | ||
73 | |||||
74 | # Old path | ||||
75 | 477609 | 443ms | 477609 | 468ms | $self->{path} ||= Mojo::Path->new; # spent 309ms making 137039 calls to Mojo::Path::new, avg 2µs/call
# spent 159ms making 340570 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 466ns/call |
76 | 477609 | 402ms | return $self->{path} unless @_; | ||
77 | |||||
78 | # New path | ||||
79 | 170690 | 185ms | 137007 | 3.45s | $self->{path} = ref $_[0] ? $_[0] : $self->{path}->merge($_[0]); # spent 3.45s making 137007 calls to Mojo::Path::merge, avg 25µs/call |
80 | |||||
81 | 170690 | 183ms | return $self; | ||
82 | } | ||||
83 | |||||
84 | # spent 9.55s (1.55+8.00) within Mojo::URL::path_query which was called 239553 times, avg 40µs/call:
# 239553 times (1.55s+8.00s) by Mojo::URL::_string at line 177, avg 40µs/call | ||||
85 | 239553 | 48.9ms | my ($self, $pq) = @_; | ||
86 | |||||
87 | 239553 | 31.0ms | if (defined $pq) { | ||
88 | return $self unless $pq =~ /^([^?#]*)(?:\?([^#]*))?/; | ||||
89 | return defined $2 ? $self->path($1)->query($2) : $self->path($1); | ||||
90 | } | ||||
91 | |||||
92 | 239553 | 283ms | 479106 | 2.34s | my $query = $self->query->to_string; # spent 1.48s making 239553 calls to Mojo::Parameters::to_string, avg 6µs/call
# spent 857ms making 239553 calls to Mojo::URL::query, avg 4µs/call |
93 | 239553 | 781ms | 479106 | 5.66s | return $self->path->to_string . (length $query ? "?$query" : ''); # spent 4.97s making 239553 calls to Mojo::Path::to_string, avg 21µs/call
# spent 696ms making 239553 calls to Mojo::URL::path, avg 3µs/call |
94 | } | ||||
95 | |||||
96 | 239553 | 458ms | 239553 | 183ms | # spent 702ms (519+183) within Mojo::URL::protocol which was called 239553 times, avg 3µs/call:
# 239553 times (519ms+183ms) by Mojo::URL::_string at line 166, avg 3µs/call # spent 183ms making 239553 calls to Mojo::URL::scheme, avg 763ns/call |
97 | |||||
98 | sub query { | ||||
99 | 286926 | 37.9ms | my $self = shift; | ||
100 | |||||
101 | # Old parameters | ||||
102 | 286926 | 315ms | 286926 | 251ms | my $q = $self->{query} ||= Mojo::Parameters->new; # spent 133ms making 47748 calls to Mojo::Parameters::new, avg 3µs/call
# spent 118ms making 239178 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 493ns/call |
103 | 286926 | 314ms | return $q unless @_; | ||
104 | |||||
105 | # Replace with list | ||||
106 | 15791 | 18.0ms | if (@_ > 1) { $q->pairs([])->parse(@_) } | ||
107 | |||||
108 | # Merge with hash | ||||
109 | elsif (ref $_[0] eq 'HASH') { $q->merge(%{$_[0]}) } | ||||
110 | |||||
111 | # Append array | ||||
112 | elsif (ref $_[0] eq 'ARRAY') { $q->append(@{$_[0]}) } | ||||
113 | |||||
114 | # New parameters | ||||
115 | 15791 | 8.04ms | else { $self->{query} = ref $_[0] ? $_[0] : $q->parse($_[0]) } | ||
116 | |||||
117 | 15791 | 17.1ms | return $self; | ||
118 | } | ||||
119 | |||||
120 | # spent 7.63s (1.21+6.42) within Mojo::URL::to_abs which was called 45548 times, avg 168µs/call:
# 38781 times (1.11s+6.02s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 215 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 184µs/call
# 4196 times (16.2ms+114ms) by JSON::Schema::Modern::Utilities::E at line 213 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 31µs/call
# 2556 times (92.0ms+283ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 237 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 147µs/call
# 15 times (707µs+2.34ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 177 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 203µs/call | ||||
121 | 45548 | 8.60ms | my $self = shift; | ||
122 | |||||
123 | 45548 | 34.6ms | 45548 | 835ms | my $abs = $self->clone; # spent 835ms making 45548 calls to Mojo::URL::clone, avg 18µs/call |
124 | 45548 | 60.5ms | 45548 | 142ms | return $abs if $abs->is_abs; # spent 142ms making 45548 calls to Mojo::URL::is_abs, avg 3µs/call |
125 | |||||
126 | # Scheme | ||||
127 | 33683 | 46.3ms | 33683 | 30.7ms | my $base = shift || $abs->base; # spent 30.7ms making 33683 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 910ns/call |
128 | 33683 | 78.2ms | 101049 | 106ms | $abs->base($base)->scheme($base->scheme); # spent 54.4ms making 67366 calls to Mojo::URL::scheme, avg 808ns/call
# spent 51.9ms making 33683 calls to Mojo::URL::base, avg 2µs/call |
129 | |||||
130 | # Authority | ||||
131 | 33683 | 26.4ms | 33683 | 18.1ms | return $abs if $abs->host; # spent 18.1ms making 33683 calls to Mojo::URL::host, avg 538ns/call |
132 | 33683 | 115ms | 202098 | 151ms | $abs->userinfo($base->userinfo)->host($base->host)->port($base->port); # spent 60.5ms making 67366 calls to Mojo::URL::port, avg 898ns/call
# spent 50.5ms making 67366 calls to Mojo::URL::host, avg 749ns/call
# spent 39.7ms making 67366 calls to Mojo::URL::userinfo, avg 589ns/call |
133 | |||||
134 | # Absolute path | ||||
135 | 33683 | 29.7ms | 33683 | 102ms | my $path = $abs->path; # spent 102ms making 33683 calls to Mojo::URL::path, avg 3µs/call |
136 | 33683 | 24.9ms | 33683 | 96.6ms | return $abs if $path->leading_slash; # spent 96.6ms making 33683 calls to Mojo::Path::leading_slash, avg 3µs/call |
137 | |||||
138 | # Inherit path | ||||
139 | 33683 | 49.5ms | 33683 | 74.2ms | if (!@{$path->parts}) { # spent 74.2ms making 33683 calls to Mojo::Path::parts, avg 2µs/call |
140 | 15791 | 41.5ms | 63164 | 653ms | $abs->path($base->path->clone->canonicalize); # spent 483ms making 15791 calls to Mojo::Path::canonicalize, avg 31µs/call
# spent 86.5ms making 15791 calls to Mojo::Path::clone, avg 5µs/call
# spent 83.8ms making 31582 calls to Mojo::URL::path, avg 3µs/call |
141 | |||||
142 | # Query | ||||
143 | 15791 | 50.7ms | 78955 | 420ms | $abs->query($base->query->clone) unless length $abs->query->to_string; # spent 195ms making 47373 calls to Mojo::URL::query, avg 4µs/call
# spent 120ms making 15791 calls to Mojo::Parameters::clone, avg 8µs/call
# spent 105ms making 15791 calls to Mojo::Parameters::to_string, avg 7µs/call |
144 | } | ||||
145 | |||||
146 | # Merge paths | ||||
147 | 17892 | 61.4ms | 89460 | 3.79s | else { $abs->path($base->path->clone->merge($path)->canonicalize) } # spent 3.44s making 17892 calls to Mojo::Path::merge, avg 192µs/call
# spent 155ms making 17892 calls to Mojo::Path::canonicalize, avg 9µs/call
# spent 99.5ms making 35784 calls to Mojo::URL::path, avg 3µs/call
# spent 95.0ms making 17892 calls to Mojo::Path::clone, avg 5µs/call |
148 | |||||
149 | 33683 | 114ms | return $abs; | ||
150 | } | ||||
151 | |||||
152 | 237236 | 382ms | 237236 | 19.5s | # spent 19.9s (383ms+19.5) within Mojo::URL::to_string which was called 237236 times, avg 84µs/call:
# 237236 times (383ms+19.5s) by Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] at line 3, avg 84µs/call # spent 19.5s making 237236 calls to Mojo::URL::_string, avg 82µs/call |
153 | 2317 | 4.96ms | 2317 | 186ms | # spent 191ms (5.07+186) within Mojo::URL::to_unsafe_string which was called 2317 times, avg 82µs/call:
# 1380 times (2.98ms+98.2ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:124] at line 123 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 73µs/call
# 740 times (1.67ms+69.7ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 313 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 96µs/call
# 151 times (343µs+14.6ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 120 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 99µs/call
# 46 times (80µs+3.08ms) by JSON::Schema::Modern::Utilities::assert_uri at line 330 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Utilities.pm, avg 69µs/call # spent 186ms making 2317 calls to Mojo::URL::_string, avg 80µs/call |
154 | |||||
155 | sub username { (shift->userinfo // '') =~ /^([^:]+)/ ? $1 : undef } | ||||
156 | |||||
157 | 58250 | 119ms | 58250 | 516ms | # spent 626ms (111+516) within Mojo::URL::_decode which was called 58250 times, avg 11µs/call:
# 58250 times (111ms+516ms) by Mojo::URL::parse at line 60, avg 11µs/call # spent 516ms making 58250 calls to Mojo::Util::decode, avg 9µs/call |
158 | |||||
159 | 381988 | 781ms | 763976 | 3.41s | sub _encode { url_escape encode('UTF-8', $_[0]), $_[1] } # spent 1.79s making 381988 calls to Mojo::Util::url_escape, avg 5µs/call
# spent 1.62s making 381988 calls to Mojo::Util::encode, avg 4µs/call |
160 | |||||
161 | sub _string { | ||||
162 | 239553 | 61.4ms | my ($self, $unsafe) = @_; | ||
163 | |||||
164 | # Scheme | ||||
165 | 239553 | 42.9ms | my $url = ''; | ||
166 | 239553 | 249ms | 239553 | 702ms | if (my $proto = $self->protocol) { $url .= "$proto:" } # spent 702ms making 239553 calls to Mojo::URL::protocol, avg 3µs/call |
167 | |||||
168 | # Authority | ||||
169 | 239553 | 160ms | 239553 | 1.92s | my $auth = $self->host_port; # spent 1.92s making 239553 calls to Mojo::URL::host_port, avg 8µs/call |
170 | 239553 | 217ms | 235958 | 2.84s | $auth = _encode($auth, '^A-Za-z0-9\-._~!$&\'()*+,;=:\[\]') if defined $auth; # spent 2.84s making 235958 calls to Mojo::URL::_encode, avg 12µs/call |
171 | 239553 | 30.3ms | 2317 | 1.35ms | if ($unsafe && defined(my $info = $self->userinfo)) { # spent 1.35ms making 2317 calls to Mojo::URL::userinfo, avg 585ns/call |
172 | $auth = _encode($info, '^A-Za-z0-9\-._~!$&\'()*+,;=:') . '@' . $auth; | ||||
173 | } | ||||
174 | 239553 | 67.9ms | $url .= "//$auth" if defined $auth; | ||
175 | |||||
176 | # Path and query | ||||
177 | 239553 | 180ms | 239553 | 9.55s | my $path = $self->path_query; # spent 9.55s making 239553 calls to Mojo::URL::path_query, avg 40µs/call |
178 | 239553 | 476ms | 235958 | 164ms | $url .= !$auth || !length $path || $path =~ m!^[/?]! ? $path : "/$path"; # spent 164ms making 235958 calls to Mojo::URL::CORE:match, avg 696ns/call |
179 | |||||
180 | # Fragment | ||||
181 | 239553 | 292ms | 239553 | 153ms | return $url unless defined(my $fragment = $self->fragment); # spent 153ms making 239553 calls to Mojo::URL::fragment, avg 639ns/call |
182 | 146030 | 327ms | 146030 | 1.62s | return $url . '#' . _encode($fragment, '^A-Za-z0-9\-._~!$&\'()*+,;=:@/?'); # spent 1.62s making 146030 calls to Mojo::URL::_encode, avg 11µs/call |
183 | } | ||||
184 | |||||
185 | 1 | 3µs | 1; | ||
186 | |||||
187 | =encoding utf8 | ||||
188 | |||||
189 | =head1 NAME | ||||
190 | |||||
191 | Mojo::URL - Uniform Resource Locator | ||||
192 | |||||
193 | =head1 SYNOPSIS | ||||
194 | |||||
195 | use Mojo::URL; | ||||
196 | |||||
197 | # Parse | ||||
198 | my $url = Mojo::URL->new('http://sri:foo@example.com:3000/foo?foo=bar#23'); | ||||
199 | say $url->scheme; | ||||
200 | say $url->userinfo; | ||||
201 | say $url->host; | ||||
202 | say $url->port; | ||||
203 | say $url->path; | ||||
204 | say $url->query; | ||||
205 | say $url->fragment; | ||||
206 | |||||
207 | # Build | ||||
208 | my $url = Mojo::URL->new; | ||||
209 | $url->scheme('http'); | ||||
210 | $url->host('example.com'); | ||||
211 | $url->port(3000); | ||||
212 | $url->path('/foo/bar'); | ||||
213 | $url->query(foo => 'bar'); | ||||
214 | $url->fragment(23); | ||||
215 | say "$url"; | ||||
216 | |||||
217 | =head1 DESCRIPTION | ||||
218 | |||||
219 | L<Mojo::URL> implements a subset of L<RFC 3986|https://tools.ietf.org/html/rfc3986>, L<RFC | ||||
220 | 3987|https://tools.ietf.org/html/rfc3987> and the L<URL Living Standard|https://url.spec.whatwg.org> for Uniform | ||||
221 | Resource Locators with support for IDNA and IRIs. | ||||
222 | |||||
223 | =head1 ATTRIBUTES | ||||
224 | |||||
225 | L<Mojo::URL> implements the following attributes. | ||||
226 | |||||
227 | =head2 base | ||||
228 | |||||
229 | my $base = $url->base; | ||||
230 | $url = $url->base(Mojo::URL->new); | ||||
231 | |||||
232 | Base of this URL, defaults to a L<Mojo::URL> object. | ||||
233 | |||||
234 | "http://example.com/a/b?c" | ||||
235 | Mojo::URL->new("/a/b?c")->base(Mojo::URL->new("http://example.com"))->to_abs; | ||||
236 | |||||
237 | =head2 fragment | ||||
238 | |||||
239 | my $fragment = $url->fragment; | ||||
240 | $url = $url->fragment('♥mojolicious♥'); | ||||
241 | |||||
242 | Fragment part of this URL. | ||||
243 | |||||
244 | # "yada" | ||||
245 | Mojo::URL->new('http://example.com/foo?bar=baz#yada')->fragment; | ||||
246 | |||||
247 | =head2 host | ||||
248 | |||||
249 | my $host = $url->host; | ||||
250 | $url = $url->host('127.0.0.1'); | ||||
251 | |||||
252 | Host part of this URL. | ||||
253 | |||||
254 | # "example.com" | ||||
255 | Mojo::URL->new('http://sri:t3st@example.com:8080/foo')->host; | ||||
256 | |||||
257 | =head2 port | ||||
258 | |||||
259 | my $port = $url->port; | ||||
260 | $url = $url->port(8080); | ||||
261 | |||||
262 | Port part of this URL. | ||||
263 | |||||
264 | # "8080" | ||||
265 | Mojo::URL->new('http://sri:t3st@example.com:8080/foo')->port; | ||||
266 | |||||
267 | =head2 scheme | ||||
268 | |||||
269 | my $scheme = $url->scheme; | ||||
270 | $url = $url->scheme('http'); | ||||
271 | |||||
272 | Scheme part of this URL. | ||||
273 | |||||
274 | # "http" | ||||
275 | Mojo::URL->new('http://example.com/foo')->scheme; | ||||
276 | |||||
277 | =head2 userinfo | ||||
278 | |||||
279 | my $info = $url->userinfo; | ||||
280 | $url = $url->userinfo('root:♥'); | ||||
281 | |||||
282 | Userinfo part of this URL. | ||||
283 | |||||
284 | # "sri:t3st" | ||||
285 | Mojo::URL->new('https://sri:t3st@example.com/foo')->userinfo; | ||||
286 | |||||
287 | =head1 METHODS | ||||
288 | |||||
289 | L<Mojo::URL> inherits all methods from L<Mojo::Base> and implements the following new ones. | ||||
290 | |||||
291 | =head2 clone | ||||
292 | |||||
293 | my $url2 = $url->clone; | ||||
294 | |||||
295 | Return a new L<Mojo::URL> object cloned from this URL. | ||||
296 | |||||
297 | =head2 host_port | ||||
298 | |||||
299 | my $host_port = $url->host_port; | ||||
300 | $url = $url->host_port('example.com:8080'); | ||||
301 | |||||
302 | Normalized version of L</"host"> and L</"port">. | ||||
303 | |||||
304 | # "xn--n3h.net:8080" | ||||
305 | Mojo::URL->new('http://☃.net:8080/test')->host_port; | ||||
306 | |||||
307 | # "example.com" | ||||
308 | Mojo::URL->new('http://example.com/test')->host_port; | ||||
309 | |||||
310 | =head2 ihost | ||||
311 | |||||
312 | my $ihost = $url->ihost; | ||||
313 | $url = $url->ihost('xn--bcher-kva.ch'); | ||||
314 | |||||
315 | Host part of this URL in punycode format. | ||||
316 | |||||
317 | # "xn--n3h.net" | ||||
318 | Mojo::URL->new('http://☃.net')->ihost; | ||||
319 | |||||
320 | # "example.com" | ||||
321 | Mojo::URL->new('http://example.com')->ihost; | ||||
322 | |||||
323 | =head2 is_abs | ||||
324 | |||||
325 | my $bool = $url->is_abs; | ||||
326 | |||||
327 | Check if URL is absolute. | ||||
328 | |||||
329 | # True | ||||
330 | Mojo::URL->new('http://example.com')->is_abs; | ||||
331 | Mojo::URL->new('http://example.com/test/index.html')->is_abs; | ||||
332 | |||||
333 | # False | ||||
334 | Mojo::URL->new('test/index.html')->is_abs; | ||||
335 | Mojo::URL->new('/test/index.html')->is_abs; | ||||
336 | Mojo::URL->new('//example.com/test/index.html')->is_abs; | ||||
337 | |||||
338 | =head2 new | ||||
339 | |||||
340 | my $url = Mojo::URL->new; | ||||
341 | my $url = Mojo::URL->new('http://127.0.0.1:3000/foo?f=b&baz=2#foo'); | ||||
342 | |||||
343 | Construct a new L<Mojo::URL> object and L</"parse"> URL if necessary. | ||||
344 | |||||
345 | =head2 parse | ||||
346 | |||||
347 | $url = $url->parse('http://127.0.0.1:3000/foo/bar?fo=o&baz=23#foo'); | ||||
348 | |||||
349 | Parse relative or absolute URL. | ||||
350 | |||||
351 | # "/test/123" | ||||
352 | $url->parse('/test/123?foo=bar')->path; | ||||
353 | |||||
354 | # "example.com" | ||||
355 | $url->parse('http://example.com/test/123?foo=bar')->host; | ||||
356 | |||||
357 | # "sri@example.com" | ||||
358 | $url->parse('mailto:sri@example.com')->path; | ||||
359 | |||||
360 | =head2 password | ||||
361 | |||||
362 | my $password = $url->password; | ||||
363 | |||||
364 | Password part of L</"userinfo">. | ||||
365 | |||||
366 | # "s3cret" | ||||
367 | Mojo::URL->new('http://isabel:s3cret@mojolicious.org')->password; | ||||
368 | |||||
369 | # "s:3:c:r:e:t" | ||||
370 | Mojo::URL->new('http://isabel:s:3:c:r:e:t@mojolicious.org')->password; | ||||
371 | |||||
372 | =head2 path | ||||
373 | |||||
374 | my $path = $url->path; | ||||
375 | $url = $url->path('foo/bar'); | ||||
376 | $url = $url->path('/foo/bar'); | ||||
377 | $url = $url->path(Mojo::Path->new); | ||||
378 | |||||
379 | Path part of this URL, relative paths will be merged with L<Mojo::Path/"merge">, defaults to a L<Mojo::Path> object. | ||||
380 | |||||
381 | # "test" | ||||
382 | Mojo::URL->new('http://example.com/test/Mojo')->path->parts->[0]; | ||||
383 | |||||
384 | # "/test/DOM/HTML" | ||||
385 | Mojo::URL->new('http://example.com/test/Mojo')->path->merge('DOM/HTML'); | ||||
386 | |||||
387 | # "http://example.com/DOM/HTML" | ||||
388 | Mojo::URL->new('http://example.com/test/Mojo')->path('/DOM/HTML'); | ||||
389 | |||||
390 | # "http://example.com/test/DOM/HTML" | ||||
391 | Mojo::URL->new('http://example.com/test/Mojo')->path('DOM/HTML'); | ||||
392 | |||||
393 | # "http://example.com/test/Mojo/DOM/HTML" | ||||
394 | Mojo::URL->new('http://example.com/test/Mojo/')->path('DOM/HTML'); | ||||
395 | |||||
396 | =head2 path_query | ||||
397 | |||||
398 | my $path_query = $url->path_query; | ||||
399 | $url = $url->path_query('/foo/bar?a=1&b=2'); | ||||
400 | |||||
401 | Normalized version of L</"path"> and L</"query">. | ||||
402 | |||||
403 | # "/test?a=1&b=2" | ||||
404 | Mojo::URL->new('http://example.com/test?a=1&b=2')->path_query; | ||||
405 | |||||
406 | # "/" | ||||
407 | Mojo::URL->new('http://example.com/')->path_query; | ||||
408 | |||||
409 | =head2 protocol | ||||
410 | |||||
411 | my $proto = $url->protocol; | ||||
412 | |||||
413 | Normalized version of L</"scheme">. | ||||
414 | |||||
415 | # "http" | ||||
416 | Mojo::URL->new('HtTp://example.com')->protocol; | ||||
417 | |||||
418 | =head2 query | ||||
419 | |||||
420 | my $query = $url->query; | ||||
421 | $url = $url->query({merge => 'to'}); | ||||
422 | $url = $url->query([append => 'with']); | ||||
423 | $url = $url->query(replace => 'with'); | ||||
424 | $url = $url->query('a=1&b=2'); | ||||
425 | $url = $url->query(Mojo::Parameters->new); | ||||
426 | |||||
427 | Query part of this URL, key/value pairs in an array reference will be appended with L<Mojo::Parameters/"append">, and | ||||
428 | key/value pairs in a hash reference merged with L<Mojo::Parameters/"merge">, defaults to a L<Mojo::Parameters> object. | ||||
429 | |||||
430 | # "2" | ||||
431 | Mojo::URL->new('http://example.com?a=1&b=2')->query->param('b'); | ||||
432 | |||||
433 | # "a=2&b=2&c=3" | ||||
434 | Mojo::URL->new('http://example.com?a=1&b=2')->query->merge(a => 2, c => 3); | ||||
435 | |||||
436 | # "http://example.com?a=2&c=3" | ||||
437 | Mojo::URL->new('http://example.com?a=1&b=2')->query(a => 2, c => 3); | ||||
438 | |||||
439 | # "http://example.com?a=2&a=3" | ||||
440 | Mojo::URL->new('http://example.com?a=1&b=2')->query(a => [2, 3]); | ||||
441 | |||||
442 | # "http://example.com?a=2&b=2&c=3" | ||||
443 | Mojo::URL->new('http://example.com?a=1&b=2')->query({a => 2, c => 3}); | ||||
444 | |||||
445 | # "http://example.com?b=2" | ||||
446 | Mojo::URL->new('http://example.com?a=1&b=2')->query({a => undef}); | ||||
447 | |||||
448 | # "http://example.com?a=1&b=2&a=2&c=3" | ||||
449 | Mojo::URL->new('http://example.com?a=1&b=2')->query([a => 2, c => 3]); | ||||
450 | |||||
451 | =head2 to_abs | ||||
452 | |||||
453 | my $abs = $url->to_abs; | ||||
454 | my $abs = $url->to_abs(Mojo::URL->new('http://example.com/foo')); | ||||
455 | |||||
456 | Return a new L<Mojo::URL> object cloned from this relative URL and turn it into an absolute one using L</"base"> or | ||||
457 | provided base URL. | ||||
458 | |||||
459 | # "http://example.com/foo/baz.xml?test=123" | ||||
460 | Mojo::URL->new('baz.xml?test=123') | ||||
461 | ->to_abs(Mojo::URL->new('http://example.com/foo/bar.html')); | ||||
462 | |||||
463 | # "http://example.com/baz.xml?test=123" | ||||
464 | Mojo::URL->new('/baz.xml?test=123') | ||||
465 | ->to_abs(Mojo::URL->new('http://example.com/foo/bar.html')); | ||||
466 | |||||
467 | # "http://example.com/foo/baz.xml?test=123" | ||||
468 | Mojo::URL->new('//example.com/foo/baz.xml?test=123') | ||||
469 | ->to_abs(Mojo::URL->new('http://example.com/foo/bar.html')); | ||||
470 | |||||
471 | =head2 to_string | ||||
472 | |||||
473 | my $str = $url->to_string; | ||||
474 | |||||
475 | Turn URL into a string. Note that L</"userinfo"> will not be included for security reasons. | ||||
476 | |||||
477 | # "http://mojolicious.org" | ||||
478 | Mojo::URL->new->scheme('http')->host('mojolicious.org')->to_string; | ||||
479 | |||||
480 | # "http://mojolicious.org" | ||||
481 | Mojo::URL->new('http://daniel:s3cret@mojolicious.org')->to_string; | ||||
482 | |||||
483 | =head2 to_unsafe_string | ||||
484 | |||||
485 | my $str = $url->to_unsafe_string; | ||||
486 | |||||
487 | Same as L</"to_string">, but includes L</"userinfo">. | ||||
488 | |||||
489 | # "http://daniel:s3cret@mojolicious.org" | ||||
490 | Mojo::URL->new('http://daniel:s3cret@mojolicious.org')->to_unsafe_string; | ||||
491 | |||||
492 | =head2 username | ||||
493 | |||||
494 | my $username = $url->username; | ||||
495 | |||||
496 | Username part of L</"userinfo">. | ||||
497 | |||||
498 | # "isabel" | ||||
499 | Mojo::URL->new('http://isabel:s3cret@mojolicious.org')->username; | ||||
500 | |||||
501 | =head1 OPERATORS | ||||
502 | |||||
503 | L<Mojo::URL> overloads the following operators. | ||||
504 | |||||
505 | =head2 bool | ||||
506 | |||||
507 | my $bool = !!$url; | ||||
508 | |||||
509 | Always true. | ||||
510 | |||||
511 | =head2 stringify | ||||
512 | |||||
513 | my $str = "$url"; | ||||
514 | |||||
515 | Alias for L</"to_string">. | ||||
516 | |||||
517 | =head1 SEE ALSO | ||||
518 | |||||
519 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||
520 | |||||
521 | =cut | ||||
# spent 975ms (602+373) within Mojo::URL::CORE:match which was called 707965 times, avg 1µs/call:
# 235958 times (164ms+0s) by Mojo::URL::_string at line 178, avg 696ns/call
# 235958 times (108ms+0s) by Mojo::URL::ihost at line 42, avg 456ns/call
# 137007 times (300ms+373ms) by Mojo::URL::parse at line 56, avg 5µs/call
# 99042 times (30.5ms+0s) by Mojo::URL::host_port at line 26, avg 308ns/call | |||||
sub Mojo::URL::CORE:subst; # opcode |