NAME

YADA - "Yet Another Download Accelerator": alias for AnyEvent::Net::Curl::Queued

VERSION

version 0.047

SYNOPSIS

#!/usr/bin/env perl
use common::sense;

use YADA;

YADA->new->append(
    [qw[
        http://www.cpan.org/modules/by-category/02_Language_Extensions/
        http://www.cpan.org/modules/by-category/02_Perl_Core_Modules/
        http://www.cpan.org/modules/by-category/03_Development_Support/
        ...
        http://www.cpan.org/modules/by-category/27_Pragma/
        http://www.cpan.org/modules/by-category/28_Perl6/
        http://www.cpan.org/modules/by-category/99_Not_In_Modulelist/
    ]] => sub {
        say $_[0]->final_url;
        say ${$_[0]->header};
    },
)->wait;

WARNING: GONE MOO!

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:

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';
...

DESCRIPTION

Use AnyEvent::Net::Curl::Queued with fewer keystrokes. Also, the easy things should be easy side of the package. For the hard things should be possible side, refer to the complete AnyEvent::Net::Curl::Queued documentation.

USAGE

The example in "SYNOPSIS" is equivalent to:

#!/usr/bin/env perl
use common::sense;

use AnyEvent::Net::Curl::Queued;
use AnyEvent::Net::Curl::Queued::Easy;

my $q = AnyEvent::Net::Curl::Queued->new;
$q->append(sub {
    AnyEvent::Net::Curl::Queued::Easy->new({
        initial_url => $_,
        on_finish   => sub {
            say $_[0]->final_url;
            say ${$_[0]->header};
        },
    })
}) for qw(
    http://www.cpan.org/modules/by-category/02_Language_Extensions/
    http://www.cpan.org/modules/by-category/02_Perl_Core_Modules/
    http://www.cpan.org/modules/by-category/03_Development_Support/
    ...
    http://www.cpan.org/modules/by-category/27_Pragma/
    http://www.cpan.org/modules/by-category/28_Perl6/
    http://www.cpan.org/modules/by-category/99_Not_In_Modulelist/
);
$q->wait;

As you see, YADA overloads append/prepend from AnyEvent::Net::Curl::Queued, adding implicit constructor for the worker object. It also makes both methods return a reference to the queue object, so (almost) everything gets chainable. The implicit constructor is triggered only when append/prepend receives multiple arguments. The order of arguments (mostly) doesn't matter. Their meaning is induced by their reference type:

Beware!

YADA tries to follow the principle of least astonishment, at least when you play nicely. All the following snippets have the same meaning:

$q->append(
    { retry => 3 },
    'http://www.cpan.org',
    'http://metacpan.org',
    sub { $_[0]->setopt(verbose => 1) }, # on_init placeholder
    \&on_finish,
);

$q->append(
    [qw[
        http://www.cpan.org
        http://metacpan.org
    ]],
    { retry => 3, opts => { verbose => 1 } },
    \&on_finish,
);

$q->append(
    URI->new($_) => \&on_finish,
    { retry => 3, opts => { verbose => 1 } },
) for qw[
    http://www.cpan.org
    http://metacpan.org
];

$q->append(
    [qw[
        http://www.cpan.org
        http://metacpan.org
    ]] => {
        retry       => 3,
        opts        => { verbose => 1 },
        on_finish   => \&on_finish,
    }
);

However, you will be astonished if you specify multiple distinct on_init and on_finish or try to sneak in initial_url through attributes! At least, RTFC if you seriously attempt to do that.

SEE ALSO

AUTHOR

Stanislaw Pusep <stas@sysd.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 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.