Skip to content

Role::Tiny based role to add operations for relative Mojo::Path objects

Notifications You must be signed in to change notification settings

kiwiroy/mojo-path-role-relative

Repository files navigation

NAME

Mojo::Path::Role::Relative - Relative operations on a Mojo::Path

SYNOPSIS

$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);

DESCRIPTION

"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.

METHODS

This role adds the following methods to Mojo::Path when composed.

is_subpath_of

# 1
$path->is_subpath_of($base);

Determine if $path is a subpath/child of $base.

to_rel

# "baz/data.json"
$path->to_rel($base);

Use "to_rel" in Mojo::File to determine a relative path.

to_subpath_of

# "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.

AUTHOR

kiwiroy - Roy Storey <kiwiroy@cpan.org>

LICENSE

This library is free software and may be distributed under the same terms as perl itself.

About

Role::Tiny based role to add operations for relative Mojo::Path objects

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages