HTTP-MultiGet

 view release on metacpan or  search on metacpan

lib/HTTP/MultiGet/Role.pm  view on Meta::CPAN

package HTTP::MultiGet::Role;

use Modern::Perl;
use Moo::Role;
use MooX::Types::MooseLike::Base qw(:all);
use AnyEvent::HTTP::MultiGet;
use AnyEvent;
use JSON qw();
use Data::Dumper;
use Carp qw(croak);
use namespace::clean;
use AnyEvent;
use Ref::Util qw(is_plain_arrayref);

BEGIN { 
  with 'Log::LogMethods','Data::Result::Moo';
}

our $AUTOLOAD;

=head1 NAME

HTTP::MultiGet::Role - Role for building blocking/non-blocking AnyEvent friendly REST Clients

=head1 SYNOPSIS

  package My::Rest::Class;

  use Modern::Perl;
  use Moo;
  BEGIN { with 'HTTP::MultiGet::Role' }

  sub que_some_request {
    my ($self,$cb)=@_;
    my $request=HTTP::Request->new(GET=>'https://some_json_endpoint');
    return $self->queue_request($request,$cb);
  }


Blocking Example

  # blocking context
  use My::Rest::Class;

  my $self=new My::Rest::Class;
  my $result=$self->some_request;
  die $result unless $result;


NonBlocking Example

  # non blocking
  use AnyEvent::Loop;
  use My::Rest::Class;

  my $self=new My::Rest::Class;
  my $id=$self->some_request(sub {
    my ($self,$id,$result,$request,$response)=@_;
  });

  $obj->agent->run_next;
  AnyEvent::Loop::run;

=head1 DESCRIPTION

In the real world we are often confronted with a situation of needing and or wanting blocking and non-blocking code, but we normally only have time to develop one or the other.  This class provided an AnyEvent friendly framework that solves some of t...

The solution presented by this module is to simply develop the non blocking interface and dynamically AUTOLOAD the blocking interface as needed.  One of the major advantages of this model of coding is it becomes possible to create asyncronous calls i...

More documentation comming soon.. time permitting.

=cut

our %MULTIGET_ARRGS=(
  timeout=>300,
  max_que_count=>20,
);

our $VERSION=$HTTP::MultiGet::VERSION;

=head1 OO Declarations

This section documents the Object Declarations.  ALl of these arguments are optional and autogenerated on demand if not passed into the constructor.

  agnet: AnyEvent::HTTP::MultiGet object
  json: JSON object

Run Time State Settings ( modify at your own risk!! )



( run in 0.626 second using v1.01-cache-2.11-cpan-39bf76dae61 )