Bot-Cobalt

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "POE::Component::SSLify" : "1.006"
         },
         "requires" : {
            "App::bmkpasswd" : "2",
            "DB_File" : "0",
            "Devel::StackTrace" : "0",
            "Digest::MD5" : "0",
            "Exporter::Tiny" : "0",
            "Fcntl" : "0",
            "File::ShareDir" : "1",
            "HTTP::Request" : "0",
            "HTTP::Response" : "0",
            "IRC::Utils" : "0.12",
            "Import::Into" : "0",
            "JSON::MaybeXS" : "0",
            "List::Objects::Types" : "1.002",
            "List::Objects::WithUtils" : "2.008",
            "Module::Runtime" : "0",
            "Moo" : "1.006",
            "Net::IP::Minimal" : "0.04",
            "POE" : "1.3",

META.yml  view on Meta::CPAN

recommends:
  POE::Component::SSLify: '1.006'
requires:
  App::bmkpasswd: '2'
  DB_File: '0'
  Devel::StackTrace: '0'
  Digest::MD5: '0'
  Exporter::Tiny: '0'
  Fcntl: '0'
  File::ShareDir: '1'
  HTTP::Request: '0'
  HTTP::Response: '0'
  IRC::Utils: '0.12'
  Import::Into: '0'
  JSON::MaybeXS: '0'
  List::Objects::Types: '1.002'
  List::Objects::WithUtils: '2.008'
  Module::Runtime: '0'
  Moo: '1.006'
  Net::IP::Minimal: '0.04'
  POE: '1.3'

Makefile.PL  view on Meta::CPAN

  "MIN_PERL_VERSION" => "5.012001",
  "NAME" => "Bot::Cobalt",
  "PREREQ_PM" => {
    "App::bmkpasswd" => 2,
    "DB_File" => 0,
    "Devel::StackTrace" => 0,
    "Digest::MD5" => 0,
    "Exporter::Tiny" => 0,
    "Fcntl" => 0,
    "File::ShareDir" => 1,
    "HTTP::Request" => 0,
    "HTTP::Response" => 0,
    "IRC::Utils" => "0.12",
    "Import::Into" => 0,
    "JSON::MaybeXS" => 0,
    "List::Objects::Types" => "1.002",
    "List::Objects::WithUtils" => "2.008",
    "Module::Runtime" => 0,
    "Moo" => "1.006",
    "Net::IP::Minimal" => "0.04",
    "POE" => "1.3",

Makefile.PL  view on Meta::CPAN

  "App::bmkpasswd" => 2,
  "Capture::Tiny" => 0,
  "DB_File" => 0,
  "Devel::StackTrace" => 0,
  "Digest::MD5" => 0,
  "Exporter::Tiny" => 0,
  "ExtUtils::MakeMaker" => 0,
  "Fcntl" => 0,
  "File::ShareDir" => 1,
  "File::Spec" => 0,
  "HTTP::Request" => 0,
  "HTTP::Response" => 0,
  "IRC::Utils" => "0.12",
  "Import::Into" => 0,
  "JSON::MaybeXS" => 0,
  "List::Objects::Types" => "1.002",
  "List::Objects::WithUtils" => "2.008",
  "Module::Runtime" => 0,
  "Moo" => "1.006",
  "Net::IP::Minimal" => "0.04",
  "POE" => "1.3",

cpanfile  view on Meta::CPAN


requires "Devel::StackTrace" => "0";

requires "Digest::MD5" => "0";

requires "Exporter::Tiny" => "0";

requires "Fcntl" => "0";
requires "File::ShareDir" => "1";

requires "HTTP::Request" => "0";
requires "HTTP::Response" => "0";

requires "Import::Into" => "0";
requires "IRC::Utils" => "0.12";

requires "JSON::MaybeXS" => "0";

requires "List::Objects::WithUtils" => "2.008";
requires "List::Objects::Types" => "1.002";

lib/Bot/Cobalt/Manual/Plugins.pod  view on Meta::CPAN


It's fairly common to want to make some kind of HTTP request from an 
IRC bot. The most common Perl method of speaking HTTP is 
L<LWP::UserAgent> -- which will block the plugin pipeline until the 
request is complete.

L<Bot::Cobalt::Plugin::WWW>, if loaded, dispatches HTTP requests 
asynchronously via L<POE::Component::Client::HTTP> and returns 
L<HTTP::Response> responses to the plugin pipeline:

  ## build a request object via HTTP::Request
  use HTTP::Request;

  ## a simple GET, see HTTP::Request docs for more info:
  my $request = HTTP::Request->new( 'GET', $url );

  ## push it to www_request with a response event:
  broadcast( 'www_request',
    $request,
    'myplugin_resp_recv',

     ## you can include a reference containing args
     ## (or a scalar, if you like)
     ##
     ## here's an example args arrayref telling our handler 

lib/Bot/Cobalt/Manual/Plugins.pod  view on Meta::CPAN

    ## eat this event, we're the only handler:
    return PLUGIN_EAT_ALL
  }

When a response is received, it will be pushed to the plugin pipeline 
as the specified SERVER event.

If the plugin is available, B<< $core->Provided->{www_request} >> will be 
boolean true:

  my $request = HTTP::Request->new( . . . );
  if ($core->Provided->{www_request}) {
    ## send www_request event like above
    . . .   
  } else {
    ## no async available, error out or use LWP or something:
    my $ua = LWP::UserAgent->new(
      timeout => 5,
      max_redirect => 0,
    );
    my $response = $ua->request($request);

lib/Bot/Cobalt/Plugin/Extras/CPAN.pm  view on Meta::CPAN

package Bot::Cobalt::Plugin::Extras::CPAN;
$Bot::Cobalt::Plugin::Extras::CPAN::VERSION = '0.021003';
use strictures 2;

use Bot::Cobalt;
use Bot::Cobalt::Common;

use Bot::Cobalt::Serializer;
our $Serializer = Bot::Cobalt::Serializer->new('JSON');

use HTTP::Request;

use Module::CoreList;

use Try::Tiny;

our $HelpText
  = 'try: dist, latest, tests, abstract, changes, belongs, license';

## FIXME cachedb?

lib/Bot/Cobalt/Plugin/Extras/CPAN.pm  view on Meta::CPAN

}

sub _request {
  my ($self, $url, $hints) = @_;

  my $base_url = 'http://api.metacpan.org';
  my $this_url = $base_url . $url;

  logger->debug("metacpan request: $this_url");

  my $request = HTTP::Request->new(GET => $this_url);

  broadcast( 'www_request',
    $request,
    'mcpan_plug_resp_recv',
    $hints
  );
}

sub Bot_mcpan_plug_resp_recv {
  my ($self, $core) = splice @_, 0, 2;

lib/Bot/Cobalt/Plugin/WWW.pm  view on Meta::CPAN


  return PLUGIN_EAT_NONE
}

sub Bot_www_request {
  my ($self, $core) = splice @_, 0, 2;
  my $request = ${ $_[0] };
  my $event   = defined $_[1] ? ${$_[1]} : undef ;
  my $args    = defined $_[2] ? ${$_[2]} : undef ;

  unless ($request && $request->isa('HTTP::Request')) {
    logger->warn(
      "www_request received but no request at "
      .join ' ', (caller)[0,2]
    );
  }
  
  unless ($event) {
    ## no event at all is legitimate
    $event = 'www_not_handled';
  }

lib/Bot/Cobalt/Plugin/WWW.pm  view on Meta::CPAN


=pod

=head1 NAME

Bot::Cobalt::Plugin::WWW - Asynchronous HTTP requests from Cobalt plugins

=head1 SYNOPSIS

  ## Send your request, specify an event to handle response:
  use HTTP::Request;
  my $request = HTTP::Request->new(
    'GET',
    'http://www.cobaltirc.org'
  );
  
  broadcast( 'www_request',
    $request,
    'myplugin_resp_recv',
    [ $some, $args ]
  );
  

lib/Bot/Cobalt/Plugin/WWW.pm  view on Meta::CPAN

    
    return PLUGIN_EAT_ALL
  }

=head1 DESCRIPTION

This plugin provides an easy interface to asynchronous HTTP requests; it 
bridges Cobalt's plugin pipeline and L<POE::Component::Client::HTTP> to 
provide responses to B<Bot_www_request> events.

The request should be a L<HTTP::Request> object.

Inside the response handler, $_[1] will contain the L<HTTP::Response> 
object; $_[0] is the undecoded content if the request was successful or 
some error from L<HTTP::Status> if not.

Arguments can be attached to the request event and retrieved in the 
handler via $_[2] -- this is usually an array reference, but anything 
that fits in a scalar will do.

Plugin authors should check for the boolean value of B<< 
$core->Provided->{www_request} >> and possibly fall back to using LWP 
with a short timeout if they'd like to continue to function if this 
plugin is B<not> loaded.

=head1 SEE ALSO

L<POE::Component::Client::HTTP>

L<HTTP::Request>

L<HTTP::Response>

=head1 AUTHOR

Jon Portnoy <avenj@cobaltirc.org>

L<http://www.cobaltirc.org>

=cut

t/00-report-prereqs.dd  view on Meta::CPAN

                                        'POE::Component::SSLify' => '1.006'
                                      },
                      'requires' => {
                                      'App::bmkpasswd' => '2',
                                      'DB_File' => '0',
                                      'Devel::StackTrace' => '0',
                                      'Digest::MD5' => '0',
                                      'Exporter::Tiny' => '0',
                                      'Fcntl' => '0',
                                      'File::ShareDir' => '1',
                                      'HTTP::Request' => '0',
                                      'HTTP::Response' => '0',
                                      'IRC::Utils' => '0.12',
                                      'Import::Into' => '0',
                                      'JSON::MaybeXS' => '0',
                                      'List::Objects::Types' => '1.002',
                                      'List::Objects::WithUtils' => '2.008',
                                      'Module::Runtime' => '0',
                                      'Moo' => '1.006',
                                      'Net::IP::Minimal' => '0.04',
                                      'POE' => '1.3',



( run in 0.446 second using v1.01-cache-2.11-cpan-de7293f3b23 )