← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:30 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm
StatementsExecuted 16824323 statements in 22.9s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
3876261165.21s12.9sMojo::URL::::cloneMojo::URL::clone (recurses: max depth 1, inclusive time 1.00s)
311941214.22s30.3sMojo::URL::::_stringMojo::URL::_string
311941112.47s14.3sMojo::URL::::path_queryMojo::URL::path_query
411643211.90s4.00sMojo::URL::::host_portMojo::URL::host_port
117729521.86s12.3sMojo::URL::::to_absMojo::URL::to_abs
550415511.81s6.55sMojo::URL::::pathMojo::URL::path
136585111.59s9.90sMojo::URL::::parseMojo::URL::parse
527158211.57s7.26sMojo::URL::::_encodeMojo::URL::_encode
5242362371.34s11.9sMojo::URL::::newMojo::URL::new
359524211.18s1.53sMojo::URL::::queryMojo::URL::query
311941111.14s1.55sMojo::URL::::ihostMojo::URL::ihost
85570741860ms1.36sMojo::URL::::CORE:matchMojo::URL::CORE:match (opcode)
31194111790ms1.06sMojo::URL::::protocolMojo::URL::protocol
376480206742ms31.5sMojo::URL::::__ANON__[:3]Mojo::URL::__ANON__[:3]
31114911619ms30.8sMojo::URL::::to_stringMojo::URL::to_string
11779044322ms431msMojo::URL::::is_absMojo::URL::is_abs
5714111134ms743msMojo::URL::::_decodeMojo::URL::_decode
1994042162.8ms62.8msMojo::URL::::CORE:substMojo::URL::CORE:subst (opcode)
11118.6ms158msMojo::URL::::BEGIN@2Mojo::URL::BEGIN@2
1112.65ms3.27msMojo::URL::::BEGIN@5Mojo::URL::BEGIN@5
792212.12ms75.5msMojo::URL::::to_unsafe_stringMojo::URL::to_unsafe_string
1111.64ms2.00msMojo::URL::::BEGIN@6Mojo::URL::BEGIN@6
11112µs44µsMojo::URL::::BEGIN@3Mojo::URL::BEGIN@3
11110µs137µsMojo::URL::::BEGIN@7Mojo::URL::BEGIN@7
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;
22648µs2158ms
# spent 158ms (18.6+139) within Mojo::URL::BEGIN@2 which was called: # once (18.6ms+139ms) by JSON::Schema::Modern::BEGIN@23 at line 2
use Mojo::Base -base;
# spent 158ms making 1 call to Mojo::URL::BEGIN@2 # spent 243µs making 1 call to Mojo::Base::import
3376482942ms31115130.8s
# spent 44µs (12+32) within Mojo::URL::BEGIN@3 which was called: # once (12µs+32µs) by JSON::Schema::Modern::BEGIN@23 at line 3 # spent 31.5s (742ms+30.8) within Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] which was called 376480 times, avg 84µs/call: # 91595 times (214ms+8.90s) by JSON::Schema::Modern::_eval_subschema at line 544 of JSON/Schema/Modern.pm, avg 99µs/call # 91595 times (170ms+7.68s) by JSON::Schema::Modern::_eval_subschema at line 545 of JSON/Schema/Modern.pm, avg 86µs/call # 71790 times (155ms+7.14s) by JSON::Schema::Modern::Utilities::A at line 252 of JSON/Schema/Modern/Utilities.pm, avg 102µs/call # 47668 times (112ms+6.19s) by Data::Perl::Role::Collection::Hash::get at line 24 of Data/Perl/Role/Collection/Hash.pm, avg 132µs/call # 33963 times (37.4ms+0s) by Mojo::URL::to_abs at line 127, avg 1µs/call # 31362 times (27.5ms+0s) by Mojo::URL::clone at line 16, avg 878ns/call # 4217 times (8.85ms+393ms) by JSON::Schema::Modern::Utilities::E at line 218 of JSON/Schema/Modern/Utilities.pm, avg 95µs/call # 4071 times (15.6ms+488ms) by Mojo::URL::CORE:match at line 56, avg 124µs/call # 46 times (83µs+2.72ms) by JSON::Schema::Modern::Document::BUILD at line 168 of JSON/Schema/Modern/Document.pm, avg 61µs/call # 39 times (172µs+4.55ms) by Data::Perl::Role::Collection::Hash::set at line 33 of Data/Perl/Role/Collection/Hash.pm, avg 121µs/call # 39 times (74µs+4.15ms) by Data::Perl::Role::Collection::Hash::set at line 35 of Data/Perl/Role/Collection/Hash.pm, avg 108µs/call # 30 times (102µs+3.11ms) by JSON::Schema::Modern::Document::BUILD at line 149 of JSON/Schema/Modern/Document.pm, avg 107µs/call # 14 times (41µs+1.28ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 67 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 95µs/call # 12 times (22µs+845µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:672] at line 655 of JSON/Schema/Modern.pm, avg 72µs/call # 9 times (39µs+1.02ms) by JSON::Schema::Modern::add_schema at line 187 of JSON/Schema/Modern.pm, avg 117µs/call # 8 times (29µs+1.04ms) by JSON::Schema::Modern::_get_or_load_resource at line 810 of JSON/Schema/Modern.pm, avg 134µs/call # 8 times (19µs+939µ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 120µs/call # 6 times (10µs+476µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:672] at line 651 of JSON/Schema/Modern.pm, avg 81µs/call # 6 times (14µs+0s) by JSON::Schema::Modern::add_schema at line 152 of JSON/Schema/Modern.pm, avg 2µs/call # 2 times (2µs+95µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:672] at line 648 of JSON/Schema/Modern.pm, avg 48µs/call
use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
# spent 30.8s making 311149 calls to Mojo::URL::to_string, avg 99µs/call # spent 44µs making 1 call to Mojo::URL::BEGIN@3 # spent 32µs making 1 call to overload::import
4
52530µs23.27ms
# spent 3.27ms (2.65+614µs) within Mojo::URL::BEGIN@5 which was called: # once (2.65ms+614µs) by JSON::Schema::Modern::BEGIN@23 at line 5
use Mojo::Parameters;
# spent 3.27ms making 1 call to Mojo::URL::BEGIN@5 # spent 4µs making 1 call to Mojo::Base::import
62601µs22.01ms
# spent 2.00ms (1.64+365µs) within Mojo::URL::BEGIN@6 which was called: # once (1.64ms+365µs) by JSON::Schema::Modern::BEGIN@23 at line 6
use Mojo::Path;
# spent 2.00ms making 1 call to Mojo::URL::BEGIN@6 # spent 2µs making 1 call to Mojo::Base::import
721.47ms2264µs
# spent 137µs (10+127) within Mojo::URL::BEGIN@7 which was called: # once (10µs+127µ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 137µs making 1 call to Mojo::URL::BEGIN@7 # spent 127µs making 1 call to Exporter::import
8
914µs143µshas base => sub { Mojo::URL->new };
# spent 43µs making 1 call to Mojo::URL::has
1012µs168µshas [qw(fragment host port scheme userinfo)];
# spent 68µs making 1 call to Mojo::URL::has
11
12
# spent 12.9s (5.21+7.66) within Mojo::URL::clone which was called 387626 times, avg 33µs/call: # 126625 times (1.83s+2.92s) by JSON::Schema::Modern::Utilities::canonical_uri at line 192 of JSON/Schema/Modern/Utilities.pm, avg 38µs/call # 117729 times (1.35s+1.90s) by Mojo::URL::to_abs at line 123, avg 28µs/call # 39123 times (567ms+1.57s) by JSON::Schema::Modern::_fetch_from_uri at line 852 of JSON/Schema/Modern.pm, avg 55µs/call # 39123 times (581ms+893ms) by JSON::Schema::Modern::_fetch_from_uri at line 865 of JSON/Schema/Modern.pm, avg 38µs/call # 31362 times (392ms+-392ms) by Mojo::URL::clone at line 16, avg 0s/call # 25862 times (365ms+578ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_id at line 90 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 36µs/call # 7758 times (114ms+184ms) by JSON::Schema::Modern::_fetch_from_uri at line 885 of JSON/Schema/Modern.pm, avg 38µs/call # 15 times (211µs+137µs) by JSON::Schema::Modern::Document::BUILD at line 145 of JSON/Schema/Modern/Document.pm, avg 23µs/call # 14 times (298µs+428µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 81 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 52µs/call # 14 times (105µs+79µs) by JSON::Schema::Modern::Document::traverse at line 178 of JSON/Schema/Modern/Document.pm, avg 13µs/call # once (15µs+26µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 115 of JSON/Schema/Modern/Document/OpenAPI.pm
sub clone {
1338762670.0ms my $self = shift;
14387626294ms3876261.28s my $clone = $self->new;
# spent 1.28s making 387626 calls to Mojo::URL::new, avg 3µs/call
153876261.08s @$clone{keys %$self} = values %$self;
163876261.99s14764826.38s $clone->{$_} && ($clone->{$_} = $clone->{$_}->clone) for qw(base path query);
# spent 3.13s making 319284 calls to Mojo::Parameters::clone, avg 10µs/call # spent 2.75s making 387595 calls to Mojo::Path::clone, avg 7µs/call # spent 265ms making 387595 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 684ns/call # spent 206ms making 319284 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 644ns/call # spent 27.5ms making 31362 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 878ns/call # spent 1.00s making 31362 calls to Mojo::URL::clone, avg 32µs/call, recursion: max depth 1, sum of overlapping time 1.00s
17387626617ms return $clone;
18}
19
20
# spent 4.00s (1.90+2.11) within Mojo::URL::host_port which was called 411643 times, avg 10µs/call: # 311941 times (1.24s+1.72s) by Mojo::URL::_string at line 169, avg 9µs/call # 99702 times (658ms+384ms) by Mojo::URL::parse at line 63, avg 10µs/call
sub host_port {
21411643105ms my ($self, $host_port) = @_;
22
2341164365.9ms if (defined $host_port) {
2499702144ms9970225.5ms $self->port($1) if $host_port =~ s/:(\d+)$//;
# spent 25.5ms making 99702 calls to Mojo::URL::CORE:subst, avg 256ns/call
259970280.2ms99702217ms my $host = url_unescape $host_port;
# spent 217ms making 99702 calls to Mojo::Util::url_unescape, avg 2µs/call
2699702353ms199404142ms return $host =~ /[^\x00-\x7f]/ ? $self->ihost($host) : $self->host($host);
# spent 103ms making 99702 calls to Mojo::URL::host, avg 1µs/call # spent 38.8ms making 99702 calls to Mojo::URL::CORE:match, avg 389ns/call
27 }
28
29311941248ms3119411.55s return undef unless defined(my $host = $self->ihost);
# spent 1.55s making 311941 calls to Mojo::URL::ihost, avg 5µs/call
30309710642ms309710178ms return $host unless defined(my $port = $self->port);
# spent 178ms making 309710 calls to Mojo::URL::port, avg 574ns/call
31 return "$host:$port";
32}
33
34
# spent 1.55s (1.14+410ms) within Mojo::URL::ihost which was called 311941 times, avg 5µs/call: # 311941 times (1.14s+410ms) by Mojo::URL::host_port at line 29, avg 5µs/call
sub ihost {
3531194151.6ms my $self = shift;
36
37 # Decode
3831194143.6ms return $self->host(join '.', map { /^xn--(.+)$/ ? punycode_decode $1 : $_ } split(/\./, shift, -1)) if @_;
39
40 # Check if host needs to be encoded
41311941269ms311941230ms return undef unless defined(my $host = $self->host);
# spent 230ms making 311941 calls to Mojo::URL::host, avg 736ns/call
42309710955ms309710180ms return $host unless $host =~ /[^\x00-\x7f]/;
# spent 180ms making 309710 calls to Mojo::URL::CORE:match, avg 581ns/call
43
44 # Encode
45 return join '.', map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split(/\./, $host, -1);
46}
47
48117790297ms117790109ms
# spent 431ms (322+109) within Mojo::URL::is_abs which was called 117790 times, avg 4µs/call: # 117729 times (322ms+109ms) by Mojo::URL::to_abs at line 124, avg 4µs/call # 46 times (120µs+50µs) by JSON::Schema::Modern::Utilities::assert_uri at line 329 of JSON/Schema/Modern/Utilities.pm, avg 4µs/call # 14 times (67µs+9µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 69 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 5µs/call # once (3µs+0s) 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 109ms making 117790 calls to Mojo::URL::scheme, avg 924ns/call
49
505242361.23s66082110.5s
# spent 11.9s (1.34+10.5) within Mojo::URL::new which was called 524236 times, avg 23µs/call: # 387626 times (802ms+477ms) by Mojo::URL::clone at line 14, avg 3µs/call # 89213 times (344ms+4.38s) by JSON::Schema::Modern::_fetch_from_uri at line 861 of JSON/Schema/Modern.pm, avg 53µs/call # 39121 times (163ms+4.26s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 209 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 113µs/call # 2586 times (11.9ms+356ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 231 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 142µs/call # 2586 times (9.10ms+345ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 243 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 137µs/call # 757 times (3.20ms+228ms) by JSON::Schema::Modern::traverse at line 257 of JSON/Schema/Modern.pm, avg 306µs/call # 746 times (3.93ms+101ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 312 of JSON/Schema/Modern/Utilities.pm, avg 141µs/call # 743 times (3.64ms+305ms) by JSON::Schema::Modern::traverse at line 235 of JSON/Schema/Modern.pm, avg 416µs/call # 743 times (3.40ms+74.5ms) by JSON::Schema::Modern::traverse at line 250 of JSON/Schema/Modern.pm, avg 105µs/call # 46 times (167µs+2.08ms) by JSON::Schema::Modern::Utilities::assert_uri at line 327 of JSON/Schema/Modern/Utilities.pm, avg 49µs/call # 15 times (90µs+831µ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 61µs/call # 15 times (83µs+47µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 171 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 9µs/call # 14 times (49µs+573µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id at line 51 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 44µs/call # 9 times (63µs+829µs) by JSON::Schema::Modern::add_schema at line 140 of JSON/Schema/Modern.pm, avg 99µs/call # 8 times (28µs+6µ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 (16µs+383µ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 (3µs+233µs) by JSON::Schema::Modern::evaluate at line 319 of JSON/Schema/Modern.pm # once (3µs+130µs) by JSON::Schema::Modern::evaluate at line 302 of JSON/Schema/Modern.pm # once (8µs+57µ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 (4µs+58µs) by JSON::Schema::Modern::_fetch_from_uri at line 848 of JSON/Schema/Modern.pm # once (4µs+48µ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+43µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema at line 132 of JSON/Schema/Modern/Vocabulary/Core.pm # once (3µs+0s) 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.90s making 136585 calls to Mojo::URL::parse, avg 72µs/call # spent 632ms making 524236 calls to Mojo::Base::new, avg 1µs/call
51
52
# spent 9.90s (1.59+8.31) within Mojo::URL::parse which was called 136585 times, avg 72µs/call: # 136585 times (1.59s+8.31s) by Mojo::URL::new at line 50, avg 72µs/call
sub parse {
5313658544.5ms my ($self, $url) = @_;
54
55 # Official regex from RFC 3986
56136585554ms1406561.38s $url =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!;
# spent 878ms making 136585 calls to Mojo::URL::CORE:match, avg 6µs/call # spent 504ms making 4071 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 124µs/call
57136585150ms99702149ms $self->scheme($2) if defined $2;
# spent 149ms making 99702 calls to Mojo::URL::scheme, avg 1µs/call
58136585167ms1365855.22s $self->path($5) if defined $5;
# spent 5.22s making 136585 calls to Mojo::URL::path, avg 38µs/call
5913658550.7ms $self->query($7) if defined $7;
60136585172ms171423977ms $self->fragment(_decode(url_unescape $9)) if defined $9;
# spent 743ms making 57141 calls to Mojo::URL::_decode, avg 13µs/call # spent 169ms making 57141 calls to Mojo::Util::url_unescape, avg 3µs/call # spent 64.5ms making 57141 calls to Mojo::URL::fragment, avg 1µs/call
6113658596.1ms if (defined(my $auth = $4)) {
6299702182ms9970237.3ms $self->userinfo(_decode(url_unescape $1)) if $auth =~ s/^([^\@]+)\@//;
# spent 37.3ms making 99702 calls to Mojo::URL::CORE:subst, avg 374ns/call
639970276.6ms997021.04s $self->host_port($auth);
# spent 1.04s making 99702 calls to Mojo::URL::host_port, avg 10µs/call
64 }
65
66136585193ms return $self;
67}
68
69sub password { (shift->userinfo // '') =~ /:(.*)$/ ? $1 : undef }
70
71
# spent 6.55s (1.81+4.74) within Mojo::URL::path which was called 550415 times, avg 12µs/call: # 311941 times (829ms+162ms) by Mojo::URL::path_query at line 93, avg 3µs/call # 136585 times (694ms+4.53s) by Mojo::URL::parse at line 58, avg 38µs/call # 36204 times (109ms+19.0ms) by Mojo::URL::to_abs at line 147, avg 4µs/call # 33963 times (90.4ms+17.1ms) by Mojo::URL::to_abs at line 135, avg 3µs/call # 31722 times (83.9ms+15.8ms) by Mojo::URL::to_abs at line 140, avg 3µs/call
sub path {
7255041581.6ms my $self = shift;
73
74 # Old path
75550415575ms550415577ms $self->{path} ||= Mojo::Path->new;
# spent 363ms making 136617 calls to Mojo::Path::new, avg 3µs/call # spent 213ms making 413798 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 515ns/call
76550415587ms return $self->{path} unless @_;
77
78 # New path
79170548253ms1365854.17s $self->{path} = ref $_[0] ? $_[0] : $self->{path}->merge($_[0]);
# spent 4.17s making 136585 calls to Mojo::Path::merge, avg 31µs/call
80
81170548206ms return $self;
82}
83
84
# spent 14.3s (2.47+11.8) within Mojo::URL::path_query which was called 311941 times, avg 46µs/call: # 311941 times (2.47s+11.8s) by Mojo::URL::_string at line 177, avg 46µs/call
sub path_query {
8531194164.4ms my ($self, $pq) = @_;
86
8731194145.0ms if (defined $pq) {
88 return $self unless $pq =~ /^([^?#]*)(?:\?([^#]*))?/;
89 return defined $2 ? $self->path($1)->query($2) : $self->path($1);
90 }
91
92311941443ms6238823.48s my $query = $self->query->to_string;
# spent 2.18s making 311941 calls to Mojo::Parameters::to_string, avg 7µs/call # spent 1.30s making 311941 calls to Mojo::URL::query, avg 4µs/call
933119411.15s6238828.31s return $self->path->to_string . (length $query ? "?$query" : '');
# spent 7.32s making 311941 calls to Mojo::Path::to_string, avg 23µs/call # spent 990ms making 311941 calls to Mojo::URL::path, avg 3µs/call
94}
95
96311941683ms311941270ms
# spent 1.06s (790ms+270ms) within Mojo::URL::protocol which was called 311941 times, avg 3µs/call: # 311941 times (790ms+270ms) by Mojo::URL::_string at line 166, avg 3µs/call
sub protocol { lc(shift->scheme // '') }
# spent 270ms making 311941 calls to Mojo::URL::scheme, avg 864ns/call
97
98
# spent 1.53s (1.18+350ms) within Mojo::URL::query which was called 359524 times, avg 4µs/call: # 311941 times (1.02s+278ms) by Mojo::URL::path_query at line 92, avg 4µs/call # 47583 times (160ms+72.0ms) by Mojo::URL::to_abs at line 143, avg 5µs/call
sub query {
9935952454.5ms my $self = shift;
100
101 # Old parameters
102359524473ms359524350ms my $q = $self->{query} ||= Mojo::Parameters->new;
# spent 197ms making 312897 calls to Mojo::Parameters::__ANON__[Mojo/Parameters.pm:3], avg 631ns/call # spent 152ms making 46627 calls to Mojo::Parameters::new, avg 3µs/call
103359524471ms return $q unless @_;
104
105 # Replace with list
1061586121.5ms 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
115158618.41ms else { $self->{query} = ref $_[0] ? $_[0] : $q->parse($_[0]) }
116
1171586120.5ms return $self;
118}
119
120
# spent 12.3s (1.86+10.4) within Mojo::URL::to_abs which was called 117729 times, avg 104µs/call: # 71790 times (341ms+2.51s) by JSON::Schema::Modern::Utilities::A at line 247 of JSON/Schema/Modern/Utilities.pm, avg 40µs/call # 39121 times (1.35s+7.40s) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref at line 209 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 224µs/call # 4217 times (19.6ms+142ms) by JSON::Schema::Modern::Utilities::E at line 213 of JSON/Schema/Modern/Utilities.pm, avg 38µs/call # 2586 times (146ms+360ms) by JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef at line 231 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 196µs/call # 15 times (906µs+2.98ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 171 of JSON/Schema/Modern/Vocabulary/Core.pm, avg 259µs/call
sub to_abs {
12111772920.9ms my $self = shift;
122
123117729103ms1177293.26s my $abs = $self->clone;
# spent 3.26s making 117729 calls to Mojo::URL::clone, avg 28µs/call
124117729293ms117729431ms return $abs if $abs->is_abs;
# spent 431ms making 117729 calls to Mojo::URL::is_abs, avg 4µs/call
125
126 # Scheme
1273396354.9ms3396337.4ms my $base = shift || $abs->base;
# spent 37.4ms making 33963 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 1µs/call
1283396392.0ms101889142ms $abs->base($base)->scheme($base->scheme);
# spent 74.1ms making 33963 calls to Mojo::URL::base, avg 2µs/call # spent 68.0ms making 67926 calls to Mojo::URL::scheme, avg 1µs/call
129
130 # Authority
1313396333.3ms3396322.1ms return $abs if $abs->host;
# spent 22.1ms making 33963 calls to Mojo::URL::host, avg 652ns/call
13233963141ms203778179ms $abs->userinfo($base->userinfo)->host($base->host)->port($base->port);
# spent 69.9ms making 67926 calls to Mojo::URL::host, avg 1µs/call # spent 55.4ms making 67926 calls to Mojo::URL::userinfo, avg 815ns/call # spent 53.7ms making 67926 calls to Mojo::URL::port, avg 791ns/call
133
134 # Absolute path
1353396338.1ms33963108ms my $path = $abs->path;
# spent 108ms making 33963 calls to Mojo::URL::path, avg 3µs/call
1363396341.8ms33963123ms return $abs if $path->leading_slash;
# spent 123ms making 33963 calls to Mojo::Path::leading_slash, avg 4µs/call
137
138 # Inherit path
1393396371.1ms3396386.4ms if (!@{$path->parts}) {
# spent 86.4ms making 33963 calls to Mojo::Path::parts, avg 3µs/call
1401586158.7ms63444796ms $abs->path($base->path->clone->canonicalize);
# spent 594ms making 15861 calls to Mojo::Path::canonicalize, avg 37µs/call # spent 102ms making 15861 calls to Mojo::Path::clone, avg 6µs/call # spent 99.7ms making 31722 calls to Mojo::URL::path, avg 3µs/call
141
142 # Query
1431586163.6ms79305502ms $abs->query($base->query->clone) unless length $abs->query->to_string;
# spent 232ms making 47583 calls to Mojo::URL::query, avg 5µs/call # spent 144ms making 15861 calls to Mojo::Parameters::clone, avg 9µs/call # spent 126ms making 15861 calls to Mojo::Parameters::to_string, avg 8µs/call
144 }
145
146 # Merge paths
1471810286.7ms905104.73s else { $abs->path($base->path->clone->merge($path)->canonicalize) }
# spent 4.27s making 18102 calls to Mojo::Path::merge, avg 236µs/call # spent 214ms making 18102 calls to Mojo::Path::canonicalize, avg 12µs/call # spent 128ms making 36204 calls to Mojo::URL::path, avg 4µs/call # spent 117ms making 18102 calls to Mojo::Path::clone, avg 6µs/call
148
14933963103ms return $abs;
150}
151
152311149620ms31114930.2s
# spent 30.8s (619ms+30.2) within Mojo::URL::to_string which was called 311149 times, avg 99µs/call: # 311149 times (619ms+30.2s) by Mojo::URL::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/URL.pm:3] at line 3, avg 99µs/call
sub to_string { shift->_string(0) }
# spent 30.2s making 311149 calls to Mojo::URL::_string, avg 97µs/call
1537921.95ms79273.4ms
# spent 75.5ms (2.12+73.4) within Mojo::URL::to_unsafe_string which was called 792 times, avg 95µs/call: # 746 times (2.00ms+68.8ms) by JSON::Schema::Modern::Utilities::assert_uri_reference at line 312 of JSON/Schema/Modern/Utilities.pm, avg 95µs/call # 46 times (114µs+4.61ms) by JSON::Schema::Modern::Utilities::assert_uri at line 329 of JSON/Schema/Modern/Utilities.pm, avg 103µs/call
sub to_unsafe_string { shift->_string(1) }
# spent 73.4ms making 792 calls to Mojo::URL::_string, avg 93µs/call
154
155sub username { (shift->userinfo // '') =~ /^([^:]+)/ ? $1 : undef }
156
15757141158ms57141609ms
# spent 743ms (134+609) within Mojo::URL::_decode which was called 57141 times, avg 13µs/call: # 57141 times (134ms+609ms) by Mojo::URL::parse at line 60, avg 13µs/call
sub _decode { decode('UTF-8', $_[0]) // $_[0] }
# spent 609ms making 57141 calls to Mojo::Util::decode, avg 11µs/call
158
1595271581.28s10543165.69s
# spent 7.26s (1.57+5.69) within Mojo::URL::_encode which was called 527158 times, avg 14µs/call: # 309710 times (952ms+3.55s) by Mojo::URL::_string at line 170, avg 15µs/call # 217448 times (621ms+2.14s) by Mojo::URL::_string at line 182, avg 13µs/call
sub _encode { url_escape encode('UTF-8', $_[0]), $_[1] }
# spent 3.07s making 527158 calls to Mojo::Util::url_escape, avg 6µs/call # spent 2.63s making 527158 calls to Mojo::Util::encode, avg 5µs/call
160
161
# spent 30.3s (4.22+26.0) within Mojo::URL::_string which was called 311941 times, avg 97µs/call: # 311149 times (4.20s+26.0s) by Mojo::URL::to_string at line 152, avg 97µs/call # 792 times (11.4ms+62.0ms) by Mojo::URL::to_unsafe_string at line 153, avg 93µs/call
sub _string {
16231194191.6ms my ($self, $unsafe) = @_;
163
164 # Scheme
16531194172.7ms my $url = '';
166311941406ms3119411.06s if (my $proto = $self->protocol) { $url .= "$proto:" }
# spent 1.06s making 311941 calls to Mojo::URL::protocol, avg 3µs/call
167
168 # Authority
169311941250ms3119412.96s my $auth = $self->host_port;
# spent 2.96s making 311941 calls to Mojo::URL::host_port, avg 9µs/call
170311941347ms3097104.50s $auth = _encode($auth, '^A-Za-z0-9\-._~!$&\'()*+,;=:\[\]') if defined $auth;
# spent 4.50s making 309710 calls to Mojo::URL::_encode, avg 15µs/call
17131194148.0ms792562µs if ($unsafe && defined(my $info = $self->userinfo)) {
# spent 562µs making 792 calls to Mojo::URL::userinfo, avg 710ns/call
172 $auth = _encode($info, '^A-Za-z0-9\-._~!$&\'()*+,;=:') . '@' . $auth;
173 }
174311941110ms $url .= "//$auth" if defined $auth;
175
176 # Path and query
177311941280ms31194114.3s my $path = $self->path_query;
# spent 14.3s making 311941 calls to Mojo::URL::path_query, avg 46µs/call
178311941741ms309710268ms $url .= !$auth || !length $path || $path =~ m!^[/?]! ? $path : "/$path";
# spent 268ms making 309710 calls to Mojo::URL::CORE:match, avg 864ns/call
179
180 # Fragment
181311941421ms311941231ms return $url unless defined(my $fragment = $self->fragment);
# spent 231ms making 311941 calls to Mojo::URL::fragment, avg 740ns/call
182217448610ms2174482.76s return $url . '#' . _encode($fragment, '^A-Za-z0-9\-._~!$&\'()*+,;=:@/?');
# spent 2.76s making 217448 calls to Mojo::URL::_encode, avg 13µs/call
183}
184
18514µ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.36s (860ms+504ms) within Mojo::URL::CORE:match which was called 855707 times, avg 2µs/call: # 309710 times (268ms+0s) by Mojo::URL::_string at line 178, avg 864ns/call # 309710 times (180ms+0s) by Mojo::URL::ihost at line 42, avg 581ns/call # 136585 times (374ms+504ms) by Mojo::URL::parse at line 56, avg 6µs/call # 99702 times (38.8ms+0s) by Mojo::URL::host_port at line 26, avg 389ns/call
sub Mojo::URL::CORE:match; # opcode
# spent 62.8ms within Mojo::URL::CORE:subst which was called 199404 times, avg 315ns/call: # 99702 times (37.3ms+0s) by Mojo::URL::parse at line 62, avg 374ns/call # 99702 times (25.5ms+0s) by Mojo::URL::host_port at line 24, avg 256ns/call
sub Mojo::URL::CORE:subst; # opcode