Chris Williams > POE-Component-SmokeBox-Recent-1.44 > POE::Component::SmokeBox::Recent::HTTP

Download:
POE-Component-SmokeBox-Recent-1.44.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

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

NAME ^

POE::Component::SmokeBox::Recent::HTTP - an extremely minimal HTTP client

SYNOPSIS ^

  # 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;
   }

DESCRIPTION ^

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.

CONSTRUCTOR ^

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;

OUTPUT EVENTS ^

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.

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.

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.

AUTHOR ^

Chris BinGOs Williams <chris@bingosnet.co.uk>

LICENSE ^

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.

syntax highlighting: