SYNOPSIS

    use IO::All;

    "hello world\n" > io('ftp://localhost/test/x');   # save to FTP
    $content < io('http://example.org');              # GET webpage

    io('http://example.org') > io('index.html');      # save webpage

DESCRIPTION

This module acts as glue between IO::All and \s-1LWP\s0, so that files can be read and written through the network using the convenient <IO:All> interface. Note that this module is not \*(C`use\*(C'd directly: you just use IO::All, which knows when to autoload IO::All::HTTP, IO::All::HTTPS, IO::All::FTP, or IO::All::Gopher, which implement the specific protocols based on IO::All::LWP.

EXECUTION MODEL

\s-1GET\s0 requests. When the IO::All object is opened, the \s-1URI\s0 is fetched and stored by the object in an internal file handle. It can then be accessed like any other file via the IO::All methods and operators, it can be tied, etc.

\s-1PUT\s0 requests. When the IO::All object is opened, an internal file handle is created. It is possible to that file handle using the various IO::All methods and operators, it can be tied, etc. If $io->put is not called explicitly, when the IO::All object is closed, either explicitly via $io->close or automatically upon destruction, the actual \s-1PUT\s0 request is made.

The bad news is that the whole file is stored in memory after getting it or before putting it. This may cause problems if you are dealing with multi-gigabyte files!

METHODS

The simplest way of doing things is via the overloaded operators > and <, as shown in the \s-1SYNOPSIS\s0. These take care of automatically opening and closing the files and connections as needed. However, various methods are available to provide a finer degree of control.

This is a subclass of IO::All. In addition to the inherited methods, the following methods are available:

  • ua Set or get the user agent object (LWP::UserAgent or a subclass). If called with a list, the list is passed to LWP::UserAgent->new. If called with an object, the object is used directly as the user agent. Note that there is a default user agent if no user agent is specified.

  • uri Set or get the \s-1URI\s0. It can take either a \s-1URI\s0 object or a string, and it returns an \s-1URI\s0 object. Note that calling this method overrides the user and password fields, because URIs can contain authentication information.

  • user Set or get the user name for authentication. Note that the user name (and the password) can also be set as part of the \s-1URL\s0, as in \*(L"http://me:[email protected]/\*(R".

  • password Set or get the password for authentication. Note that the password can also be set as part of the \s-1URL\s0, as discussed above.

  • get \s-1GET\s0 the current \s-1URI\s0 using \s-1LWP\s0. Or, if called with an HTTP::Request object as a parameter, it does that request instead. It returns the HTTP::Response object.

  • put \s-1PUT\s0 to the current \s-1URI\s0 using \s-1LWP\s0. If called with an HTTP::Request object, it does that request instead. If called with a scalar, it PUTs that as the content to the current \s-1URI\s0, instead of the current accumulated content.

  • response Return the HTTP::Response object.

  • request Does an \s-1LWP\s0 request. It requires an HTTP::Request object as a parameter. Returns an HTTP::Response object.

  • open Overrides the \*(C`open\*(C' method from IO::All. It takes care of GETting the content, or of setting up the internal buffer for PUTting. Just like the \*(C`open\*(C' method from IO::All, it can take a mode: '<' for \s-1GET\s0 and '>' for \s-1PUT\s0.

  • close Overrides the \*(C`close\*(C' method from IO::All. It takes care of PUTting the content.

DEPENDENCIES

This module uses \s-1LWP\s0 for all the heavy lifting. It also requires perl-5.8.0 or a more recent version.

RELATED TO IO::All::LWP…

IO::All, \s-1LWP\s0, IO::All::HTTP, IO::All::FTP.

AUTHORS

Ivan Tubert-Brohman <[email protected]> and Brian Ingerson <[email protected]>

Thanks to Sergey Gleizer for the ua method.

COPYRIGHT

Copyright (c) 2007. Ivan Tubert-Brohman and Brian Ingerson. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>