POE::Component::SmokeBox::Recent::HTTP - an extremely minimal HTTP client
# Obtain the RECENT file from a given CPAN mirror. use strict; use warnings; use File::Spec; use POE qw(Component::SmokeBox::Recent::HTTP); use URI; my $url = shift || die "You must provide a url parameter\n"; my $uri = URI->new( $url ); die "Unsupported scheme\n" unless $uri->scheme and $uri->scheme eq 'http'; $uri->path( File::Spec::Unix->catfile( $uri->path(), 'RECENT' ) ); POE::Session->create( package_states => [ main => [qw(_start http_sockerr http_timeout http_response)], ] ); $poe_kernel->run(); exit 0; sub _start { POE::Component::SmokeBox::Recent::HTTP->spawn( uri => $uri, ); return; } sub http_sockerr { warn join ' ', @_[ARG0..$#_]; return; } sub http_timeout { warn $_[ARG0], "\n"; return; } sub http_response { my $http_response = $_[ARG0]; print $http_response->as_string; return; }
POE::Component::SmokeBox::Recent::HTTP is the small helper module used by POE::Component::SmokeBox::Recent to do HTTP client duties.
It only implements a simple request with no following of redirections and connection keep-alive, etc.
spawn
Takes a number of parameters:
'uri', a URI object for the URL you wish to retrieve, mandatory; 'session', optional if the poco is spawned from within another session; 'prefix', specify an event prefix other than the default of 'http'; 'timeout', specify a timeout in seconds, default is 60;
The component sends the following events. If you have changed the prefix option in spawn then substitute http with the event prefix that you specified.
prefix
http
http_sockerr
Generated if there is a problem connecting to the given HTTP host/address. ARG0 contains the name of the operation that failed. ARG1 and ARG2 hold numeric and string values for $!, respectively.
ARG0
ARG1
ARG2
$!
http_timeout
Triggered if we don't get a response from the HTTP server.
http_response
Emitted when the transfer has finished. ARG0 will be a HTTP::Response object. It is up to you to check the status, etc. of the response.
Chris BinGOs Williams <chris@bingosnet.co.uk>
BinGOs
Copyright © Chris Williams
This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details.
To install POE::Component::SmokeBox::Recent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::SmokeBox::Recent
CPAN shell
perl -MCPAN -e shell install POE::Component::SmokeBox::Recent
For more information on module installation, please visit the detailed CPAN module installation guide.