Net/Prober.pm

filter: Statementstmt 90.7% 59 / 65 Branchbran 60.0% 6 / 10 Conditioncond 57.1% 8 / 14 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 85.7% 18 / 21 Podpod 20.0% 2 / 10 totaltotal 74.2% 95 / 128 CC 11 SCAR 11.1
CC
11
Cov
82%
probe
7.9
port_name_to_num
4.0
probe_any
3.1
CRAP 3.0
« Net/Prober/Probe/TCP.pm ↑ Summary Net/Prober/smtp.pm »
1 # ABSTRACT: Probes network hosts for downtime, latency, etc...
2  
3 package Net::Prober;
4 8 $Net::Prober::VERSION = '0.16';
5  
6 8 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use IO::Socket::INET ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use LWPx::ParanoidAgent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Net::Ping ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use Net::Prober::Probe::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub port_name_to_num {
22 21 ▶ my ($port) = @_;
Subroutine port_name_to_num: called CC=4 SCAR=13.9
Pod documented
23  
24 21 ▶ if (defined $port and $port ne "" and $port =~ m{^\D}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $port and $port ne "" and $port =~ /^\D/) 5 16 21
Condition83%5/6
defined $port and $port ne "" and $port =~ /^\D/
!ll&&!rl&&r
3135
defined $port and $port ne ""
!ll&&!rl&&r
3018
MC/DC66%2/3
defined $port and $port ne "" and $port =~ /^\D/
defined $port $port ne "" $port =~ /^\D/
Truth table75%3/4
A and B and C
A= defined $portB= $port ne ""C= $port =~ /^\D/
ABCresult
0XX0
10X0
1100
1111
25 5 $port = (getservbyname($port, "tcp"))[2];
26 }
27  
28 21 return $port;
29 }
30  
31 sub probe_any {
32 7 ▶ my ($class, $args) = @_;
Subroutine probe_any: called CC=3 SCAR=11.4
Pod undocumented
33 7 my $full_pkg = $class;
34  
35 # Open up for != Net::Prober::* classes
36 7 ▶ if ($full_pkg !~ m{::}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($full_pkg =~ /::/) 7 0 7
37 7 $full_pkg = "Net::Prober::${full_pkg}";
38 }
39  
40 7 ▶ eval "require $full_pkg; 1" or do {
Branch: 1 branch
BranchTrueFalseTotal
eval "require $full_pkg; 1" or do { Carp::croak("Couldn't load $full_pkg class: $@") } 0 7 7
41 0 Carp::croak("Couldn't load $full_pkg class: $@");
42 };
43  
44 7 my $p = $full_pkg->new();
45 7 return $p->probe($args);
46 }
47  
48 sub probe_icmp {
49 0 ▶ return probe_any('ping', @_);
Subroutine probe_icmp: not called CC=1 SCAR=6.9
Pod undocumented
50 }
51  
52 sub probe_ping {
53 0 ▶ return probe_any('ping', @_);
Subroutine probe_ping: not called CC=1 SCAR=6.9
Pod undocumented
54 }
55  
56 sub probe_imap {
57 0 ▶ return probe_any('imap', @_);
Subroutine probe_imap: not called CC=1 SCAR=6.9
Pod undocumented
58 }
59  
60 sub probe_ssh {
61 1 ▶ return probe_any('ssh', @_);
Subroutine probe_ssh: called CC=1 SCAR=0.0
Pod undocumented
62 }
63  
64 sub probe_smtp {
65 1 ▶ return probe_any('smtp', @_);
Subroutine probe_smtp: called CC=1 SCAR=0.0
Pod undocumented
66 }
67  
68 sub probe_http {
69 2 ▶ return probe_any('http', @_);
Subroutine probe_http: called CC=1 SCAR=0.0
Pod undocumented
70 }
71  
72 sub probe_tcp {
73 2 ▶ return probe_any('tcp', @_);
Subroutine probe_tcp: called CC=1 SCAR=0.0
Pod undocumented
74 }
75  
76  
77 sub probe {
78 1 ▶ my ($probe_type) = @_;
Subroutine probe: called CC=6 SCAR=20.7
Pod documented
79  
80 1 ▶ if (! $probe_type || ref $probe_type ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $probe_type or ref $probe_type ne "HASH") 0 1 1
Condition33%1/3
not $probe_type or ref $probe_type ne "HASH"
l!l&&r!l&&!r
001
MC/DC0%0/2
not $probe_type or ref $probe_type ne "HASH"
not $probe_type ref $probe_type ne "HASH"
Truth table33%1/3
not(A) or B
A= not $probe_typeB= ref $probe_type ne "HASH"
ABresult
1X1
011
000
81 0 Carp::croak("Invalid probe data");
82 }
83  
84 1 my $host = $probe_type->{host};
85 1 ▶ if (! defined $host or $host eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $host or $host eq "") 0 1 1
Condition33%1/3
not defined $host or $host eq ""
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $host or $host eq ""
not defined $host $host eq ""
Truth table33%1/3
not(A) or B
A= not defined $hostB= $host eq ""
ABresult
1X1
011
000
86 0 Carp::croak("Can't probe undefined host");
87 }
88  
89 1 my %probe_args = %{ $probe_type };
90 1 ▶ my $class = lc ($probe_args{class} || 'tcp');
Condition50%1/2
$probe_args{'class'} || 'tcp'
l!l
10
MC/DC0%0/1
$probe_args{'class'} || 'tcp'
$probe_args{'class'}
Truth table50%1/2
A
A= $probe_args{'class'}
Aresult
11
00
91  
92 # Resolve port names (http => 80)
93 1 $probe_args{port} = port_name_to_num($probe_args{port});
94  
95 1 my $result = probe_any($class, \%probe_args);
96  
97 1 return $result;
98 }
99  
100 8 1;
101  
102 __END__
« Net/Prober/Probe/TCP.pm ↑ Summary Net/Prober/smtp.pm »