Author image Christopher White
and 1 contributors

NAME

Test::OnlySome::PathCapsule - yet another object-oriented path representation

INSTALLATION

See Test::OnlySome, with which this module is distributed.

SYNOPSIS

    use Test::OnlySome::PathCapsule;
    my $path = Test::OnlySome::PathCapsule->new('some/path')
    my $cwd = Test::OnlySome::PathCapsule->new()

    $path->up()         # move to the parent dir, if any
    $path->down('foo')  # move to dir 'foo'

Test::OnlySome::PathCapsule doesn't care whether the path actually exists on disk.

CREATING AND MODIFYING

new

Create a new instance.

    my $path = Test::OnlySome::PathCapsule->new([$pathname_string[, $is_dir = 0]])

If $pathname_string is given, the instance points at that path. Otherwise, the instance points at cwd. If $is_dir, $pathname_string points at a directory; otherwise, it points at a file.

clone

Return a clone of this instance. Useful if you want to start from one path and move to others. Usage is $instance-clone()>.

up

Move up one directory, if that is possible. Returns the instance, so you can chain calls. Usage:

    $path->up([$keep_filename=0])

If $keep_filename is truthy, keep the filename. Otherwise, clear it out, since moving into a different directory probably invalidates the name.

Returns the instance.

down

Move up one directory, if that is possible. Returns the instance, so you can chain calls. Usage:

    $path->down($whither[, $keep_filename=0])

If $keep_filename is truthy, keep the filename. Otherwise, clear it out, since moving into a different directory probably invalidates the name.

Returns the instance.

file

Get or set the filename. Usage:

    $self->file([$new_filename])

If no argument is given, returns the current filename, or undef if the path is a directory. If an argument is given, marks the instance as not representing a dir, and returns the instance.

ACCESSING

is_dir

Returns true if the instance represents a directory as opposed to a file.

abs

Returns the absolute path to the file. Usage: $self-abs>.

rel

Returns the relative path to the file from the current working directory. Usage: $self-rel>.

rel_orig

Returns the relative path to the file from the current working directory at the time the instance was created. Usage: $self-rel_orig>.