File::Object - Object system for filesystem paths.
use File::Object; my $obj = File::Object->new(%parameters); my $self = $obj->dir(@dir); my $self = $obj->file(@file_path); my $dir = $obj->get_dir($dir_num); my $file = $obj->get_file; my $self = $obj->reset; my $path = $obj->s; my $self = $obj->set; my $self = $obj->up($num);
This provides an object oriented interface to file/directory paths, such as actual, parent or explicit directory and relative paths to them.
new
my $obj = File::Object->new(%parameters);
Constructor.
Constructor parameters are:
dir
Directory path in reference to array.
Default value is [].
file
File path.
Default value is undef.
type
Type of path. Types:
- file - dir
Default value is 'dir'.
Returns instance of object.
my $self = $obj->dir(@dir);
Add directory or directories to object.
my $self = $obj->file(@file_path);
Add file or directory/directories with file to object.
get_dir
my $dir = $obj->get_dir($dir_num);
Default value of $dir_num is 1.
$dir_num
Returns $dir_num level directory.
get_file
my $file = $obj->get_file;
Returns:
- Filename if object is file path. - undef if object is directory path.
reset
my $self = $obj->reset;
Reset to constructor values.
s
my $path = $obj->s;
Serialize path and return.
Returns string.
set
my $self = $obj->set;
Set actual values to constructor values.
up
my $self = $obj->up($num);
Go to upper directory/ies defined by $num count. Default value is one.
$num
new(): 'dir' parameter must be a reference to array. Bad 'type' parameter. Bad file constructor with undefined 'file' parameter. From Class::Utils::set_params(): Unknown parameter '%s'. up(): Cannot go up. PATH -> path;
use strict; use warnings; use File::Object; # Print actual directory path. print File::Object->new->s."\n"; # Output which runs from /usr/local/bin: # /usr/local/bin
use strict; use warnings; use File::Object; # Print parent directory path. print File::Object->new->up->s."\n"; # Output which runs from /usr/local/bin: # /usr/local
use strict; use warnings; use File::Object; # Object with directory path. my $obj = File::Object->new( 'dir' => ['path', 'to', 'subdir'], ); # Relative path to file1. print $obj->file('file1')->s."\n"; # Relative path to file2. print $obj->file('file2')->s."\n"; # Output: # Unix: # path/to/subdir/file1 # path/to/subdir/file2 # Windows: # path\to\subdir\file1 # path\to\subdir\file2
use strict; use warnings; use File::Object; # Object with directory path. my $obj = File::Object->new( 'dir' => ['path', 'to', 'subdir'], ); # Relative path to dir1. print $obj->dir('dir1')->s."\n"; # Relative path to dir2. print $obj->reset->dir('dir2')->s."\n"; # Output: # Unix: # path/to/subdir/dir1 # path/to/subdir/dir2 # Windows: # path\to\subdir\dir1 # path\to\subdir\dir2
Class::Utils, Error::Pure, FindBin, File::Spec::Functions.
file and directory objects
portably perform operations on file names
IO::All to Larry Wall!
Cross-platform path specification manipulation
File path utility
https://github.com/michal-josef-spacek/File-Object
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2009-2023 Michal Josef Špaček
BSD 2-Clause License
0.18
To install File::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Object
CPAN shell
perl -MCPAN -e shell install File::Object
For more information on module installation, please visit the detailed CPAN module installation guide.