Reflexive::Client::HTTP::Role - A role for automatically getting a watched Reflexive::Client::HTTP
version 0.007
{ package MySampleClient; use Moose; with 'Reflexive::Client::HTTP::Role'; sub on_http_response { my ( $self, $response_event ) = @_; my $http_response = $response_event->response; my ( $who ) = @{$response_event->args}; print $who." got status ".$http_response->code."\n"; } sub request { my ( $self, $who ) = @_; $self->http_request( HTTP::Request->new( GET => 'http://www.duckduckgo.com/' ), $who ); } } my $msc = MySampleClient->new; $msc->request('peter'); $msc->request('paul'); $msc->request('marry'); Reflex->run_all();
If you attach this role, your Moose class gets an additional attribute http which contains a Reflexive::Client::HTTP. This allows you to add a simple on_http_response method, which gets the Reflexive::Client::HTTP::ResponseEvent on the success of a previous executed call to "http_request".
http
on_http_response
This watched attribute containts the Reflexive::Client::HTTP. It handles "http_request" which triggers "request" in Reflexive::Client::HTTP.
This HashRef is used for constructing the Reflexive::Client::HTTP in "http".
See "request" in Reflexive::Client::HTTP.
Torsten Raudssus <torsten@raudss.us>
This software is copyright (c) 2012 by Torsten Raudssus.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Reflexive::Client::HTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Reflexive::Client::HTTP
CPAN shell
perl -MCPAN -e shell install Reflexive::Client::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.