The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Path::Abstract::Fast - Path::Abstract without stringification overloading

SYNOPSIS

  use Path::Abstract::Fast;

  my $path = Path::Abstract::Fast->new("/apple/banana");

  # $parent is "/apple"
  my $parent = $path->parent;

  # $cherry is "/apple/banana/cherry.txt"
  my $cherry = $path->child("cherry.txt");

DESCRIPTION

This is a version of Path::Abstract without the magic "use overload ..." stringification. You should experience a significant speedup if you use Path::Abstract::Fast instead of Path::Abstract

Unfortunately, without overloading, you can't do this:

    my $path = Path::Abstract::Fast->new("/a/path/to/somewhere");

    print "$path\n"; # Will print out something like "Path::Abstract::Fast=SCALAR(0xdffaa0)\n"

You'll have to do this instead:

    print $path->get, "\n"; Will print out "/a/path/to/somewhere\n"
    # Note, you can also use $path->stringify or $path->path

    # You could also do this (but it's safer to do one of the above):
    print $$path, "\n";

Thanks to JJORE, MKANAT, and KONOBI for discovering this

METHODS

Path::Abstract::Fast->new( <path> )

Path::Abstract::Fast->new( <part>, [ <part>, ..., <part> ] )

Create a new Path::Abstract::Fast object using <path> or by joining each <part> with "/"

Returns the new Path::Abstract::Fast object

Path::Abstract::Fast::path( <path> )

Path::Abstract::Fast::path( <part>, [ <part>, ..., <part> ] )

Create a new Path::Abstract::Fast object using <path> or by joining each <part> with "/"

Returns the new Path::Abstract::Fast object

$path->clone

Returns an exact copy of $path

$path->set( <path> )

$path->set( <part>, [ <part>, ..., <part> ] )

Set the path of $path to <path> or the concatenation of each <part> (separated by "/")

Returns $path

$path->is_nil

$path->is_empty

Returns true if $path is equal to ""

$path->is_root

Returns true if $path is equal to "/"

$path->is_tree

Returns true if $path begins with "/"

        path("/a/b")->is_tree # Returns true
        path("c/d")->is_tree # Returns false

$path->is_branch

Returns true if $path does NOT begin with a "/"

        path("c/d")->is_branch # Returns true
        path("/a/b")->is_branch # Returns false

$path->to_tree

Change $path by prefixing a "/" if it doesn't have one already

Returns $path

$path->to_branch

Change $path by removing a leading "/" if it has one

Returns $path

$path->list

$path->split

Returns the path in list form by splitting at each "/"

        path("c/d")->list # Returns ("c", "d")
        path("/a/b/")->last # Returns ("a", "b")

$path->first

Returns the first part of $path up to the first "/" (but not including the leading slash, if any)

        path("c/d")->first # Returns "c"
        path("/a/b")->first # Returns "a"

$path->last

Returns the last part of $path up to the last "/"

        path("c/d")->last # Returns "d"
        path("/a/b/")->last # Returns "b"

path

$path->get

$path->stringify

Returns the path in string or scalar form

        path("c/d")->list # Returns "c/d"
        path("/a/b/")->last # Returns "/a/b"

$path->push( <part>, [ <part>, ..., <part> ] )

$path->down( <part>, [ <part>, ..., <part> ] )

Modify $path by appending each <part> to the end of \$path, separated by "/"

Returns $path

$path->child( <part>, [ <part>, ..., <part> ] )

Make a copy of $path and push each <part> to the end of the new path.

Returns the new child path

$path->pop( <count> )

Modify $path by removing <count> parts from the end of $path

Returns the removed path as a Path::Abstract::Fast object

$path->up( <count> )

Modify $path by removing <count> parts from the end of $path

Returns $path

$path->parent( <count> )

Make a copy of $path and pop <count> parts from the end of the new path

Returns the new parent path

$path->file

$path->file( <part>, [ <part>, ..., <part> ] )

Create a new Path::Class::File object using $path as a base, and optionally extending it by each <part>

Returns the new file object

$path->dir

$path->dir( <part>, [ <part>, ..., <part> ] )

Create a new Path::Class::Dir object using $path as a base, and optionally extending it by each <part>

Returns the new dir object