IO::All

IO::All combines all of the best Perl IO modules into a single nifty object oriented interface.
Download

IO::All Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Ingy dt Net
  • Publisher web site:
  • http://search.cpan.org/~ingy/Vroom-0.13/lib/Vroom/Vroom.pm

IO::All Tags


IO::All Description

IO::All combines all of the best Perl IO modules into a single nifty object oriented interface. IO::All - IO::All of it to Graham and Damian!SYNOPSIS use IO::All; # Let the madness begin... # Some of the many ways to read a whole file into a scalar io('file.txt') > $contents; # Overloaded "arrow" $contents < io 'file.txt'; # Flipped but same operation $io = io 'file.txt'; # Create a new IO::All object $contents = $$io; # Overloaded scalar dereference $contents = $io->all; # A method to read everything $contents = $io->slurp; # Another method for that $contents = join '', $io->getlines; # Join the separate lines $contents = join '', map "$_n", @$io; # Same. Overloaded array deref $io->tie; # Tie the object as a handle $contents = join '', ; # And use it in builtins # and the list goes on ... # Other file operations: @lines = io('file.txt')->slurp; # List context slurp $content > io('file.txt'); # Print to a file io('file.txt')->print($content, $more); # (ditto) $content >> io('file.txt'); # Append to a file io('file.txt')->append($content); # (ditto) $content io('copy.txt'); # Invokes File::Copy io('more.txt') >> io('all.txt'); # Add on to a file # UTF-8 Support $contents = io('file.txt')->utf8->all; # Turn on utf8 use IO::All -utf8; # Turn on utf8 for all io $contents = io('file.txt')->all; # by default in this package. # General Encoding Support $contents = io('file.txt')->encoding('big5')->all; use IO::All -encoding => 'big5'; # Turn on big5 for all io $contents = io('file.txt')->all; # by default in this package. # Print the path name of a file: print $io->name; # The direct method print "$io"; # Object stringifies to name print $io; # Quotes not needed here print $io->filename; # The file portion only # Read all the files/directories in a directory: $io = io('my/directory/'); # Create new directory object @contents = $io->all; # Get all contents of dir @contents = @$io; # Directory as an array @contents = values %$io; # Directory as a hash push @contents, $subdir # One at a time while $subdir = $io->next; # Print the name and file type for all the contents above: print "$_ is a " . $_->type . "n" # Each element of @contents for @contents; # is an IO::All object!! # Print first line of each file: print $_->getline # getline gets one line for io('dir')->all_files; # Files only # Print names of all files/dirs three directories deep: print "$_n" for $io->all(3); # Pass in the depth. Default=1 # Print names of all files/dirs recursively: print "$_n" for $io->all(0); # Zero means all the way down print "$_n" for $io->All; # Capitalized shortcut print "$_n" for $io->deep->all; # Another way # There are some special file names: print io('-'); # Print STDIN to STDOUT io('-') > io('-'); # Do it again io('-') < io('-'); # Same. Context sensitive. "Bad puppy" > io('='); # Message to STDERR $string_file = io('$'); # Create IO::String Object $temp_file = io('?'); # Create a temporary file # Socket operations: $server = io('localhost:5555')->fork; # Create a daemon socket $connection = $server->accept; # Get a connection socket $input < $connection; # Get some data from it "Thank you!" > $connection; # Thank the caller $connection->close; # Hang up io(':6666')->accept->slurp > io->devnull; # Take a complaint and file it # DBM database operations: $dbm = io 'my/database'; # Create a database object print $dbm->{grocery_list}; # Hash context makes it a DBM $dbm->{todo} = $new_list; # Write to database $dbm->dbm('GDBM_file'); # Demand specific DBM io('mydb')->mldbm->{env} = %ENV; # MLDBM support # Tie::File support: $io = io 'file.txt'; $io-> = 'Line Forty Three'; # Change a line print $io->; # Print middle line @$io = reverse @$io; # Reverse lines in a file # Stat functions: printf "%s %s %sn", # Print name, uid and size of $_->name, $_->uid, $_->size # contents of current directory for io('.')->all; print "$_n" for sort # Use mtime method to sort all {$b->mtime $a->mtime} # files under current directory io('.')->All_Files; # by recent modification time. # File::Spec support: $contents < io->catfile(qw(dir file.txt)); # Portable IO operation # Miscellaneous: @lines = io('file.txt')->chomp->slurp; # Chomp as you slurp @chunks = io('file.txt')->separator('xxx')->slurp; # Use alternnate record sep $binary = io('file.bin')->binary->all; # Read a binary file io('a-symlink')->readlink->slurp; # Readlink returns an object print io('foo')->absolute->pathname; # Print absolute path of foo # IO::All External Plugin Methods io("myfile") > io->("ftp://store.org"); # Upload a file using ftp $html < io->http("www.google.com"); # Grab a web page io('mailto:worst@enemy.net')->print($spam); # Email a "friend" # This is just the beginning, read on...IO::All combines all of the best Perl IO modules into a single nifty object oriented interface to greatly simplify your everyday Perl IO idioms. It exports a single function called io, which returns a new IO::All object. And that object can do it all!The IO::All object is a proxy for IO::File, IO::Dir, IO::Socket, IO::String, Tie::File, File::Spec, File::Path and File::ReadBackwards; as well as all the DBM and MLDBM modules. You can use most of the methods found in these classes and in IO::Handle (which they inherit from). IO::All adds dozens of other helpful idiomatic methods including file stat and manipulation functions.IO::All is pluggable, and modules like IO::All::LWP and IO::All::Mailto add even more functionality. Optionally, every IO::All object can be tied to itself. This means that you can use most perl IO builtins on it: readline, , getc, print, printf, syswrite, sysread, close.The distinguishing magic of IO::All is that it will automatically open (and close) files, directories, sockets and other IO things for you. You never need to specify the mode ('>', etc), since it is determined by the usage context. That means you can replace this: open STUFF, ' Requirements: · Perl


IO::All Related Software