-
Notifications
You must be signed in to change notification settings - Fork 0
/
tst_ae.pl
52 lines (45 loc) · 945 Bytes
/
tst_ae.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
#
use strict;
use feature ':5.10';
use utf8;
use open qw(:std :utf8);
use DDP;
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
use Time::HiRes qw(gettimeofday tv_interval);
use AnyEvent;
use AnyEvent::HTTP;
my $cv = AnyEvent->condvar;
$|++;
my @u = @ARGV;
unless (scalar @u) {
die RED "Give some URLs to my STDIN."
}
my $time_in = [ gettimeofday ];
my @r;
my $cnt = 0;
foreach my $url (@u) {
say "GET $url";
my $guard;
$guard = http_get($url,
sub {
undef $guard;
my ($body, $hdr) = @_;
$cnt++;
if ($hdr->{Status} =~ /^2/) {
print GREEN "$url: "
} else {
print RED "$url: "
}
say $hdr->{Status};
push @r => [$url, tv_interval($time_in)];
$cv->send() if $cnt==scalar @u
}
)
}
$cv->recv;
@r = sort { $b->[1] <=> $a->[1] } @r;
p(@r);
say GREEN "Yeah!";
exit;