NAME

Util::Medley::File - utility file methods

VERSION

version 0.007

SYNOPSIS

my $file = Util::Medley::File->new;

my $basename = $file->basename($path);
my $dirname  = $file->dirname($path);
my $newpath  = $file->trimSuffix($path);

my ($dir, $filename, $suffix) = $file->parsePath($path);

$file->cp($src, $dest);
$file->mv($src, $dest);
$file->chmod($path);
$file->mkdir($path);
$file->rmdir($path);
$file->unlink($path);

my $prev_dir = $file->chdir($path);
my $type     = $file->fileType($path);
my @found    = $file->find($path);
my $cwd      = $file->getcwd;

$file->xmllint(path => $path);
my $formated_xml = $file->xmllint(string => $myxml);

DESCRIPTION

Provides frequently used file operation methods. Many of these are pass-through to a standard module. Others offer variations on the originals. All methods output debug logging statements when enabled. Any errors are bubbled up with Carp::confess(). Use eval as appropriate.

METHODS

basename

Pass-through to File::Path::basename().

usage:
my $basename = $file->basename($path);
args:
path [Str]

The file path.

chdir

Pass-through to CORE::chdir(), but differs in that it returns the original dir.

usage:
my $previous_dir = $file->chdir($path);
args:
$path [Str]

Destination directory.

chmod

Pass-through to CORE::chmod().

usage:
$file->chmod(0755, $path);
args:
$perm [Str]

Numeric mode.

cp

Pass-through to File::Copy::copy().

usage:
$file->cp($src, $dest);
args:
$src [Str]

Source file.

$dest [Str]

Destination file.

dirname

Pass-through to File::Path::dirname().

usage:
my $dir = $file->dirname($path);
args:
path [Str]

The file path.

fileType

Get the filetype of a file.

usage:
my $type = $file->fileType($path);
args:
path [Str]

Path of the file you wish to interrogate.

find

Pass-through to Path::Iterator::Rule.

usage:
my @files = $file->find( dir => $dir, 
                       [ files_only => $bool ],
                       [ dirs_only  => $bool ]);
						
args:
dir [Str]

The directory path you wish to search.

files_only [Bool]

Return files only (no directories). Mutually exclusive from dirs_only.

dirs_only [Bool]

Return directories only (no files). Mutually exclusive from files_only.

getcwd

Pass-through to Cwd::getcwd().

usage:
my $cwd = $file->getcwd;

mkdir

Pass-through to File::Path::make_path().

usage:
$file->mkdir($path;
$file->mkdir($path, 0755);
args:
path [Str]

The directory path.

perm [Str]

Numeric mode.

mv

Pass-through to File::Copy::move().

usage:
$file->mv($src, $dest);
args:
src [Str]

The source path.

dest [Str]

The destination path.

parsePath

Parse a file path into directory, filename, and extension. This is a pass-through to File::Basename::fileparse, but it additional trims the '.' from the extension and extraneous trailing /'s in the dir.

usage:
my ($dir, $name, $ext) = $file->parsePath($path);
args:
path [Str]

The file path for which you wish to parse.

rmdir

Delete a directory and any contents. Pass-through to File::Path::remove_tree().

usage:
$file->rmdir($dir);
args:
dir [Str]

Directory to remove.

trimExt

Trim the file extension from a filename.

usage:
my $filename_no_ext = $file->trimExt($filename);
args:
filename [Str]

The filename for which you want to remove the extension.

Pass-through to CORE::unlink().

usage:
$file->unlink($path);
args:
path [Str]

Path of the file you wish to delete.

xmllint

Wrapper around the xmllint command. You can pass an xml string or the path to an xml file.

usage:
$file->xmllint($path);

my $pretty_xml = $file->xmllint($xmlstring);
args:
string [Str]

An xml string.

path [Str]

Path to an xml file.