Иван Бахчеев > IO-Easy > IO::Easy

Download:
IO-Easy-0.16.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.16   Source  

NAME ^

IO::Easy - is easy to use class for operations with filesystem objects.

ABSTRACT ^

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.

SYNOPSIS ^

        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;

METHODS ^

new

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.

filesystem object path manipulation

path

return current filesystem object path, also available as overload of "" # ???

        # example :
        $file->path     # /home/user/my_stuff/file.txt

name

return current filesystem object name, without path (filename in most of cases)

        # example :
        $file->name     # file.txt

base_name, extension

name part before last dot and after last dot

        # example :
        $file->base_name        # file
        $file->extension        # txt

as_file, as_dir

rebless object with specified type (currently 'dir' or 'file')

abs_path

absolute path

        # example :
        $file->abs_path # /home/user/my_stuff.bak/file.txt

append, append_in_place

append filesystem objects to IO::Easy object

        my $config = IO::Easy::Dir->current->append (qw(etc config.json));

produce ./etc/config.json on unix

file_io, dir_io

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

up, parent

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'

rel_path

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_components

path, split by filesystem separators

filesystem object manipulation

attach_interface

rebless object with autodetected filesystem object type

stat, modified, dev, inode, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, blocks

complete stat array or this array accessors

touch

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

AUTHOR ^

Ivan Baktsheev, <apla at the-singlers.us>

BUGS ^

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.

SUPPORT ^

ACKNOWLEDGEMENTS ^

COPYRIGHT & LICENSE ^

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.

syntax highlighting: