Mojo::Path::Role::Relative - Relative operations on a Mojo::Path
$path = Mojo::Path->with_roles('+Relative')->new('/foo/bar/baz/data.json');
$base = Mojo::Path->new('/foo/bar');
# 1
$path->is_subpath_of($base);
# "baz/data.json"
$path->to_subpath_of($base);
# "baz/data.json"
$path->to_rel($base);
"to_rel" in Mojo::URL was deprecated sometime ago. A suggestion was made to move the functionality to Mojo::Path. This is an implementation of that suggestion as a role.
This role adds the following methods to Mojo::Path when composed.
# 1
$path->is_subpath_of($base);
Determine if $path
is a subpath/child of $base
.
# "baz/data.json"
$path->to_rel($base);
Use "to_rel" in Mojo::File to determine a relative path.
# "baz/data.json"
$path->to_subpath_of($base);
Similar to "to_rel", except that the path will remain absolute if $path
is not a subpath of $base
.
kiwiroy - Roy Storey <kiwiroy@cpan.org>
This library is free software and may be distributed under the same terms as perl itself.