IO::All::LWP(3pm)

๐Ÿ’– IO::All::LWP ๐Ÿ’–

okay so bestie, this is the IO::All::LWP page from the User Contributed Perl Documentation section โ€” it's the little glue module that lets IO::All do its thing over the network, and honestly? it's giving main character energy. โœจ


โœจ NAME โœจ

IO::All::LWP โ€” the IO::All interface to LWP, no cap ๐Ÿซถ


๐ŸŒธ 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

like. look at that. three lines and you're on the internet. iconic behavior fr fr ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So this module is literally the glue between IO::All and LWP, which means you can read and write files through the network using that super cute <IO:All> interface you already know and love. ๐ŸŒˆ

But here's the thing โ€” you do not use this module directly. Nope. You just use IO::All, and it's smart enough to know when to autoload IO::All::HTTP, IO::All::HTTPS, IO::All::FTP, or IO::All::Gopher, which are the ones actually implementing the specific protocols, all built on top of IO::All::LWP. it's giving delegation, it's giving teamwork ๐ŸŽ€


๐Ÿ”ฅ EXECUTION MODEL ๐Ÿ”ฅ

GET requests ๐Ÿ’Œ

When the IO::All object gets opened, the URI is fetched and stored by the object in an internal file handle. After that you can access it like literally any other file, using all the IO::All methods and operators, and yeah it can be tied and everything. slay.

PUT requests ๐Ÿ“ฎ

When the IO::All object gets opened, an internal file handle is created. You can write to that file handle with all your fave IO::All methods and operators, and it can be tied too, etc. And if $io->put is not called explicitly? then when the IO::All object is closed โ€” either explicitly via $io->close or automatically upon destruction โ€” the actual PUT request is made. surprise! it was queued the whole time ๐Ÿ™ˆ

the bad news ๐Ÿ˜ญ

The whole file is stored in memory after getting it or before putting it. So if you're dealing with multi-gigabyte files, that may cause problems. multi. gigabyte. bestie. your RAM is NOT ready. ๐Ÿ’€


๐Ÿ‘‘ METHODS ๐Ÿ‘‘

The simplest way of doing things is via the overloaded operators > and <, like in the SYNOPSIS. They handle automatically opening and closing the files and connections as needed. effortless. but if you want a finer degree of control, there's a whole methods menu:

This is a subclass of IO::All. On top of the inherited methods, you also get:

  • ua โ€” set or get the user agent object (LWP::UserAgent or a subclass). If you call it with a list, that list gets passed to LWP::UserAgent->new. If you call it with an object, that object is used directly as the user agent. And ngl, there's a default user agent if you don't specify one, so you're never left hanging. ๐Ÿ’–
  • uri โ€” set or get the URI. It can take either a URI object or a string, and it returns a URI object. Heads up though: calling this method overrides the user and password fields, because URIs can contain authentication information. the way that it just takes over like that ๐Ÿ˜ณ
  • user โ€” set or get the user name for authentication. and remember, the user name (and the password too) can also be set as part of the URL, like "http://me:secret@example.com/". sneaky and convenient ๐Ÿ’…
  • password โ€” set or get the password for authentication. and again, the password can also be set as part of the URL, as discussed above. (yes bestie, we talked about this one line ago ๐Ÿ“)
  • get โ€” GET the current URI using LWP. Or, if you call it with an HTTP::Request object as a parameter, it does that request instead. It returns the HTTP::Response object.
  • put โ€” PUT to the current URI using LWP. 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 URI, instead of the current accumulated content. choose your own adventure โœจ
  • response โ€” return the HTTP::Response object. that's it. that's the whole job. we respect it.
  • request โ€” does an LWP request. It requires an HTTP::Request object as a parameter. Returns an HTTP::Response object. no parameter? no request. rules are rules.
  • open โ€” overrides the open method from IO::All. It takes care of GETting the content, or of setting up the internal buffer for PUTting. And just like the open method from IO::All, it can take a mode: < for GET and > for PUT. ๐ŸŒˆ
  • close โ€” overrides the close method from IO::All. It takes care of PUTting the content. the grand finale ๐ŸŽ€

๐Ÿงš DEPENDENCIES ๐Ÿงš

This module uses LWP for all the heavy lifting (it's the muscle ๐Ÿ’ช). It also requires perl-5.8.0 or a more recent version. so like, vintage perl is fine, but not that vintage.


โญ SEE ALSO โญ

IO::All, LWP, IO::All::HTTP, IO::All::FTP. go read those too bestie, iykyk ๐Ÿ“š


๐Ÿ’œ AUTHORS ๐Ÿ’œ

Ivan Tubert-Brohman <itub@cpan.org> and Brian Ingerson <ingy@cpan.org>

Thanks to Sergey Gleizer for the ua method. ๐Ÿซถ


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>


and that's the whole page, bestie! this one's running on perl v5.32.0 and it was last touched on 2021-01-04 โ€” shoutout to the IO::All::LWP(3pm) era. stay networked, stay hydrated, and pls don't load a multi-gigabyte file into memory. mwah ๐Ÿ’–โœจ
๐Ÿ“ฆ where this page comes from