AnyEvent::Net::Curl::Queued::Easy - Net::Curl::Easy wrapped by Moo
version 0.049
package MyIEDownloader; use strict; use utf8; use warnings qw(all); use Moo; use Net::Curl::Easy qw(/^CURLOPT_/); extends 'AnyEvent::Net::Curl::Queued::Easy'; after init => sub { my ($self) = @_; $self->setopt(CURLOPT_ENCODING, ''); $self->setopt(CURLOPT_FOLLOWLOCATION, 1); $self->setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'); $self->setopt(CURLOPT_VERBOSE, 1); }; after finish => sub { my ($self, $result) = @_; if ($self->has_error) { printf "error downloading %s: %s\n", $self->final_url, $result; } else { printf "finished downloading %s: %d bytes\n", $self->final_url, length ${$self->data}; } }; around has_error => sub { my $orig = shift; my $self = shift; return 1 if $self->$orig(@_); return 1 if $self->getinfo(Net::Curl::Easy::CURLINFO_RESPONSE_CODE) =~ m{^5[0-9]{2}$}; }; 1;
This module isn't using Any::Moose anymore due to the announced deprecation status of that module. The switch to the Moo is known to break modules that do extend 'AnyEvent::Net::Curl::Queued::Easy' / extend 'YADA::Worker'! To keep the compatibility, make sure that you are using MooseX::NonMoose:
extend 'AnyEvent::Net::Curl::Queued::Easy'
extend 'YADA::Worker'
package YourSubclassingModule; use Moose; use MooseX::NonMoose; extends 'AnyEvent::Net::Curl::Queued::Easy'; ...
Or MouseX::NonMoose:
package YourSubclassingModule; use Mouse; use MouseX::NonMoose; extends 'AnyEvent::Net::Curl::Queued::Easy'; ...
Or the Any::Moose equivalent:
package YourSubclassingModule; use Any::Moose; use Any::Moose qw(X::NonMoose); extends 'AnyEvent::Net::Curl::Queued::Easy'; ...
However, the recommended approach is to switch your subclassing module to Moo altogether (you can use MooX::late to smoothen the transition):
package YourSubclassingModule; use Moo; use MooX::late; extends 'AnyEvent::Net::Curl::Queued::Easy'; ...
The class you should overload to fetch stuff your own way.
libcurl return code (Net::Curl::Easy::Code).
Net::Curl::Easy::Code
Receive buffer.
Force request processing, despite the uniqueness signature.
Header buffer.
Encapsulate the response with HTTP::Response (only when the scheme is HTTP/HTTPS). Default: disabled.
Cache POST content to perform retries.
URL to fetch (string).
Final URL (after redirections).
HashRef to be passed to setopt() during initialization (inside init(), before on_init() callback).
HashRef
setopt()
init()
on_init()
AnyEvent::Net::Curl::Queued circular reference.
Uniqueness detection helper. Setup via sign and access through unique.
sign
unique
Encapsulated HTTP::Response instance, if "http_response" was set.
Deprecated alias for "response".
Number of retries (default: 10).
AnyEvent::Net::Curl::Queued::Stats instance.
Set to true to enable stats computation. Note that extracting libcurl time/size data degrades performance slightly.
libcurl
Callback you can define instead of extending the init method. Almost the same as after init => sub { ... }
init
after init => sub { ... }
Callback you can define instead of extending the finish method. Almost the same as after finish => sub { ... }
finish
after finish => sub { ... }
Returns the unique signature of the request. By default, the signature is derived from Digest::SHA of the initial_url.
initial_url
Use $str to compute the unique value. Useful to successfully enqueue POST parameters.
$str
Initialize the instance. We can't use the default BUILD method as we need the initialization to be done after the instance is in the queue.
BUILD
You are supposed to build your own stuff after/around/before this method using method modifiers.
Error handling: if has_error returns true, the request is re-enqueued (until the retries number is exhausted).
has_error
You are supposed to build your own stuff after/around/before this method using method modifiers. For example, to retry on server error (HTTP 5xx response code):
around has_error => sub { my $orig = shift; my $self = shift; return 1 if $self->$orig(@_); return 1 if $self->getinfo('response_code') =~ m{^5[0-9]{2}$}; };
Called when the download is finished. $result holds the Net::Curl::Easy::Code.
$result
Clones the instance, for re-enqueuing purposes.
Extends Net::Curl::Easy setopt(), allowing option lists:
$self->setopt( CURLOPT_ENCODING, '', CURLOPT_FOLLOWLOCATION, 1, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)', CURLOPT_VERBOSE, 1, );
Or even shorter:
$self->setopt( encoding => '', followlocation => 1, useragent => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)', verbose => 1, );
Complete list of options: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
If CURLOPT_POSTFIELDS is a HashRef or looks like a valid JSON (validates via JSON), it is encoded as UTF-8 and Content-Type: application/json; charset=utf-8 header is set automatically.
CURLOPT_POSTFIELDS
Content-Type: application/json; charset=utf-8
Extends Net::Curl::Easy getinfo() so it is able to get several variables at once; HashRef parameter under void context will fill respective values in the HashRef:
getinfo()
my $x = { content_type => 0, speed_download => 0, primary_ip => 0, }; $self->getinfo($x);
HashRef parameter will return another HashRef:
my $x = $self->getinfo({ content_type => 0, speed_download => 0, primary_ip => 0, });
ArrayRef parameter will return a list:
ArrayRef
my ($content_type, $speed_download, $primary_ip) = $self->getinfo([qw(content_type speed_download primary_ip)]);
Complete list of options: http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html
Internal. Required for Moo to operate properly on new parameters.
new
Moo
Net::Curl::Easy
Stanislaw Pusep <stas@sysd.org>
This software is copyright (c) 2021 by Stanislaw Pusep.
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 AnyEvent::Net::Curl::Queued, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Net::Curl::Queued
CPAN shell
perl -MCPAN -e shell install AnyEvent::Net::Curl::Queued
For more information on module installation, please visit the detailed CPAN module installation guide.