Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Util::Path
Source

Index


NAME ^

Newcomen::Util::Path - Path related utility functions.

SYNOPSIS ^

use Newcomen::Util::Path;

# Get the resolved absolute path:
my $abs_path = Newcomen::Util::Path::resolute ($path);

# Check if some file is located beneath this path:
if (contains_file ($abs_path, $file)) {
   # do something...
}

DESCRIPTION ^

This package provides utility functions dealing with paths. Note that all functions may be imported into the package using Newcomen::Util::Path:

use Newcomen::Util::List qw( contains_dir contains_file resolute );

No function is exported by default.

FUNCTIONS ^

contains_dir, contains_file

Toggle sources:   contains_dir   contains_file

sub contains_dir {

   my $parent = shift;
   my $child  = shift;

   return ($parent -> contains ($child) and -d $child -> stringify ());

}
sub contains_file {

   my $parent = shift;
   my $child  = shift;

   return ($parent -> contains ($child) and -f $child -> stringify ());

}
if (contains_dir ($ancestor, $descendant)) {
   # do something...
}

# Same for contains_file()...

These functions will check if the directory or file represented by the Path::Class instance specified as the second parameter is a direct or indirect child of the directory represented by the Path::Class::Dir instance specified as the first parameter. For both directories and files it will be checked if they actually exist on the file system.

resolute

Toggle source:   resolute

sub resolute { $_ [0] -> resolve () -> absolute () }
my $abs_path = resolute ($path);

Expects a Path::Class::Dir or Path::Class::File instance as first and only parameter, and returns a new instance with the path resolved and converted to an absolute path, by chaining the two Path::Class methods resolve() and absolute(). See Path::Class::Dir and/or Path::Class::File for details.

SEE ALSO ^

Path::Class, Path::Class::Dir, Path::Class::File

VERSION ^

This is version 2014101201.

AUTHOR ^

Stefan Goebel - newcomen {at} subtype {dot} de

COPYRIGHT AND LICENSE ^

Copyright 2013-2014 Stefan Goebel.

This file is part of Newcomen.

Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.