.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Path 3pm" .TH Mojo::Path 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Path \- Path .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Path; \& \& # Parse \& my $path = Mojo::Path\->new(\*(Aq/foo%2Fbar%3B/baz.html\*(Aq); \& say $path\->[0]; \& \& # Build \& my $path = Mojo::Path\->new(\*(Aq/i/♥\*(Aq); \& push @$path, \*(Aqmojolicious\*(Aq; \& say "$path"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Path is a container for paths used by Mojo::URL, based on \&\s-1RFC 3986\s0 . .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Path implements the following attributes. .SS "charset" .IX Subsection "charset" .Vb 2 \& my $charset = $path\->charset; \& $path = $path\->charset(\*(AqUTF\-8\*(Aq); .Ve .PP Charset used for encoding and decoding, defaults to \f(CW\*(C`UTF\-8\*(C'\fR. .PP .Vb 2 \& # Disable encoding and decoding \& $path\->charset(undef); .Ve .SH "METHODS" .IX Header "METHODS" Mojo::Path inherits all methods from Mojo::Base and implements the following new ones. .SS "canonicalize" .IX Subsection "canonicalize" .Vb 1 \& $path = $path\->canonicalize; .Ve .PP Canonicalize path by resolving \f(CW\*(C`.\*(C'\fR and \f(CW\*(C`..\*(C'\fR, in addition \f(CW\*(C`...\*(C'\fR will be treated as \f(CW\*(C`.\*(C'\fR to protect from path traversal attacks. .PP .Vb 2 \& # "/foo/baz" \& Mojo::Path\->new(\*(Aq/foo/./bar/../baz\*(Aq)\->canonicalize; \& \& # "/../baz" \& Mojo::Path\->new(\*(Aq/foo/../bar/../../baz\*(Aq)\->canonicalize; \& \& # "/foo/bar" \& Mojo::Path\->new(\*(Aq/foo/.../bar\*(Aq)\->canonicalize; .Ve .SS "clone" .IX Subsection "clone" .Vb 1 \& my $clone = $path\->clone; .Ve .PP Return a new Mojo::Path object cloned from this path. .SS "contains" .IX Subsection "contains" .Vb 1 \& my $bool = $path\->contains(\*(Aq/i/♥/mojolicious\*(Aq); .Ve .PP Check if path contains given prefix. .PP .Vb 4 \& # True \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/\*(Aq); \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/foo\*(Aq); \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/foo/bar\*(Aq); \& \& # False \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/f\*(Aq); \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/bar\*(Aq); \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->contains(\*(Aq/whatever\*(Aq); .Ve .SS "leading_slash" .IX Subsection "leading_slash" .Vb 2 \& my $bool = $path\->leading_slash; \& $path = $path\->leading_slash($bool); .Ve .PP Path has a leading slash. Note that this method will normalize the path and that \f(CW%2F\fR will be treated as \f(CW\*(C`/\*(C'\fR for security reasons. .PP .Vb 2 \& # "/foo/bar" \& Mojo::Path\->new(\*(Aqfoo/bar\*(Aq)\->leading_slash(1); \& \& # "foo/bar" \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->leading_slash(0); .Ve .SS "merge" .IX Subsection "merge" .Vb 3 \& $path = $path\->merge(\*(Aq/foo/bar\*(Aq); \& $path = $path\->merge(\*(Aqfoo/bar\*(Aq); \& $path = $path\->merge(Mojo::Path\->new); .Ve .PP Merge paths. Note that this method will normalize both paths if necessary and that \f(CW%2F\fR will be treated as \f(CW\*(C`/\*(C'\fR for security reasons. .PP .Vb 2 \& # "/baz/yada" \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->merge(\*(Aq/baz/yada\*(Aq); \& \& # "/foo/baz/yada" \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->merge(\*(Aqbaz/yada\*(Aq); \& \& # "/foo/bar/baz/yada" \& Mojo::Path\->new(\*(Aq/foo/bar/\*(Aq)\->merge(\*(Aqbaz/yada\*(Aq); .Ve .SS "new" .IX Subsection "new" .Vb 2 \& my $path = Mojo::Path\->new; \& my $path = Mojo::Path\->new(\*(Aq/foo%2Fbar%3B/baz.html\*(Aq); .Ve .PP Construct a new Mojo::Path object and \*(L"parse\*(R" path if necessary. .SS "parse" .IX Subsection "parse" .Vb 1 \& $path = $path\->parse(\*(Aq/foo%2Fbar%3B/baz.html\*(Aq); .Ve .PP Parse path. .SS "to_abs_string" .IX Subsection "to_abs_string" .Vb 1 \& my $str = $path\->to_abs_string; .Ve .PP Turn path into an absolute string. .PP .Vb 3 \& # "/i/%E2%99%A5/mojolicious" \& Mojo::Path\->new(\*(Aq/i/%E2%99%A5/mojolicious\*(Aq)\->to_abs_string; \& Mojo::Path\->new(\*(Aqi/%E2%99%A5/mojolicious\*(Aq)\->to_abs_string; .Ve .SS "parts" .IX Subsection "parts" .Vb 2 \& my $parts = $path\->parts; \& $path = $path\->parts([qw(foo bar baz)]); .Ve .PP The path parts. Note that this method will normalize the path and that \f(CW%2F\fR will be treated as \f(CW\*(C`/\*(C'\fR for security reasons. .PP .Vb 2 \& # Part with slash \& push @{$path\->parts}, \*(Aqfoo/bar\*(Aq; .Ve .SS "to_dir" .IX Subsection "to_dir" .Vb 1 \& my $dir = $route\->to_dir; .Ve .PP Clone path and remove everything after the right-most slash. .PP .Vb 2 \& # "/i/%E2%99%A5/" \& Mojo::Path\->new(\*(Aq/i/%E2%99%A5/mojolicious\*(Aq)\->to_dir\->to_abs_string; \& \& # "i/%E2%99%A5/" \& Mojo::Path\->new(\*(Aqi/%E2%99%A5/mojolicious\*(Aq)\->to_dir\->to_abs_string; .Ve .SS "to_route" .IX Subsection "to_route" .Vb 1 \& my $route = $path\->to_route; .Ve .PP Turn path into a route. .PP .Vb 3 \& # "/i/♥/mojolicious" \& Mojo::Path\->new(\*(Aq/i/%E2%99%A5/mojolicious\*(Aq)\->to_route; \& Mojo::Path\->new(\*(Aqi/%E2%99%A5/mojolicious\*(Aq)\->to_route; .Ve .SS "to_string" .IX Subsection "to_string" .Vb 1 \& my $str = $path\->to_string; .Ve .PP Turn path into a string. .PP .Vb 2 \& # "/i/%E2%99%A5/mojolicious" \& Mojo::Path\->new(\*(Aq/i/%E2%99%A5/mojolicious\*(Aq)\->to_string; \& \& # "i/%E2%99%A5/mojolicious" \& Mojo::Path\->new(\*(Aqi/%E2%99%A5/mojolicious\*(Aq)\->to_string; .Ve .SS "trailing_slash" .IX Subsection "trailing_slash" .Vb 2 \& my $bool = $path\->trailing_slash; \& $path = $path\->trailing_slash($bool); .Ve .PP Path has a trailing slash. Note that this method will normalize the path and that \f(CW%2F\fR will be treated as \f(CW\*(C`/\*(C'\fR for security reasons. .PP .Vb 2 \& # "/foo/bar/" \& Mojo::Path\->new(\*(Aq/foo/bar\*(Aq)\->trailing_slash(1); \& \& # "/foo/bar" \& Mojo::Path\->new(\*(Aq/foo/bar/\*(Aq)\->trailing_slash(0); .Ve .SH "OPERATORS" .IX Header "OPERATORS" Mojo::Path overloads the following operators. .SS "array" .IX Subsection "array" .Vb 1 \& my @parts = @$path; .Ve .PP Alias for \*(L"parts\*(R". Note that this will normalize the path and that \f(CW%2F\fR will be treated as \f(CW\*(C`/\*(C'\fR for security reasons. .PP .Vb 2 \& say $path\->[0]; \& say for @$path; .Ve .SS "bool" .IX Subsection "bool" .Vb 1 \& my $bool = !!$path; .Ve .PP Always true. .SS "stringify" .IX Subsection "stringify" .Vb 1 \& my $str = "$path"; .Ve .PP Alias for \*(L"to_string\*(R". .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .