IO::Easy - is easy to use class for operations with filesystem objects.
We wanted to provide Perl with the interface for file system objects with the simplicity similar to shell. The following operations can be used as an example: operations for recursive creation (mkdir -p) and removing (rm -rf), touching file.
IO::Easy transparently handles OS path delimiters (e.g., Win* or *nix) using File::Spec module and does not require a lot of additional modules from CPAN.
For better understanding of IO::Easy processing principles you should keep in mind that it operates with "Path Context". "Path Context" means that for any path in any file system IO::Easy takes path parts which are between path separators, but doesn't include path separators themselves, and tries to build the path in the current system using these path parts. This way it can substitute different path separators from system to system (as long as they may differ depending on operating system, this also includes drive specification e.g. for Windows) and doesn't depend on some system specifics of paths representation.
use IO::Easy; # abstract filesystem i/o interface my $io = IO::Easy->new ('.'); # directory interface my $dir = $io->as_dir; # or easy $dir = dir->current; $dir = dir->new ('.'); # or even easier $dir = dir ('.'); # file object "./example.txt" for unix my $file = $io->append ('example.txt')->as_file; # or $file = $io->file_io ('example.txt'); my $content = "Some text goes here!"; # Overwrite file contents with $content $file->store ($content);
or
# easier scripts: you can replace IO::Easy::Dir for dir and so on use IO::Easy qw(script); my $abs_path = dir->current->abs_path; # IO::Easy::Dir->current->abs_path; my $test_file = file->new ('test'); $test_file->touch; print "ok" if -f $test_file and $test_file->size eq 0;
Creates new IO::Easy object, takes path as parameter. IO::Easy object for abstract file system path. For operating with typed objects there were 2 additional modules created: IO::Easy::File IO::Easy::Dir
You can use method attach_interface for automatic object conversion for existing filesystem object or force type by using methods as_file or as_dir.
Init file object: my $io = IO::Easy->new ('/'); my $file = $io->append(qw(home user my_stuff.bak file.txt));
In examples we will use this object to show results of method call.
return current filesystem object path, also available as overload of "" # ???
# example : $file->path # /home/user/my_stuff/file.txt
return current filesystem object name, without path (filename in most of cases)
# example : $file->name # file.txt
name part before last dot and after last dot
# example : $file->base_name # file $file->extension # txt
rebless object with specified type (currently 'dir' or 'file')
absolute path
# example : $file->abs_path # /home/user/my_stuff.bak/file.txt
append filesystem objects to IO::Easy object
my $config = IO::Easy::Dir->current->append (qw(etc config.json));
produce ./etc/config.json on unix
append filesystem objects to IO::Easy subclass object
my $config = IO::Easy::Dir->current->file_io (qw(etc config.json));
produce ./etc/config.json on unix, blessed into IO::Easy::File
directory container for io object
my $config = IO::Easy::Dir->current->append (qw(etc config.json)); # './etc/config.json' my $config_dir = $config->up; # './etc'
relative path to specified directory
my $current = IO::Easy::Dir->current; # '.' my $config = $current->append (qw(etc config.json)); # './etc/config.json' my $config_rel = $config->rel_path ($current); # 'etc/config.json'
path, split by filesystem separators
rebless object with autodetected filesystem object type
complete stat array or this array accessors
constructor for IO::Easy::Dir object
my $current = IO::Easy::Dir->current; # '.' my $config = $current->append (qw(etc config.json)); # './etc/config.json' $config->touch; # file created
Ivan Baktsheev, <apla at the-singlers.us>
<apla at the-singlers.us>
Please report any bugs or feature requests to my email address, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Easy. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
Copyright 2007-2009 Ivan Baktsheev
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
=cut found outside a pod block. Skipping to next block.
To install IO::Easy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Easy
CPAN shell
perl -MCPAN -e shell install IO::Easy
For more information on module installation, please visit the detailed CPAN module installation guide.