← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:33:55 2022
Reported on Wed Dec 14 15:40:02 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm
StatementsExecuted 17157732 statements in 21.3s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4298391165.07s12.7sMojo::URL::::cloneMojo::URL::clone (recurses: max depth 1, inclusive time 892ms)
313722213.78s27.3sMojo::URL::::_stringMojo::URL::_string
313722112.15s12.7sMojo::URL::::path_queryMojo::URL::path_query
413581211.74s3.67sMojo::URL::::host_portMojo::URL::host_port
117976521.71s11.0sMojo::URL::::to_absMojo::URL::to_abs
553730511.65s6.03sMojo::URL::::pathMojo::URL::path
529341211.49s6.62sMojo::URL::::_encodeMojo::URL::_encode
138119111.44s9.03sMojo::URL::::parseMojo::URL::parse
5679832581.25s10.9sMojo::URL::::newMojo::URL::new
361305211.05s1.35sMojo::URL::::queryMojo::URL::query
313722111.03s1.42sMojo::URL::::ihostMojo::URL::ihost
85820641791ms1.23sMojo::URL::::CORE:matchMojo::URL::CORE:match (opcode)
376727206710ms28.3sMojo::URL::::__ANON__[:3]Mojo::URL::__ANON__[:3]
31372211688ms932msMojo::URL::::protocolMojo::URL::protocol
31139611543ms27.6sMojo::URL::::to_stringMojo::URL::to_string
11818855289ms388msMojo::URL::::is_absMojo::URL::is_abs
5867311140ms696msMojo::URL::::_decodeMojo::URL::_decode
1997182158.8ms58.8msMojo::URL::::CORE:substMojo::URL::CORE:subst (opcode)
11117.6ms179msMojo::URL::::BEGIN@2Mojo::URL::BEGIN@2
2326425.87ms190msMojo::URL::::to_unsafe_stringMojo::URL::to_unsafe_string
1112.85ms3.36msMojo::URL::::BEGIN@5Mojo::URL::BEGIN@5
1112.11ms2.48msMojo::URL::::BEGIN@6Mojo::URL::BEGIN@6
11110µs107µsMojo::URL::::BEGIN@7Mojo::URL::BEGIN@7
1118µs29µsMojo::URL::::BEGIN@3Mojo::URL::BEGIN@3
0000s0sMojo::URL::::__ANON__[:9]Mojo::URL::__ANON__[:9]
0000s0sMojo::URL::::passwordMojo::URL::password
0000s0sMojo::URL::::usernameMojo::URL::username
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mojo::URL;
221.09ms2179ms
# spent 179ms (17.6+161) within Mojo::URL::BEGIN@2 which was called: # once (17.6ms+161ms) by JSON::Schema::Modern::BEGIN@23 at line 2
use Mojo::Base -base;
# spent 179ms making 1 call to Mojo::URL::BEGIN@2 # spent 140µs making 1 call to Mojo::Base::import
3376729853ms31139827.6s
# spent 28.3s (710ms+27.6) within Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] which was called 376727 times, avg 75µs/call: # 91595 times (182ms+7.98s) by JSON::Schema::Modern::_eval_subschema at line 510 of JSON/Schema/Modern.pm, avg 89µs/call # 91595 times (172ms+6.75s) by JSON::Schema::Modern::_eval_subschema at line 511 of JSON/Schema/Modern.pm, avg 76µs/call # 72037 times (180ms+6.44s) by JSON::Schema::Modern::Utilities::A at line 247 of JSON/Schema/Modern/Utilities.pm, avg 92µs/call # 47668 times (99.7ms+5.60s) by Data::Perl::Role::Collection::Hash::get at line 24 of Data/Perl/Role/Collection/Hash.pm, avg 120µs/call # 33963 times (36.9ms+0s) by Mojo::URL::to_abs at line 127, avg 1µs/call # 31362 times (21.7ms+0s) by Mojo::URL::clone at line 16, avg 692ns/call # 4217 times (8.34ms+383ms) by JSON::Schema::Modern::Utilities::E at line 213 of JSON/Schema/Modern/Utilities.pm, avg 93µs/call # 4071 times (9.12ms+430ms) by Mojo::URL::CORE:match at line 56, avg 108µs/call # 46 times (90µs+2.91ms) by JSON::Schema::Modern::Document::BUILD at line 168 of JSON/Schema/Modern/Document.pm, avg 65µs/call # 39 times (70µs+3.62ms) by Data::Perl::Role::Collection::Hash::set at line 33 of Data/Perl/Role/Collection/Hash.pm, avg 95µs/call # 39 times (58µs+3.09ms) by Data::Perl::Role::Collection::Hash::set at line 35 of Data/Perl/Role/Collection/Hash.pm, avg 81µs/call # 30 times (90µs+2.82ms) by JSON::Schema::Modern::Document::BUILD at line 149 of JSON/Schema/Modern/Document.pm, avg 97µs/call # 14 times (31µs+1.15ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 67 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 84µs/call # 12 times (56µs+803µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:646] at line 629 of JSON/Schema/Modern.pm, avg 72µs/call # 9 times (19µs+888µs) by JSON::Schema::Modern::add_schema at line 187 of JSON/Schema/Modern.pm, avg 101µs/call # 8 times (15µs+948µs) by JSON::Schema::Modern::_get_or_load_resource at line 784 of JSON/Schema/Modern.pm, avg 120µs/call # 8 times (9µs+520µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Document.pm:135] at line 122 of JSON/Schema/Modern/Document.pm, avg 66µs/call # 6 times (11µs+512µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:646] at line 625 of JSON/Schema/Modern.pm, avg 87µs/call # 6 times (32µs+0s) by JSON::Schema::Modern::add_schema at line 152 of JSON/Schema/Modern.pm, avg 5µs/call # 2 times (3µs+116µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:646] at line 622 of JSON/Schema/Modern.pm, avg 60µs/call # spent 29µs (8+21) within Mojo::URL::BEGIN@3 which was called: # once (8µs+21µs) by JSON::Schema::Modern::BEGIN@23 at line 3
use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
# spent 27.6s making 311396 calls to Mojo::URL::to_string, avg 89µs/call # spent 29µs making 1 call to Mojo::URL::BEGIN@3 # spent 21µs making 1 call to overload::import
4
52599µs23.37ms
# spent 3.36ms (2.85+515µs) within Mojo::URL::BEGIN@5 which was called: # once (2.85ms+515µs) by JSON::Schema::Modern::BEGIN@23 at line 5
use Mojo::Parameters;
# spent 3.36ms making 1 call to Mojo::URL::BEGIN@5 # spent 4µs making 1 call to Mojo::Base::import
62603µs22.48ms
# spent 2.48ms (2.11+367µs) within Mojo::URL::BEGIN@6 which was called: # once (2.11ms+367µs) by JSON::Schema::Modern::BEGIN@23 at line 6
use Mojo::Path;
# spent 2.48ms making 1 call to Mojo::URL::BEGIN@6 # spent 5µs making 1 call to Mojo::Base::import
722.48ms2204µs
# spent 107µs (10+97) within Mojo::URL::BEGIN@7 which was called: # once (10µs+97µs) by JSON::Schema::Modern::BEGIN@23 at line 7
use Mojo::Util qw(decode encode punycode_decode punycode_encode url_escape url_unescape);
# spent 107µs making 1 call to Mojo::URL::BEGIN@7 # spent 97µs making 1 call to Exporter::import
8
918µs167µshas base => sub { Mojo::URL->new };
# spent 67µs making 1 call to Mojo::URL::has
1012µs189µshas [qw(fragment host port scheme userinfo)];
# spent 89µs making 1 call to Mojo::URL::has
11
12
# spent 12.7s (5.07+7.62) within Mojo::URL::clone which was called 429839 times, avg 30µs/call: # 168591 times (2.12s+3.35s) by JSON::Schema::Modern::Utilities::canonical_uri at line 188 of JSON/Schema/Modern/Utilities.pm, avg 32µs/call # 117976 times (1.16s+1.73s) by Mojo::URL::to_abs at line 123, avg 24µs/call # 39123 times (505ms+1.42s) by JSON::Schema::Modern::_fetch_from_uri at line 826 of JSON/Schema/Modern.pm, avg 49µs/call # 39123 times (532ms+785ms) by JSON::Schema::Modern::_fetch_from_uri at line 839 of JSON/Schema/Modern.pm, avg 34µs/call # 31362 times (337ms+-337ms) by Mojo::URL::clone at line 16, avg 0s/call # 25862 times (322ms+529ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_id at line 90 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 33µs/call # 7758 times (99.5ms+150ms) by JSON::Schema::Modern::_fetch_from_uri at line 859 of JSON/Schema/Modern.pm, avg 32µs/call # 15 times (133µs+121µs) by JSON::Schema::Modern::Document::BUILD at line 145 of JSON/Schema/Modern/Document.pm, avg 17µs/call # 14 times (257µs+332µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 81 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 42µs/call # 14 times (68µs+62µs) by JSON::Schema::Modern::Document::traverse at line 178 of JSON/Schema/Modern/Document.pm, avg 9µs/call # once (16µs+25µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 115 of JSON/Schema/Modern/Document/OpenAPI.pm
sub clone {
1342983974.5ms my $self = shift;
14429839300ms4298391.23s my $clone = $self->new;
# spent 1.23s making 429839 calls to Mojo::URL::new, avg 3µs/call
154298391.04s @$clone{keys %$self} = values %$self;
164298391.98s16453346.39s $clone->{$_} && ($clone->{$_} = $clone->{$_}->clone) for qw(base path query);
# spent 3.13s making 361497 calls to Mojo::Parameters::clone, avg 9µs/call # spent 2.78s making 429808 calls to Mojo::Path::clone, avg 6µs/call # spent 257ms making 429808 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 598ns/call # spent 201ms making 361497 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 557ns/call # spent 21.7ms making 31362 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 692ns/call # spent 892ms making 31362 calls to Mojo::URL::clone, avg 28µs/call, recursion: max depth 1, sum of overlapping time 892ms
17429839626ms return $clone;
18}
19
20
# spent 3.67s (1.74+1.93) within Mojo::URL::host_port which was called 413581 times, avg 9µs/call: # 313722 times (1.20s+1.59s) by Mojo::URL::_string at line 169, avg 9µs/call # 99859 times (543ms+341ms) by Mojo::URL::parse at line 63, avg 9µs/call
sub host_port {
21413581104ms my ($self, $host_port) = @_;
22
2341358180.2ms if (defined $host_port) {
2499859126ms9985923.3ms $self->port($1) if $host_port =~ s/:(\d+)$//;
# spent 23.3ms making 99859 calls to Mojo::URL::CORE:subst, avg 233ns/call
259985969.5ms99859188ms my $host = url_unescape $host_port;
# spent 188ms making 99859 calls to Mojo::Util::url_unescape, avg 2µs/call
2699859311ms199718129ms return $host =~ /[^\x00-\x7f]/ ? $self->ihost($host) : $self->host($host);
# spent 93.4ms making 99859 calls to Mojo::URL::host, avg 936ns/call # spent 35.9ms making 99859 calls to Mojo::URL::CORE:match, avg 359ns/call
27 }
28
29313722238ms3137221.42s return undef unless defined(my $host = $self->ihost);
# spent 1.42s making 313722 calls to Mojo::URL::ihost, avg 5µs/call
30310114641ms310114163ms return $host unless defined(my $port = $self->port);
# spent 163ms making 310114 calls to Mojo::URL::port, avg 527ns/call
31 return "$host:$port";
32}
33
34
# spent 1.42s (1.03+393ms) within Mojo::URL::ihost which was called 313722 times, avg 5µs/call: # 313722 times (1.03s+393ms) by Mojo::URL::host_port at line 29, avg 5µs/call
sub ihost {
3531372243.1ms my $self = shift;
36
37 # Decode
3831372245.7ms return $self->host(join '.', map { /^xn--(.+)$/ ? punycode_decode $1 : $_ } split(/\./, shift, -1)) if @_;
39
40 # Check if host needs to be encoded
41313722259ms313722215ms return undef unless defined(my $host = $self->host);
# spent 215ms making 313722 calls to Mojo::URL::host, avg 686ns/call
42310114893ms310114178ms return $host unless $host =~ /[^\x00-\x7f]/;
# spent 178ms making 310114 calls to Mojo::URL::CORE:match, avg 574ns/call
43
44 # Encode
45 return join '.', map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split(/\./, $host, -1);
46}
47
48118188286ms11818899.1ms
# spent 388ms (289+99.1) within Mojo::URL::is_abs which was called 118188 times, avg 3µs/call: # 117976 times (288ms+99.0ms) by Mojo::URL::to_abs at line 124, avg 3µs/call # 151 times (369µs+92µs) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 120 of JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 3µs/call # 46 times (116µs+29µs) by JSON::Schema::Modern::Utilities::assert_uri at line 324 of JSON/Schema/Modern/Utilities.pm, avg 3µs/call # 14 times (34µs+11µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 69 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 3µs/call # once (3µs+2µs) by Type::Tiny::__ANON__[(eval 421)[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Sub/Quote.pm:3]:16] at line 16 of (eval 421)[Sub/Quote.pm:3]
sub is_abs { !!shift->scheme }
# spent 99.1ms making 118188 calls to Mojo::URL::scheme, avg 839ns/call
49
505679831.19s7061029.62s
# spent 10.9s (1.25+9.62) within Mojo::URL::new which was called 567983 times, avg 19µs/call: # 429839 times (791ms+440ms) by Mojo::URL::clone at line 14, avg 3µs/call # 89213 times (275ms+3.91s) by JSON::Schema::Modern::_fetch_from_uri at line 835 of JSON/Schema/Modern.pm, avg 47µs/call # 39121 times (146ms+3.89s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 200 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 103µs/call # 2586 times (9.51ms+325ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 222 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 129µs/call # 2586 times (8.27ms+307ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 234 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 122µs/call # 1390 times (5.17ms+170ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:124] at line 123 of JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 126µs/call # 757 times (2.13ms+168ms) by JSON::Schema::Modern::traverse at line 257 of JSON/Schema/Modern.pm, avg 224µs/call # 743 times (2.91ms+254ms) by JSON::Schema::Modern::traverse at line 235 of JSON/Schema/Modern.pm, avg 345µs/call # 743 times (2.48ms+56.3ms) by JSON::Schema::Modern::traverse at line 250 of JSON/Schema/Modern.pm, avg 79µs/call # 739 times (2.91ms+78.9ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 307 of JSON/Schema/Modern/Utilities.pm, avg 111µs/call # 151 times (527µs+10.7ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 119 of JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 74µs/call # 46 times (171µs+1.86ms) by JSON::Schema::Modern::Utilities::assert_uri at line 322 of JSON/Schema/Modern/Utilities.pm, avg 44µs/call # 15 times (66µs+725µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Document.pm:45] at line 45 of JSON/Schema/Modern/Document.pm, avg 53µs/call # 15 times (26µs+9µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 162 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 2µs/call # 14 times (55µs+511µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 51 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 40µs/call # 9 times (44µs+473µs) by JSON::Schema::Modern::add_schema at line 140 of JSON/Schema/Modern.pm, avg 57µs/call # 8 times (26µs+8µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Document.pm:38] at line 38 of JSON/Schema/Modern/Document.pm, avg 4µs/call # once (11µs+306µs) by JSON::Schema::Modern::Document::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Document.pm:39] at line 39 of JSON/Schema/Modern/Document.pm # once (9µs+185µs) by JSON::Schema::Modern::evaluate at line 302 of JSON/Schema/Modern.pm # once (3µs+159µs) by JSON::Schema::Modern::evaluate at line 319 of JSON/Schema/Modern.pm # once (14µs+128µ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 (6µs+53µs) by Type::Tiny::__ANON__[(eval 421)[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Sub/Quote.pm:3]:16] at line 16 of (eval 421)[Sub/Quote.pm:3] # once (5µs+40µs) by JSON::Schema::Modern::_fetch_from_uri at line 822 of JSON/Schema/Modern.pm # once (5µs+35µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema at line 123 of JSON/Schema/Modern/Vocabulary/Core.pm # once (2µs+1µs) by JSON::Schema::Modern::evaluate at line 305 of JSON/Schema/Modern.pm
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }
# spent 9.03s making 138119 calls to Mojo::URL::parse, avg 65µs/call # spent 584ms making 567983 calls to Mojo::Base::new, avg 1µs/call
51
52
# spent 9.03s (1.44+7.59) within Mojo::URL::parse which was called 138119 times, avg 65µs/call: # 138119 times (1.44s+7.59s) by Mojo::URL::new at line 50, avg 65µs/call
sub parse {
5313811948.8ms my ($self, $url) = @_;
54
55 # Official regex from RFC 3986
56138119477ms1421901.21s $url =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!;
# spent 770ms making 138119 calls to Mojo::URL::CORE:match, avg 6µs/call # spent 439ms making 4071 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 108µs/call
57138119147ms99859132ms $self->scheme($2) if defined $2;
# spent 132ms making 99859 calls to Mojo::URL::scheme, avg 1µs/call
58138119166ms1381194.84s $self->path($5) if defined $5;
# spent 4.84s making 138119 calls to Mojo::URL::path, avg 35µs/call
5913811948.7ms $self->query($7) if defined $7;
60138119175ms176019930ms $self->fragment(_decode(url_unescape $9)) if defined $9;
# spent 696ms making 58673 calls to Mojo::URL::_decode, avg 12µs/call # spent 169ms making 58673 calls to Mojo::Util::url_unescape, avg 3µs/call # spent 65.2ms making 58673 calls to Mojo::URL::fragment, avg 1µs/call
6113811991.1ms if (defined(my $auth = $4)) {
6299859140ms9985935.5ms $self->userinfo(_decode(url_unescape $1)) if $auth =~ s/^([^\@]+)\@//;
# spent 35.5ms making 99859 calls to Mojo::URL::CORE:subst, avg 356ns/call
639985968.5ms99859884ms $self->host_port($auth);
# spent 884ms making 99859 calls to Mojo::URL::host_port, avg 9µs/call
64 }
65
66138119176ms return $self;
67}
68
69sub password { (shift->userinfo // '') =~ /:(.*)$/ ? $1 : undef }
70
71
# spent 6.03s (1.65+4.38) within Mojo::URL::path which was called 553730 times, avg 11µs/call: # 313722 times (745ms+144ms) by Mojo::URL::path_query at line 93, avg 3µs/call # 138119 times (653ms+4.19s) by Mojo::URL::parse at line 58, avg 35µs/call # 36204 times (93.8ms+16.6ms) by Mojo::URL::to_abs at line 147, avg 3µs/call # 33963 times (84.0ms+15.4ms) by Mojo::URL::to_abs at line 135, avg 3µs/call # 31722 times (79.2ms+14.3ms) by Mojo::URL::to_abs at line 140, avg 3µs/call
sub path {
7255373074.0ms my $self = shift;
73
74 # Old path
75553730528ms553730533ms $self->{path} ||= Mojo::Path->new;
# spent 342ms making 138151 calls to Mojo::Path::new, avg 2µs/call # spent 191ms making 415579 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 459ns/call
76553730522ms return $self->{path} unless @_;
77
78 # New path
79172082211ms1381193.85s $self->{path} = ref $_[0] ? $_[0] : $self->{path}->merge($_[0]);
# spent 3.85s making 138119 calls to Mojo::Path::merge, avg 28µs/call
80
81172082185ms return $self;
82}
83
84
# spent 12.7s (2.15+10.5) within Mojo::URL::path_query which was called 313722 times, avg 40µs/call: # 313722 times (2.15s+10.5s) by Mojo::URL::_string at line 177, avg 40µs/call
sub path_query {
8531372261.8ms my ($self, $pq) = @_;
86
8731372246.1ms if (defined $pq) {
88 return $self unless $pq =~ /^([^?#]*)(?:\?([^#]*))?/;
89 return defined $2 ? $self->path($1)->query($2) : $self->path($1);
90 }
91
92313722413ms6274443.08s my $query = $self->query->to_string;
# spent 1.95s making 313722 calls to Mojo::Parameters::to_string, avg 6µs/call # spent 1.14s making 313722 calls to Mojo::URL::query, avg 4µs/call
93313722987ms6274447.43s return $self->path->to_string . (length $query ? "?$query" : '');
# spent 6.54s making 313722 calls to Mojo::Path::to_string, avg 21µs/call # spent 889ms making 313722 calls to Mojo::URL::path, avg 3µs/call
94}
95
96313722630ms313722244ms
# spent 932ms (688+244) within Mojo::URL::protocol which was called 313722 times, avg 3µs/call: # 313722 times (688ms+244ms) by Mojo::URL::_string at line 166, avg 3µs/call
sub protocol { lc(shift->scheme // '') }
# spent 244ms making 313722 calls to Mojo::URL::scheme, avg 778ns/call
97
98
# spent 1.35s (1.05+303ms) within Mojo::URL::query which was called 361305 times, avg 4µs/call: # 313722 times (901ms+237ms) by Mojo::URL::path_query at line 92, avg 4µs/call # 47583 times (149ms+66.6ms) by Mojo::URL::to_abs at line 143, avg 5µs/call
sub query {
9936130550.9ms my $self = shift;
100
101 # Old parameters
102361305409ms361305303ms my $q = $self->{query} ||= Mojo::Parameters->new;
# spent 160ms making 313144 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 512ns/call # spent 143ms making 48161 calls to Mojo::Parameters::new, avg 3µs/call
103361305415ms return $q unless @_;
104
105 # Replace with list
1061586124.9ms 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
115158617.78ms else { $self->{query} = ref $_[0] ? $_[0] : $q->parse($_[0]) }
116
1171586117.5ms return $self;
118}
119
120
# spent 11.0s (1.71+9.29) within Mojo::URL::to_abs which was called 117976 times, avg 93µs/call: # 72037 times (315ms+2.20s) by JSON::Schema::Modern::Utilities::A at line 242 of JSON/Schema/Modern/Utilities.pm, avg 35µs/call # 39121 times (1.27s+6.65s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 200 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 202µs/call # 4217 times (19.8ms+135ms) by JSON::Schema::Modern::Utilities::E at line 208 of JSON/Schema/Modern/Utilities.pm, avg 37µs/call # 2586 times (106ms+306ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 222 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 159µs/call # 15 times (652µs+2.24ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 162 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 193µs/call
sub to_abs {
12111797621.5ms my $self = shift;
122
123117976101ms1179762.89s my $abs = $self->clone;
# spent 2.89s making 117976 calls to Mojo::URL::clone, avg 24µs/call
124117976245ms117976387ms return $abs if $abs->is_abs;
# spent 387ms making 117976 calls to Mojo::URL::is_abs, avg 3µs/call
125
126 # Scheme
1273396355.4ms3396336.9ms my $base = shift || $abs->base;
# spent 36.9ms making 33963 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 1µs/call
1283396388.5ms101889127ms $abs->base($base)->scheme($base->scheme);
# spent 65.8ms making 33963 calls to Mojo::URL::base, avg 2µs/call # spent 61.0ms making 67926 calls to Mojo::URL::scheme, avg 898ns/call
129
130 # Authority
1313396335.3ms3396319.7ms return $abs if $abs->host;
# spent 19.7ms making 33963 calls to Mojo::URL::host, avg 580ns/call
13233963124ms203778188ms $abs->userinfo($base->userinfo)->host($base->host)->port($base->port);
# spent 64.5ms making 67926 calls to Mojo::URL::port, avg 949ns/call # spent 64.0ms making 67926 calls to Mojo::URL::host, avg 942ns/call # spent 59.1ms making 67926 calls to Mojo::URL::userinfo, avg 870ns/call
133
134 # Absolute path
1353396336.6ms3396399.4ms my $path = $abs->path;
# spent 99.4ms making 33963 calls to Mojo::URL::path, avg 3µs/call
1363396334.7ms33963102ms return $abs if $path->leading_slash;
# spent 102ms making 33963 calls to Mojo::Path::leading_slash, avg 3µs/call
137
138 # Inherit path
1393396357.9ms3396375.8ms if (!@{$path->parts}) {
# spent 75.8ms making 33963 calls to Mojo::Path::parts, avg 2µs/call
1401586148.7ms63444738ms $abs->path($base->path->clone->canonicalize);
# spent 550ms making 15861 calls to Mojo::Path::canonicalize, avg 35µs/call # spent 94.3ms making 15861 calls to Mojo::Path::clone, avg 6µs/call # spent 93.5ms making 31722 calls to Mojo::URL::path, avg 3µs/call
141
142 # Query
1431586158.3ms79305466ms $abs->query($base->query->clone) unless length $abs->query->to_string;
# spent 215ms making 47583 calls to Mojo::URL::query, avg 5µs/call # spent 136ms making 15861 calls to Mojo::Parameters::clone, avg 9µs/call # spent 115ms making 15861 calls to Mojo::Parameters::to_string, avg 7µs/call
144 }
145
146 # Merge paths
1471810273.2ms905104.17s else { $abs->path($base->path->clone->merge($path)->canonicalize) }
# spent 3.76s making 18102 calls to Mojo::Path::merge, avg 208µs/call # spent 195ms making 18102 calls to Mojo::Path::canonicalize, avg 11µs/call # spent 110ms making 36204 calls to Mojo::URL::path, avg 3µs/call # spent 102ms making 18102 calls to Mojo::Path::clone, avg 6µs/call
148
1493396390.6ms return $abs;
150}
151
152311396578ms31139627.1s
# spent 27.6s (543ms+27.1) within Mojo::URL::to_string which was called 311396 times, avg 89µs/call: # 311396 times (543ms+27.1s) by Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] at line 3, avg 89µs/call
sub to_string { shift->_string(0) }
# spent 27.1s making 311396 calls to Mojo::URL::_string, avg 87µs/call
15323268.40ms2326185ms
# spent 190ms (5.87+185) within Mojo::URL::to_unsafe_string which was called 2326 times, avg 82µs/call: # 1390 times (3.72ms+109ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:124] at line 123 of JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 81µs/call # 739 times (1.64ms+57.6ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 307 of JSON/Schema/Modern/Utilities.pm, avg 80µs/call # 151 times (421µs+13.7ms) by JSON::Schema::Modern::Vocabulary::FormatAssertion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/FormatAssertion.pm:121] at line 120 of JSON/Schema/Modern/Vocabulary/FormatAssertion.pm, avg 93µs/call # 46 times (92µs+4.12ms) by JSON::Schema::Modern::Utilities::assert_uri at line 324 of JSON/Schema/Modern/Utilities.pm, avg 92µs/call
sub to_unsafe_string { shift->_string(1) }
# spent 185ms making 2326 calls to Mojo::URL::_string, avg 79µs/call
154
155sub username { (shift->userinfo // '') =~ /^([^:]+)/ ? $1 : undef }
156
15758673129ms58673555ms
# spent 696ms (140+555) within Mojo::URL::_decode which was called 58673 times, avg 12µs/call: # 58673 times (140ms+555ms) by Mojo::URL::parse at line 60, avg 12µs/call
sub _decode { decode('UTF-8', $_[0]) // $_[0] }
# spent 555ms making 58673 calls to Mojo::Util::decode, avg 9µs/call
158
1595293411.13s10586825.14s
# spent 6.62s (1.49+5.14) within Mojo::URL::_encode which was called 529341 times, avg 13µs/call: # 310114 times (896ms+3.15s) by Mojo::URL::_string at line 170, avg 13µs/call # 219227 times (589ms+1.99s) by Mojo::URL::_string at line 182, avg 12µs/call
sub _encode { url_escape encode('UTF-8', $_[0]), $_[1] }
# spent 2.81s making 529341 calls to Mojo::Util::url_escape, avg 5µs/call # spent 2.33s making 529341 calls to Mojo::Util::encode, avg 4µs/call
160
161
# spent 27.3s (3.78+23.5) within Mojo::URL::_string which was called 313722 times, avg 87µs/call: # 311396 times (3.75s+23.3s) by Mojo::URL::to_string at line 152, avg 87µs/call # 2326 times (27.5ms+157ms) by Mojo::URL::to_unsafe_string at line 153, avg 79µs/call
sub _string {
16231372283.1ms my ($self, $unsafe) = @_;
163
164 # Scheme
16531372264.6ms my $url = '';
166313722356ms313722932ms if (my $proto = $self->protocol) { $url .= "$proto:" }
# spent 932ms making 313722 calls to Mojo::URL::protocol, avg 3µs/call
167
168 # Authority
169313722232ms3137222.79s my $auth = $self->host_port;
# spent 2.79s making 313722 calls to Mojo::URL::host_port, avg 9µs/call
170313722314ms3101144.05s $auth = _encode($auth, '^A-Za-z0-9\-._~!$&\'()*+,;=:\[\]') if defined $auth;
# spent 4.05s making 310114 calls to Mojo::URL::_encode, avg 13µs/call
17131372238.4ms23261.23ms if ($unsafe && defined(my $info = $self->userinfo)) {
# spent 1.23ms making 2326 calls to Mojo::URL::userinfo, avg 528ns/call
172 $auth = _encode($info, '^A-Za-z0-9\-._~!$&\'()*+,;=:') . '@' . $auth;
173 }
17431372295.0ms $url .= "//$auth" if defined $auth;
175
176 # Path and query
177313722262ms31372212.7s my $path = $self->path_query;
# spent 12.7s making 313722 calls to Mojo::URL::path_query, avg 40µs/call
178313722686ms310114245ms $url .= !$auth || !length $path || $path =~ m!^[/?]! ? $path : "/$path";
# spent 245ms making 310114 calls to Mojo::URL::CORE:match, avg 792ns/call
179
180 # Fragment
181313722394ms313722215ms return $url unless defined(my $fragment = $self->fragment);
# spent 215ms making 313722 calls to Mojo::URL::fragment, avg 684ns/call
182219227556ms2192272.58s return $url . '#' . _encode($fragment, '^A-Za-z0-9\-._~!$&\'()*+,;=:@/?');
# spent 2.58s making 219227 calls to Mojo::URL::_encode, avg 12µs/call
183}
184
18517µs1;
186
187=encoding utf8
188
189=head1 NAME
190
191Mojo::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
219L<Mojo::URL> implements a subset of L<RFC 3986|https://tools.ietf.org/html/rfc3986>, L<RFC
2203987|https://tools.ietf.org/html/rfc3987> and the L<URL Living Standard|https://url.spec.whatwg.org> for Uniform
221Resource Locators with support for IDNA and IRIs.
222
223=head1 ATTRIBUTES
224
225L<Mojo::URL> implements the following attributes.
226
227=head2 base
228
229 my $base = $url->base;
230 $url = $url->base(Mojo::URL->new);
231
232Base 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
242Fragment 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
252Host 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
262Port 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
272Scheme 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
282Userinfo part of this URL.
283
284 # "sri:t3st"
285 Mojo::URL->new('https://sri:t3st@example.com/foo')->userinfo;
286
287=head1 METHODS
288
289L<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
295Return 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
302Normalized 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
315Host 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
327Check 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
343Construct 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
349Parse 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
364Password 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
379Path 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
401Normalized 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
413Normalized 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
427Query part of this URL, key/value pairs in an array reference will be appended with L<Mojo::Parameters/"append">, and
428key/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
456Return a new L<Mojo::URL> object cloned from this relative URL and turn it into an absolute one using L</"base"> or
457provided 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
475Turn 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
487Same 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
496Username part of L</"userinfo">.
497
498 # "isabel"
499 Mojo::URL->new('http://isabel:s3cret@mojolicious.org')->username;
500
501=head1 OPERATORS
502
503L<Mojo::URL> overloads the following operators.
504
505=head2 bool
506
507 my $bool = !!$url;
508
509Always true.
510
511=head2 stringify
512
513 my $str = "$url";
514
515Alias for L</"to_string">.
516
517=head1 SEE ALSO
518
519L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
520
521=cut
 
# spent 1.23s (791ms+439ms) within Mojo::URL::CORE:match which was called 858206 times, avg 1µs/call: # 310114 times (245ms+0s) by Mojo::URL::_string at line 178, avg 792ns/call # 310114 times (178ms+0s) by Mojo::URL::ihost at line 42, avg 574ns/call # 138119 times (332ms+439ms) by Mojo::URL::parse at line 56, avg 6µs/call # 99859 times (35.9ms+0s) by Mojo::URL::host_port at line 26, avg 359ns/call
sub Mojo::URL::CORE:match; # opcode
# spent 58.8ms within Mojo::URL::CORE:subst which was called 199718 times, avg 295ns/call: # 99859 times (35.5ms+0s) by Mojo::URL::parse at line 62, avg 356ns/call # 99859 times (23.3ms+0s) by Mojo::URL::host_port at line 24, avg 233ns/call
sub Mojo::URL::CORE:subst; # opcode