lib/App/MadEye/Plugin/Agent/Perlbal.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 41 CC 2 SCAR 12.0
CC
2
Cov
0%
is_dead
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package App::MadEye::Plugin::Agent::Perlbal;
2 use strict;
3 use warnings;
4 use IO::Socket::INET;
5 use App::MadEye::Plugin::Agent::Base;
6  
7 my $req = <<'...';
8 GET / HTTP/1.0
9 Host: invalidhostname.example.com
10  
11 ...
12  
13 sub is_dead {
14 my ($self, $host) = @_;
15  
16 my $conf = $self->config->{config};
17 my $port = $conf->{port} || 80;
18 my $timeout = $conf->{timeout} || 10;
19  
20 my $sock = IO::Socket::INET->new(
21 PeerAddr => $host,
22 PeerPort => $port,
23 Timeout => $timeout,
24 ) or return "cannot open socket";
25 $sock->write($req);
26  
27 my $content = join '', <$sock>;
28 if ($content =~ m{Server: Perlbal.+<h1>404 - Not Found</h1>}s) {
29 return; # alive.
30 } else {
31 return "this is not a perlbal?\n\n$content";
32 }
33 }
34  
35 1;
36 __END__