| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/Path.pm |
| Statements | Executed 12291787 statements in 11.7s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 368028 | 2 | 2 | 3.17s | 8.70s | Mojo::Path::to_string |
| 715815 | 3 | 1 | 1.96s | 5.04s | Mojo::Path::_parse (recurses: max depth 1, inclusive time 101ms) |
| 463771 | 3 | 1 | 1.88s | 2.98s | Mojo::Path::clone |
| 156221 | 2 | 1 | 1.21s | 7.60s | Mojo::Path::merge |
| 658284 | 3 | 2 | 1.18s | 1.77s | Mojo::Path::new |
| 899693 | 5 | 3 | 553ms | 2.71s | Mojo::Path::__ANON__[:3] |
| 328930 | 5 | 2 | 518ms | 3.68s | Mojo::Path::parts (recurses: max depth 1, inclusive time 94.0ms) |
| 261004 | 3 | 1 | 411ms | 2.16s | Mojo::Path::trailing_slash |
| 33963 | 2 | 1 | 282ms | 745ms | Mojo::Path::canonicalize |
| 156221 | 2 | 1 | 271ms | 271ms | Mojo::Path::parse |
| 125881 | 2 | 2 | 233ms | 369ms | Mojo::Path::leading_slash |
| 257232 | 2 | 1 | 137ms | 137ms | Mojo::Path::CORE:subst (opcode) |
| 156221 | 1 | 1 | 96.8ms | 966ms | Mojo::Path::CORE:match (opcode) |
| 1 | 1 | 1 | 25µs | 212µs | Mojo::Path::BEGIN@2 |
| 1 | 1 | 1 | 11µs | 40µs | Mojo::Path::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 44µs | Mojo::Path::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | Mojo::Path::contains |
| 0 | 0 | 0 | 0s | 0s | Mojo::Path::to_abs_string |
| 0 | 0 | 0 | 0s | 0s | Mojo::Path::to_dir |
| 0 | 0 | 0 | 0s | 0s | Mojo::Path::to_route |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Mojo::Path; | ||||
| 2 | 2 | 100µs | 2 | 399µs | # spent 212µs (25+187) within Mojo::Path::BEGIN@2 which was called:
# once (25µs+187µs) by Mojo::URL::BEGIN@6 at line 2 # spent 212µs making 1 call to Mojo::Path::BEGIN@2
# spent 187µs making 1 call to Mojo::Base::import |
| 3 | 899695 | 1.14s | 54308 | 2.16s | # spent 2.71s (553ms+2.16) within Mojo::Path::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/Path.pm:3] which was called 899693 times, avg 3µs/call:
# 429808 times (257ms+0s) by Mojo::URL::clone at line 16 of Mojo/URL.pm, avg 598ns/call
# 415579 times (191ms+0s) by Mojo::URL::path at line 75 of Mojo/URL.pm, avg 459ns/call
# 18102 times (40.1ms+829ms) by Mojo::Path::CORE:match at line 44, avg 48µs/call
# 18102 times (34.3ms+691ms) by Mojo::Util::CORE:subst at line 408 of Mojo/Util.pm, avg 40µs/call
# 18102 times (31.1ms+636ms) by Mojo::Util::decode at line 122 of Mojo/Util.pm, avg 37µs/call
# spent 40µs (11+29) within Mojo::Path::BEGIN@3 which was called:
# once (11µs+29µs) by Mojo::URL::BEGIN@6 at line 3 # spent 2.16s making 54306 calls to Mojo::Path::to_string, avg 40µs/call
# spent 40µs making 1 call to Mojo::Path::BEGIN@3
# spent 29µs making 1 call to overload::import |
| 4 | |||||
| 5 | 2 | 1.45ms | 2 | 82µs | # spent 44µs (6+38) within Mojo::Path::BEGIN@5 which was called:
# once (6µs+38µs) by Mojo::URL::BEGIN@6 at line 5 # spent 44µs making 1 call to Mojo::Path::BEGIN@5
# spent 38µs making 1 call to Exporter::import |
| 6 | |||||
| 7 | 1 | 5µs | 1 | 66µs | has charset => 'UTF-8'; # spent 66µs making 1 call to Mojo::Path::has |
| 8 | |||||
| 9 | # spent 745ms (282+463) within Mojo::Path::canonicalize which was called 33963 times, avg 22µs/call:
# 18102 times (154ms+40.9ms) by Mojo::URL::to_abs at line 147 of Mojo/URL.pm, avg 11µs/call
# 15861 times (128ms+422ms) by Mojo::URL::to_abs at line 140 of Mojo/URL.pm, avg 35µs/call | ||||
| 10 | 33963 | 12.8ms | my $self = shift; | ||
| 11 | |||||
| 12 | 33963 | 31.4ms | 33963 | 463ms | my $parts = $self->parts; # spent 463ms making 33963 calls to Mojo::Path::parts, avg 14µs/call |
| 13 | 33963 | 38.8ms | for (my $i = 0; $i <= $#$parts;) { | ||
| 14 | 135851 | 129ms | if (!length $parts->[$i] || $parts->[$i] eq '.' || $parts->[$i] eq '...') { splice @$parts, $i, 1 } | ||
| 15 | elsif ($i < 1 || $parts->[$i] ne '..' || $parts->[$i - 1] eq '..') { $i++ } | ||||
| 16 | else { splice @$parts, --$i, 2 } | ||||
| 17 | } | ||||
| 18 | |||||
| 19 | 33963 | 63.8ms | return @$parts ? $self : $self->trailing_slash(undef); | ||
| 20 | } | ||||
| 21 | |||||
| 22 | # spent 2.98s (1.88+1.10) within Mojo::Path::clone which was called 463771 times, avg 6µs/call:
# 429808 times (1.77s+1.02s) by Mojo::URL::clone at line 16 of Mojo/URL.pm, avg 6µs/call
# 18102 times (60.5ms+41.2ms) by Mojo::URL::to_abs at line 147 of Mojo/URL.pm, avg 6µs/call
# 15861 times (55.7ms+38.6ms) by Mojo::URL::to_abs at line 140 of Mojo/URL.pm, avg 6µs/call | ||||
| 23 | 463771 | 79.1ms | my $self = shift; | ||
| 24 | |||||
| 25 | 463771 | 302ms | 463771 | 1.10s | my $clone = $self->new; # spent 1.10s making 463771 calls to Mojo::Path::new, avg 2µs/call |
| 26 | 463771 | 396ms | if (exists $self->{charset}) { $clone->{charset} = $self->{charset} } | ||
| 27 | 463771 | 189ms | if (my $parts = $self->{parts}) { | ||
| 28 | 66041 | 118ms | $clone->{$_} = $self->{$_} for qw(leading_slash trailing_slash); | ||
| 29 | 66041 | 58.6ms | $clone->{parts} = [@$parts]; | ||
| 30 | } | ||||
| 31 | 397730 | 184ms | else { $clone->{path} = $self->{path} } | ||
| 32 | |||||
| 33 | 463771 | 573ms | return $clone; | ||
| 34 | } | ||||
| 35 | |||||
| 36 | sub contains { $_[1] eq '/' || $_[0]->to_route =~ m!^\Q$_[1]\E(?:/|$)! } | ||||
| 37 | |||||
| 38 | 125881 | 211ms | 125881 | 100ms | # spent 369ms (233+136) within Mojo::Path::leading_slash which was called 125881 times, avg 3µs/call:
# 91918 times (171ms+95.2ms) by Mojo::Path::to_string at line 94, avg 3µs/call
# 33963 times (61.2ms+41.1ms) by Mojo::URL::to_abs at line 136 of Mojo/URL.pm, avg 3µs/call # spent 136ms making 125881 calls to Mojo::Path::_parse, avg 1µs/call, recursion: max depth 1, sum of overlapping time 36.1ms |
| 39 | |||||
| 40 | # spent 7.60s (1.21+6.40) within Mojo::Path::merge which was called 156221 times, avg 49µs/call:
# 138119 times (965ms+2.88s) by Mojo::URL::path at line 79 of Mojo/URL.pm, avg 28µs/call
# 18102 times (244ms+3.51s) by Mojo::URL::to_abs at line 147 of Mojo/URL.pm, avg 208µs/call | ||||
| 41 | 156221 | 81.0ms | my ($self, $path) = @_; | ||
| 42 | |||||
| 43 | # Replace | ||||
| 44 | 156221 | 482ms | 274182 | 2.00s | return $self->parse($path) if $path =~ m!^/!; # spent 966ms making 156221 calls to Mojo::Path::CORE:match, avg 6µs/call
# spent 869ms making 18102 calls to Mojo::Path::__ANON__[Mojo/Path.pm:3], avg 48µs/call
# spent 163ms making 99859 calls to Mojo::Path::parse, avg 2µs/call |
| 45 | |||||
| 46 | # Merge | ||||
| 47 | 56362 | 115ms | 112724 | 1.82s | pop @{$self->parts} unless $self->trailing_slash; # spent 1.65s making 56362 calls to Mojo::Path::trailing_slash, avg 29µs/call
# spent 162ms making 56362 calls to Mojo::Path::parts, avg 3µs/call |
| 48 | 56362 | 50.9ms | 56362 | 332ms | $path = $self->new($path); # spent 332ms making 56362 calls to Mojo::Path::new, avg 6µs/call |
| 49 | 56362 | 119ms | 112724 | 2.82s | push @{$self->parts}, @{$path->parts}; # spent 2.82s making 112724 calls to Mojo::Path::parts, avg 25µs/call |
| 50 | 56362 | 214ms | 112724 | 297ms | return $self->trailing_slash($path->trailing_slash); # spent 297ms making 112724 calls to Mojo::Path::trailing_slash, avg 3µs/call |
| 51 | } | ||||
| 52 | |||||
| 53 | 658284 | 1.11s | 714646 | 589ms | # spent 1.77s (1.18+589ms) within Mojo::Path::new which was called 658284 times, avg 3µs/call:
# 463771 times (767ms+329ms) by Mojo::Path::clone at line 25, avg 2µs/call
# 138151 times (240ms+102ms) by Mojo::URL::path at line 75 of Mojo/URL.pm, avg 2µs/call
# 56362 times (174ms+159ms) by Mojo::Path::merge at line 48, avg 6µs/call # spent 481ms making 658284 calls to Mojo::Base::new, avg 731ns/call
# spent 108ms making 56362 calls to Mojo::Path::parse, avg 2µs/call |
| 54 | |||||
| 55 | sub parse { | ||||
| 56 | 156221 | 25.9ms | my $self = shift; | ||
| 57 | 156221 | 77.9ms | $self->{path} = shift; | ||
| 58 | 156221 | 88.2ms | delete @$self{qw(leading_slash parts trailing_slash)}; | ||
| 59 | 156221 | 196ms | return $self; | ||
| 60 | } | ||||
| 61 | |||||
| 62 | 328930 | 548ms | 328930 | 3.22s | # spent 3.68s (518ms+3.16) within Mojo::Path::parts which was called 328930 times, avg 11µs/call:
# 112724 times (161ms+2.66s) by Mojo::Path::merge at line 49, avg 25µs/call
# 91918 times (152ms+7.62ms) by Mojo::Path::to_string at line 91, avg 2µs/call
# 56362 times (105ms+56.5ms) by Mojo::Path::merge at line 47, avg 3µs/call
# 33963 times (51.3ms+412ms) by Mojo::Path::canonicalize at line 12, avg 14µs/call
# 33963 times (49.1ms+26.8ms) by Mojo::URL::to_abs at line 139 of Mojo/URL.pm, avg 2µs/call # spent 3.26s making 328930 calls to Mojo::Path::_parse, avg 10µs/call, recursion: max depth 1, sum of overlapping time 36.4ms |
| 63 | |||||
| 64 | sub to_abs_string { | ||||
| 65 | my $path = shift->to_string; | ||||
| 66 | return $path =~ m!^/! ? $path : "/$path"; | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | sub to_dir { | ||||
| 70 | my $clone = shift->clone; | ||||
| 71 | pop @{$clone->parts} unless $clone->trailing_slash; | ||||
| 72 | return $clone->trailing_slash(!!@{$clone->parts}); | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | sub to_route { | ||||
| 76 | my $clone = shift->clone; | ||||
| 77 | return '/' . join '/', @{$clone->parts}, $clone->trailing_slash ? '' : (); | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | # spent 8.70s (3.17+5.53) within Mojo::Path::to_string which was called 368028 times, avg 24µs/call:
# 313722 times (2.35s+4.19s) by Mojo::URL::path_query at line 93 of Mojo/URL.pm, avg 21µs/call
# 54306 times (818ms+1.34s) by Mojo::Path::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/Path.pm:3] at line 3, avg 40µs/call | ||||
| 81 | 368028 | 59.7ms | my $self = shift; | ||
| 82 | |||||
| 83 | # Path | ||||
| 84 | 368028 | 304ms | 368028 | 308ms | my $charset = $self->charset; # spent 308ms making 368028 calls to Mojo::Path::charset, avg 838ns/call |
| 85 | 368028 | 157ms | if (defined(my $path = $self->{path})) { | ||
| 86 | 276110 | 228ms | 276110 | 1.14s | $path = encode $charset, $path if $charset; # spent 1.14s making 276110 calls to Mojo::Util::encode, avg 4µs/call |
| 87 | 276110 | 493ms | 276110 | 1.37s | return url_escape $path, '^A-Za-z0-9\-._~!$&\'()*+,;=%:@/'; # spent 1.37s making 276110 calls to Mojo::Util::url_escape, avg 5µs/call |
| 88 | } | ||||
| 89 | |||||
| 90 | # Build path | ||||
| 91 | 91918 | 131ms | 91918 | 159ms | my @parts = @{$self->parts}; # spent 253ms making 91918 calls to Mojo::Path::parts, avg 3µs/call, recursion: max depth 1, sum of overlapping time 94.0ms |
| 92 | 339501 | 280ms | 247583 | 916ms | @parts = map { encode $charset, $_ } @parts if $charset; # spent 916ms making 247583 calls to Mojo::Util::encode, avg 4µs/call |
| 93 | 339501 | 288ms | 247583 | 1.07s | my $path = join '/', map { url_escape $_, '^A-Za-z0-9\-._~!$&\'()*+,;=:@' } @parts; # spent 1.07s making 247583 calls to Mojo::Util::url_escape, avg 4µs/call |
| 94 | 91918 | 94.1ms | 91918 | 266ms | $path = "/$path" if $self->leading_slash; # spent 266ms making 91918 calls to Mojo::Path::leading_slash, avg 3µs/call |
| 95 | 91918 | 74.0ms | 91918 | 207ms | $path = "$path/" if $self->trailing_slash; # spent 207ms making 91918 calls to Mojo::Path::trailing_slash, avg 2µs/call |
| 96 | 91918 | 185ms | return $path; | ||
| 97 | } | ||||
| 98 | |||||
| 99 | 261004 | 412ms | 261004 | 1.72s | # spent 2.16s (411ms+1.75) within Mojo::Path::trailing_slash which was called 261004 times, avg 8µs/call:
# 112724 times (161ms+137ms) by Mojo::Path::merge at line 50, avg 3µs/call
# 91918 times (133ms+73.7ms) by Mojo::Path::to_string at line 95, avg 2µs/call
# 56362 times (118ms+1.54s) by Mojo::Path::merge at line 47, avg 29µs/call # spent 1.75s making 261004 calls to Mojo::Path::_parse, avg 7µs/call, recursion: max depth 1, sum of overlapping time 28.3ms |
| 100 | |||||
| 101 | # spent 5.04s (1.96+3.08) within Mojo::Path::_parse which was called 715815 times, avg 7µs/call:
# 328930 times (953ms+2.27s) by Mojo::Path::parts at line 62, avg 10µs/call
# 261004 times (870ms+848ms) by Mojo::Path::trailing_slash at line 99, avg 7µs/call
# 125881 times (136ms+-35.9ms) by Mojo::Path::leading_slash at line 38, avg 796ns/call | ||||
| 102 | 715815 | 162ms | my ($self, $name) = (shift, shift); | ||
| 103 | |||||
| 104 | 715815 | 167ms | unless ($self->{parts}) { | ||
| 105 | 128616 | 175ms | 128616 | 1.05s | my $path = url_unescape delete($self->{path}) // ''; # spent 1.05s making 128616 calls to Mojo::Util::url_unescape, avg 8µs/call |
| 106 | 128616 | 108ms | 128616 | 157ms | my $charset = $self->charset; # spent 157ms making 128616 calls to Mojo::Path::charset, avg 1µs/call |
| 107 | 128616 | 131ms | 128616 | 1.84s | $path = decode($charset, $path) // $path if $charset; # spent 1.84s making 128616 calls to Mojo::Util::decode, avg 14µs/call |
| 108 | 128616 | 290ms | 128616 | 107ms | $self->{leading_slash} = $path =~ s!^/!!; # spent 107ms making 128616 calls to Mojo::Path::CORE:subst, avg 835ns/call |
| 109 | 128616 | 180ms | 128616 | 29.3ms | $self->{trailing_slash} = $path =~ s!/$!!; # spent 29.3ms making 128616 calls to Mojo::Path::CORE:subst, avg 228ns/call |
| 110 | 128616 | 193ms | $self->{parts} = [split /\//, $path, -1]; | ||
| 111 | } | ||||
| 112 | |||||
| 113 | 715815 | 855ms | return $self->{$name} unless @_; | ||
| 114 | 56362 | 29.5ms | $self->{$name} = shift; | ||
| 115 | 56362 | 61.1ms | return $self; | ||
| 116 | } | ||||
| 117 | |||||
| 118 | 1 | 4µs | 1; | ||
| 119 | |||||
| 120 | =encoding utf8 | ||||
| 121 | |||||
| 122 | =head1 NAME | ||||
| 123 | |||||
| 124 | Mojo::Path - Path | ||||
| 125 | |||||
| 126 | =head1 SYNOPSIS | ||||
| 127 | |||||
| 128 | use Mojo::Path; | ||||
| 129 | |||||
| 130 | # Parse | ||||
| 131 | my $path = Mojo::Path->new('/foo%2Fbar%3B/baz.html'); | ||||
| 132 | say $path->[0]; | ||||
| 133 | |||||
| 134 | # Build | ||||
| 135 | my $path = Mojo::Path->new('/i/♥'); | ||||
| 136 | push @$path, 'mojolicious'; | ||||
| 137 | say "$path"; | ||||
| 138 | |||||
| 139 | =head1 DESCRIPTION | ||||
| 140 | |||||
| 141 | L<Mojo::Path> is a container for paths used by L<Mojo::URL>, based on L<RFC 3986|https://tools.ietf.org/html/rfc3986>. | ||||
| 142 | |||||
| 143 | =head1 ATTRIBUTES | ||||
| 144 | |||||
| 145 | L<Mojo::Path> implements the following attributes. | ||||
| 146 | |||||
| 147 | =head2 charset | ||||
| 148 | |||||
| 149 | my $charset = $path->charset; | ||||
| 150 | $path = $path->charset('UTF-8'); | ||||
| 151 | |||||
| 152 | Charset used for encoding and decoding, defaults to C<UTF-8>. | ||||
| 153 | |||||
| 154 | # Disable encoding and decoding | ||||
| 155 | $path->charset(undef); | ||||
| 156 | |||||
| 157 | =head1 METHODS | ||||
| 158 | |||||
| 159 | L<Mojo::Path> inherits all methods from L<Mojo::Base> and implements the following new ones. | ||||
| 160 | |||||
| 161 | =head2 canonicalize | ||||
| 162 | |||||
| 163 | $path = $path->canonicalize; | ||||
| 164 | |||||
| 165 | Canonicalize path by resolving C<.> and C<..>, in addition C<...> will be treated as C<.> to protect from path | ||||
| 166 | traversal attacks. | ||||
| 167 | |||||
| 168 | # "/foo/baz" | ||||
| 169 | Mojo::Path->new('/foo/./bar/../baz')->canonicalize; | ||||
| 170 | |||||
| 171 | # "/../baz" | ||||
| 172 | Mojo::Path->new('/foo/../bar/../../baz')->canonicalize; | ||||
| 173 | |||||
| 174 | # "/foo/bar" | ||||
| 175 | Mojo::Path->new('/foo/.../bar')->canonicalize; | ||||
| 176 | |||||
| 177 | =head2 clone | ||||
| 178 | |||||
| 179 | my $clone = $path->clone; | ||||
| 180 | |||||
| 181 | Return a new L<Mojo::Path> object cloned from this path. | ||||
| 182 | |||||
| 183 | =head2 contains | ||||
| 184 | |||||
| 185 | my $bool = $path->contains('/i/♥/mojolicious'); | ||||
| 186 | |||||
| 187 | Check if path contains given prefix. | ||||
| 188 | |||||
| 189 | # True | ||||
| 190 | Mojo::Path->new('/foo/bar')->contains('/'); | ||||
| 191 | Mojo::Path->new('/foo/bar')->contains('/foo'); | ||||
| 192 | Mojo::Path->new('/foo/bar')->contains('/foo/bar'); | ||||
| 193 | |||||
| 194 | # False | ||||
| 195 | Mojo::Path->new('/foo/bar')->contains('/f'); | ||||
| 196 | Mojo::Path->new('/foo/bar')->contains('/bar'); | ||||
| 197 | Mojo::Path->new('/foo/bar')->contains('/whatever'); | ||||
| 198 | |||||
| 199 | =head2 leading_slash | ||||
| 200 | |||||
| 201 | my $bool = $path->leading_slash; | ||||
| 202 | $path = $path->leading_slash($bool); | ||||
| 203 | |||||
| 204 | Path has a leading slash. Note that this method will normalize the path and that C<%2F> will be treated as C</> for | ||||
| 205 | security reasons. | ||||
| 206 | |||||
| 207 | # "/foo/bar" | ||||
| 208 | Mojo::Path->new('foo/bar')->leading_slash(1); | ||||
| 209 | |||||
| 210 | # "foo/bar" | ||||
| 211 | Mojo::Path->new('/foo/bar')->leading_slash(0); | ||||
| 212 | |||||
| 213 | =head2 merge | ||||
| 214 | |||||
| 215 | $path = $path->merge('/foo/bar'); | ||||
| 216 | $path = $path->merge('foo/bar'); | ||||
| 217 | $path = $path->merge(Mojo::Path->new); | ||||
| 218 | |||||
| 219 | Merge paths. Note that this method will normalize both paths if necessary and that C<%2F> will be treated as C</> for | ||||
| 220 | security reasons. | ||||
| 221 | |||||
| 222 | # "/baz/yada" | ||||
| 223 | Mojo::Path->new('/foo/bar')->merge('/baz/yada'); | ||||
| 224 | |||||
| 225 | # "/foo/baz/yada" | ||||
| 226 | Mojo::Path->new('/foo/bar')->merge('baz/yada'); | ||||
| 227 | |||||
| 228 | # "/foo/bar/baz/yada" | ||||
| 229 | Mojo::Path->new('/foo/bar/')->merge('baz/yada'); | ||||
| 230 | |||||
| 231 | =head2 new | ||||
| 232 | |||||
| 233 | my $path = Mojo::Path->new; | ||||
| 234 | my $path = Mojo::Path->new('/foo%2Fbar%3B/baz.html'); | ||||
| 235 | |||||
| 236 | Construct a new L<Mojo::Path> object and L</"parse"> path if necessary. | ||||
| 237 | |||||
| 238 | =head2 parse | ||||
| 239 | |||||
| 240 | $path = $path->parse('/foo%2Fbar%3B/baz.html'); | ||||
| 241 | |||||
| 242 | Parse path. | ||||
| 243 | |||||
| 244 | =head2 to_abs_string | ||||
| 245 | |||||
| 246 | my $str = $path->to_abs_string; | ||||
| 247 | |||||
| 248 | Turn path into an absolute string. | ||||
| 249 | |||||
| 250 | # "/i/%E2%99%A5/mojolicious" | ||||
| 251 | Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_abs_string; | ||||
| 252 | Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_abs_string; | ||||
| 253 | |||||
| 254 | =head2 parts | ||||
| 255 | |||||
| 256 | my $parts = $path->parts; | ||||
| 257 | $path = $path->parts([qw(foo bar baz)]); | ||||
| 258 | |||||
| 259 | The path parts. Note that this method will normalize the path and that C<%2F> will be treated as C</> for security | ||||
| 260 | reasons. | ||||
| 261 | |||||
| 262 | # Part with slash | ||||
| 263 | push @{$path->parts}, 'foo/bar'; | ||||
| 264 | |||||
| 265 | =head2 to_dir | ||||
| 266 | |||||
| 267 | my $dir = $route->to_dir; | ||||
| 268 | |||||
| 269 | Clone path and remove everything after the right-most slash. | ||||
| 270 | |||||
| 271 | # "/i/%E2%99%A5/" | ||||
| 272 | Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_dir->to_abs_string; | ||||
| 273 | |||||
| 274 | # "i/%E2%99%A5/" | ||||
| 275 | Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_dir->to_abs_string; | ||||
| 276 | |||||
| 277 | =head2 to_route | ||||
| 278 | |||||
| 279 | my $route = $path->to_route; | ||||
| 280 | |||||
| 281 | Turn path into a route. | ||||
| 282 | |||||
| 283 | # "/i/♥/mojolicious" | ||||
| 284 | Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_route; | ||||
| 285 | Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_route; | ||||
| 286 | |||||
| 287 | =head2 to_string | ||||
| 288 | |||||
| 289 | my $str = $path->to_string; | ||||
| 290 | |||||
| 291 | Turn path into a string. | ||||
| 292 | |||||
| 293 | # "/i/%E2%99%A5/mojolicious" | ||||
| 294 | Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_string; | ||||
| 295 | |||||
| 296 | # "i/%E2%99%A5/mojolicious" | ||||
| 297 | Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_string; | ||||
| 298 | |||||
| 299 | =head2 trailing_slash | ||||
| 300 | |||||
| 301 | my $bool = $path->trailing_slash; | ||||
| 302 | $path = $path->trailing_slash($bool); | ||||
| 303 | |||||
| 304 | Path has a trailing slash. Note that this method will normalize the path and that C<%2F> will be treated as C</> for | ||||
| 305 | security reasons. | ||||
| 306 | |||||
| 307 | # "/foo/bar/" | ||||
| 308 | Mojo::Path->new('/foo/bar')->trailing_slash(1); | ||||
| 309 | |||||
| 310 | # "/foo/bar" | ||||
| 311 | Mojo::Path->new('/foo/bar/')->trailing_slash(0); | ||||
| 312 | |||||
| 313 | =head1 OPERATORS | ||||
| 314 | |||||
| 315 | L<Mojo::Path> overloads the following operators. | ||||
| 316 | |||||
| 317 | =head2 array | ||||
| 318 | |||||
| 319 | my @parts = @$path; | ||||
| 320 | |||||
| 321 | Alias for L</"parts">. Note that this will normalize the path and that C<%2F> will be treated as C</> for security | ||||
| 322 | reasons. | ||||
| 323 | |||||
| 324 | say $path->[0]; | ||||
| 325 | say for @$path; | ||||
| 326 | |||||
| 327 | =head2 bool | ||||
| 328 | |||||
| 329 | my $bool = !!$path; | ||||
| 330 | |||||
| 331 | Always true. | ||||
| 332 | |||||
| 333 | =head2 stringify | ||||
| 334 | |||||
| 335 | my $str = "$path"; | ||||
| 336 | |||||
| 337 | Alias for L</"to_string">. | ||||
| 338 | |||||
| 339 | =head1 SEE ALSO | ||||
| 340 | |||||
| 341 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||
| 342 | |||||
| 343 | =cut | ||||
# spent 966ms (96.8+869) within Mojo::Path::CORE:match which was called 156221 times, avg 6µs/call:
# 156221 times (96.8ms+869ms) by Mojo::Path::merge at line 44, avg 6µs/call | |||||
sub Mojo::Path::CORE:subst; # opcode |