Net/Prober.pm

filter: Statementstmt 75.3% 49 / 65 Branchbran 40.0% 4 / 10 Conditioncond 35.7% 5 / 14 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 80.9% 17 / 21 Podpod 20.0% 2 / 10 totaltotal 61.7% 79 / 128 CC 11 SCAR 22.6
CC
11
Cov
65%
probe
42.0
port_name_to_num
4.0
probe_any
3.1
CRAP 9.6
« Net/Prober/ping.pm ↑ Summary Test/Net/Prober/HTTPServer.pm »
1 # ABSTRACT: Probes network hosts for downtime, latency, etc...
2  
3 package Net::Prober;
4 8 $Net::Prober::VERSION = '0.17';
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 20 ▶sub port_name_to_num {
Subroutine port_name_to_num: called CC=4 SCAR=13.9
Pod documented
22 20 my ($port) = @_;
23  
24 20 ▶ if (defined $port and $port ne "" and $port =~ m{^\D}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $port and $port ne "" and $port =~ /^\D/) 5 15 20
Condition83%5/6
defined $port and $port ne "" and $port =~ /^\D/
!ll&&!rl&&r
2135
defined $port and $port ne ""
!ll&&!rl&&r
2018
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 20 return $port;
29 }
30  
31 6 ▶sub probe_any {
Subroutine probe_any: called CC=3 SCAR=11.4
Pod undocumented
32 6 my ($class, $args) = @_;
33 6 my $full_pkg = $class;
34  
35 # Open up for != Net::Prober::* classes
36 6 ▶ if ($full_pkg !~ m{::}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($full_pkg =~ /::/) 6 0 6
37 6 $full_pkg = "Net::Prober::${full_pkg}";
38 }
39  
40 6 ▶ 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: $@") } 6 0 6
41 0 Carp::croak("Couldn't load $full_pkg class: $@");
42 };
43  
44 6 my $p = $full_pkg->new();
45 6 return $p->probe($args);
46 }
47  
48 0 ▶sub probe_icmp {
Subroutine probe_icmp: not called CC=1 SCAR=6.9
Pod undocumented
49 0 return probe_any('ping', @_);
50 }
51  
52 0 ▶sub probe_ping {
Subroutine probe_ping: not called CC=1 SCAR=6.9
Pod undocumented
53 0 return probe_any('ping', @_);
54 }
55  
56 0 ▶sub probe_imap {
Subroutine probe_imap: not called CC=1 SCAR=6.9
Pod undocumented
57 0 return probe_any('imap', @_);
58 }
59  
60 1 ▶sub probe_ssh {
Subroutine probe_ssh: called CC=1 SCAR=0.0
Pod undocumented
61 1 return probe_any('ssh', @_);
62 }
63  
64 1 ▶sub probe_smtp {
Subroutine probe_smtp: called CC=1 SCAR=0.0
Pod undocumented
65 1 return probe_any('smtp', @_);
66 }
67  
68 2 ▶sub probe_http {
Subroutine probe_http: called CC=1 SCAR=0.0
Pod undocumented
69 2 return probe_any('http', @_);
70 }
71  
72 2 ▶sub probe_tcp {
Subroutine probe_tcp: called CC=1 SCAR=0.0
Pod undocumented
73 2 return probe_any('tcp', @_);
74 }
75  
76  
77 0 ▶sub probe {
Subroutine probe: not called CC=6 SCAR=37.4
Pod documented
78 0 my ($probe_type) = @_;
79  
80 0 ▶ if (! $probe_type || ref $probe_type ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $probe_type or ref $probe_type ne "HASH") 0 0 0
Condition0%0/3
not $probe_type or ref $probe_type ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $probe_type or ref $probe_type ne "HASH"
not $probe_type ref $probe_type ne "HASH"
Truth table0%0/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 0 my $host = $probe_type->{host};
85 0 ▶ if (! defined $host or $host eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $host or $host eq "") 0 0 0
Condition0%0/3
not defined $host or $host eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $host or $host eq ""
not defined $host $host eq ""
Truth table0%0/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 0 my %probe_args = %{ $probe_type };
90 0 ▶ my $class = lc ($probe_args{class} || 'tcp');
Condition0%0/2
$probe_args{'class'} || 'tcp'
l!l
00
MC/DC0%0/1
$probe_args{'class'} || 'tcp'
$probe_args{'class'}
Truth table0%0/2
A
A= $probe_args{'class'}
Aresult
11
00
91  
92 # Resolve port names (http => 80)
93 0 $probe_args{port} = port_name_to_num($probe_args{port});
94  
95 0 my $result = probe_any($class, \%probe_args);
96  
97 0 return $result;
98 }
99  
100 8 1;
101  
102 __END__
« Net/Prober/ping.pm ↑ Summary Test/Net/Prober/HTTPServer.pm »