perl-Combinator-0.004003-alt1.noarch.rpm


Advertisement

Description

perl-Combinator - Intuitively write async program serially, parallel, or circularly

Property Value
Distribution ALT Linux Sisyphus
Repository Autoimports noarch
Package name perl-Combinator
Package version 0.004003
Package release alt1
Package architecture noarch
Package type rpm
Installed size 18.55 KB
Download size 18.55 KB
Official Mirror ftp.altlinux.org
The following is the basic form for serializing a sequence of async code blocks:
use Combinator;
use AE;
my $cv = AE::cv;
{{com
print "sleep 1 second\n";
my $t = AE::timer 1, 0, {{next}};
--ser
undef $t;
my $t = AE::timer 0.5, 0, {{next}};
print "sleep 0.5 second\n"; # this line will be executed before the next block
--ser
undef $t;
print "wait for 3 timers at the same time\n";
my $t1 = AE::timer 1, 0, {{next}};
my $t2 = AE::timer 2, 0, {{next}};
my $t3 = AE::timer 1.5, 0, {{next}};
--ser
undef $t1; undef $t2; undef $t3;
print "the next block will start immediately\n";
--ser
print "done\n";
$cv->send;
}}com
$cv->recv;
The following block will wait for previous block's end and all the {{next}}s in the
previous block been called.
And also, it could be nested {{com..}}com blocks in the code block.
the following block will also wait for completion of these {{com..}}com blocks.
Thus, you can distribute independent code blocks into each one,
and optionally use 'return' to stop the {{com..}}com block.
use Combinator;
use AE;
my $cv = AE::cv;
{{com
print "all start\n";
{{com
print "A begin\n";
my $t = AE::timer 1, 0, {{next}};
--ser
undef $t;
print "A second\n";
my $t = AE::timer 1, 0, {{next}};
--ser
undef $t;
print "A done\n";
return; # this will stop the later part of this {{com..}}com block
--ser
print "never be here\n";
--ser
print "never be here either\n";
}}com
{{com
print "B begin\n";
my $t = AE::timer .7, 0, {{next}};
--ser
print "B second\n";
my $t = AE::timer .7, 0, {{next}};
--ser
print "B done\n";
--com # this is a short cut for }}com {{com
print "C begin\n";
my $t = AE::timer .4, 0, {{next}};
--ser
print "C second\n";
my $t = AE::timer .4, 0, {{next}};
--ser
print "C done\n";
}}com
--ser
print "all done\n";
$cv->send;
}}com
$cv->recv;
And also, the following block will get all the arguments when {{next}} is called.
This is useful when integrating with other callback based module.
use Combinator;
use AE;
use AnyEvent::HTTP;
my $cv = AE::cv;
{{com
print "start\n";
http_get "http://search.cpan.org/", {{next}};
--ser
my($data, $headers) = @_; # the cb args of http_get
if( !defined($data) ) {
print "Fetch cpan fail\n";
return;
}
print "Fetch cpan success\n";
http_get "http://www.perl.org/", {{next}};
--ser
my($data, $headers) = @_; # the cb args of http_get
if( !defined($data) ) {
print "Fetch perl fail\n";
return;
}
print "Fetch perl success\n";
print "done\n";
$cv->send;
}}com
$cv->recv;
If there are multiple {{next}}s been called,
You'll get all the args concatenated together.
use Combinator;
use AE;
my $cv = AE::cv;
{{com
{{next}}->(0);
{{com
my $t = AE::timer 1, 0, {{next}};
--ser
undef $t;
{{next}}->(1);
--com
my $t = AE::timer .6, 0, {{next}};
--ser
undef $t;
{{next}}->(2);
--com
my $t = AE::timer .3, 0, {{next}};
--ser
undef $t;
{{next}}->(3);
}}com
{{next}}->(4);
--ser
print "@_\n"; # 0 4 3 2 1
$cv->send;
}}com
If you want to process each {{next}}'s args seperately,
you might use seperate {{com..}}com, and then gather the final result.
use Combinator;
use AnyEvent::HTTP;
use Data::Dumper;
my $cv = AE::cv;
{{com
my @health;
for my $url (qw(http://www.perl.org/ http://search.cpan.org/)) {{com
my $url = $url; # we need to copy-out the $url here,
http_get $url, {{next}};
--ser
push @health, [$url, defined($_[0])];
}}com
--ser
print Dumper(\@health);
$cv->send;
}}com
If you wish to run a {{com..}}com repeatly. Use {{cir instead of {{com,
or use --cir instead of --com if it's not the first block.
use Combinator;
use AE;
use AnyEvent::Socket;
use AnyEvent::Handle;
tcp_server 0, 8888, sub {
my($fh, $host, $port) = @_;
my $hd; $hd = AnyEvent::Handle->new(
fh => $fh,
on_error => sub {
print "socket $host:$port end.\n";
undef $hd;
},
);
{{cir
$hd->push_read( line => {{next}} );
--ser
my($hd, $line) = @_;
$hd->push_write($line.$/);
}}com
};
AE::cv->recv;
If you need finer controlled {{next}}, use {{nex .. }}nex block to
replace {{next}}.
use Combinator;
use AE;
use AnyEvent::HTTP;
{{com
my($a_res, $b_res);
http_get 'http://site.a/', {{nex $a_res = $_[1] }}nex;
http_get 'http://site.b/', {{nex $b_res = $_[1] }}nex;
--ser
print "Completed!\n";
print "SiteA = $a_res\n";
print "SiteB = $b_res\n";
}}com
AE::cv->recv;
Though without {{nex .. }}nex block, you can still write:
use Combinator;
use AE;
use AnyEvent::HTTP;
{{com
my($a_res, $b_res);
{{com
http_get 'http://site.a/', {{next}};
--ser
$a_res = $_[1];
--com
http_get 'http://site.b/', {{next}};
--ser
$b_res = $_[1];
}}com
--ser
print "Completed!\n";
print "SiteA = $a_res\n";
print "SiteB = $b_res\n";
}}com
AE::cv->recv;
It's up to you to choose which one to use.

Alternatives

Package Version Architecture Repository
perl-Combinator - - -

Requires

Name Value
/usr/share/perl5 -
perl(Devel/Caller.pm) -
perl(Filter/Simple.pm) -
perl(Guard.pm) -
perl-base >= 1:5.10.0
rpmlib(PayloadIsLzma) -

Provides

Name Value
perl(Combinator.pm) = 0.004.003
perl-Combinator = 0.004003-alt1

Download

Type URL
Binary Package perl-Combinator-0.004003-alt1.noarch.rpm
Source Package perl-Combinator-0.004003-alt1.src.rpm

Install Howto

  1. Add the following line to /etc/apt/sources.list:
    
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    
  2. Update the package index:
    # sudo apt-get update
  3. Install perl-Combinator rpm package:
    # sudo apt-get install perl-Combinator

Files

Path
/usr/share/doc/perl-Combinator-0.004003/Changes
/usr/share/doc/perl-Combinator-0.004003/README
/usr/share/perl5/Combinator.pm

See Also

Package Description
perl-Comics-1.09-alt1.noarch.rpm Comics aggregator in the style of Gotblah
perl-Comics-scripts-1.09-alt1.noarch.rpm Comics scripts
perl-Command-Do-0.120011-alt1.noarch.rpm Simple Command-Line Interfaces
perl-Command-Interactive-1.4-alt1.noarch.rpm handles interactive (and non-interactive) process invocation
perl-Command-Runner-0.002-alt1.noarch.rpm run external commands and Perl code refs
perl-Commandable-0.02-alt1.noarch.rpm utilities for commandline-based programs
perl-Commands-Guarded-1.01-alt1.noarch.rpm Better scripts through guarded commands
perl-Comment-Block-0.01-alt1.noarch.rpm Comment::Block - Makes Block Comments Possible
perl-Comment-Spell-0.001002-alt1.noarch.rpm Spell Checking for your comments
perl-Comment-Spell-Check-0.002001-alt1.noarch.rpm Check words from Comment::Spell vs a system spell checker
perl-Common-CLI-0.04-alt1.noarch.rpm perl module Common-CLI
perl-Common-Routine-0.0.5-alt1.noarch.rpm Provide and synthesize very commonly used routines that are not provided in perl's build-in routine
perl-Comodo-DCV-0.04-alt1.noarch.rpm DCV logic for COMODO SSL APIs
perl-Compare-Directory-1.25-alt1.noarch.rpm Interface to compare directories
perl-Compass-Bearing-0.07-alt1.noarch.rpm Convert angle to text bearing (aka heading)
Advertisement
Advertisement