blib/lib/Net/Peep/Host/Pool.pm

filter: Statementstmt 32.5% 27 / 83 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 38.4% 5 / 13 Podpod 0.0% 0 / 8 totaltotal 21.3% 32 / 150 CC 21 SCAR 28.7
CC
21
Cov
23%
getHostByName
30.0
getHostByAddr
30.0
addHosts
20.0
CRAP 17.6
« blib/lib/Net/Peep/Host.pm ↑ Summary blib/lib/Net/Peep/BC.pm »
1 package Net::Peep::Host::Pool;
2  
3 10 require 5.00503;
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # use warnings; # commented out for 5.005 compatibility
6 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 require Exporter;
9 10 ▶use Net::Peep::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD @Attributes $LOGGER };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 10 @ISA = qw(Exporter);
14 10 %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
15 10 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
16 10 @EXPORT = qw( );
17 10 $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
18  
19 10 $LOGGER = new Net::Peep::Log;
20  
21 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
22  
23 0 my $self = shift;
24 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
25 0 my $this = {};
26 0 bless $this, $class;
27 0 $this->{'HOSTS'} = [];
28 0 $this;
29  
30 } # end sub new
31  
32 0 ▶sub addHost {
Subroutine addHost: not called CC=2 SCAR=17.9
Pod undocumented
33  
34 0 my $self = shift;
35 0 ▶ my $host = shift || confess "Cannot add host to host pool: Host not found.";
Condition0%0/2
shift() || confess('Cannot add host to host pool: Host not found.')
l!l
00
MC/DC0%0/1
shift() || confess('Cannot add host to host pool: Host not found.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
36 0 push @{$self->{'HOSTS'}}, $host;
37 0 return 1;
38  
39 } # end sub addHost
40  
41 0 ▶sub hosts {
Subroutine hosts: not called CC=2 SCAR=17.9
Pod undocumented
42  
43 0 my $self = shift;
44  
45 0 ▶ return wantarray ? @{$self->{'HOSTS'}} : $self->{'HOSTS'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
46  
47 } # end sub hosts
48  
49 0 ▶sub getHostByName {
Subroutine getHostByName: not called CC=5 SCAR=34.0
Pod undocumented
50  
51 0 my $self = shift;
52 0 ▶ my $name = shift || confess "Cannot get host by name: No name found.";
Condition0%0/2
shift() || confess('Cannot get host by name: No name found.')
l!l
00
MC/DC0%0/1
shift() || confess('Cannot get host by name: No name found.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
53  
54 0 my $return = undef;
55 0 for my $host ($self->hosts()) {
56 0 ▶ $return = $host if $host->name() eq $name or $host->name() eq 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
if $host->name eq $name or $host->name eq "localhost" 0 0 0
Condition0%0/3
$host->name eq $name or $host->name eq "localhost"
l!l&&r!l&&!r
000
MC/DC0%0/2
$host->name eq $name or $host->name eq "localhost"
$host->name eq $name $host->name eq "localhost"
Truth table0%0/3
A or B
A= $host->name eq $nameB= $host->name eq "localhost"
ABresult
1X1
011
000
57 }
58 0 return $return;
59  
60 } # end sub getHostByName
61  
62 0 ▶sub getHostByAddr {
Subroutine getHostByAddr: not called CC=5 SCAR=34.0
Pod undocumented
63  
64 0 my $self = shift;
65 0 ▶ my $addr = shift || confess "Cannot get host by IP address: No address found.";
Condition0%0/2
shift() || confess('Cannot get host by IP address: No address found.')
l!l
00
MC/DC0%0/1
shift() || confess('Cannot get host by IP address: No address found.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
66  
67 0 my $return = undef;
68 0 for my $host ($self->hosts()) {
69 0 ▶ $return = $host if $host->ip() eq $addr or $host->ip() eq '127.0.0.1';
Branch: 1 branch
BranchTrueFalseTotal
if $host->ip eq $addr or $host->ip eq "127.0.0.1" 0 0 0
Condition0%0/3
$host->ip eq $addr or $host->ip eq "127.0.0.1"
l!l&&r!l&&!r
000
MC/DC0%0/2
$host->ip eq $addr or $host->ip eq "127.0.0.1"
$host->ip eq $addr $host->ip eq "127.0.0.1"
Truth table0%0/3
A or B
A= $host->ip eq $addrB= $host->ip eq "127.0.0.1"
ABresult
1X1
011
000
70 }
71 0 return $return;
72  
73 } # end sub getHostByName
74  
75 0 ▶sub addHosts {
Subroutine addHosts: not called CC=4 SCAR=30.0
Pod undocumented
76  
77 0 my $self = shift;
78 0 ▶ my $hosts = shift || confess "Cannot add hosts: No hosts found.";
Condition0%0/2
shift() || confess('Cannot add hosts: No hosts found.')
l!l
00
MC/DC0%0/1
shift() || confess('Cannot add hosts: No hosts found.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
79  
80 0 my @hosts = split /\s*,\s*/, $hosts;
81 0 for my $id (@hosts) {
82 0 my $host = new Net::Peep::Host;
83 0 ▶ if ($host->isIP($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host->isIP($id)) { } 0 0 0
84 0 $host->ip($id);
85 } else {
86 0 $host->name($id);
87 }
88 0 $self->addHost($host);
89 }
90 0 return 1;
91  
92 } # end sub addHosts
93  
94 0 ▶sub isInHostPool {
Subroutine isInHostPool: not called CC=4 SCAR=30.0
Pod undocumented
95  
96 0 my $self = shift;
97 0 ▶ my $nameOrIp = shift || confess "Cannot check whether host is in pool: No host found.";
Condition0%0/2
shift() || confess('Cannot check whether host is in pool: No host found.')
l!l
00
MC/DC0%0/1
shift() || confess('Cannot check whether host is in pool: No host found.')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
98  
99 0 my @hosts = $self->hosts();
100  
101 0 my $host = new Net::Peep::Host;
102  
103 0 my $got;
104 0 ▶ if ($host->isIP($nameOrIp)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host->isIP($nameOrIp)) { } 0 0 0
105 0 $got = $self->getHostByAddr($nameOrIp);
106 } else {
107 0 $got = $self->getHostByName($nameOrIp);
108 }
109  
110 0 ▶ return $got ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$got ? : 0 0 0
111  
112 } # end sub isInHostPool
113  
114 0 ▶sub areInHostPool {
Subroutine areInHostPool: not called CC=4 SCAR=30.0
Pod undocumented
115  
116 0 my $self = shift;
117 0 my @hosts = @_;
118  
119 0 my $host = new Net::Peep::Host;
120  
121 0 my $return = 0;
122 0 for my $nameOrIp (@hosts) {
123 0 my $got;
124 0 ▶ if ($self->isIP($nameOrIp)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isIP($nameOrIp)) { } 0 0 0
125 0 $got = $self->getHostByAddr($nameOrIp);
126 } else {
127 0 $got = $self->getHostByName($nameOrIp);
128 }
129 0 ▶ $return++ if $got;
Branch: 1 branch
BranchTrueFalseTotal
if $got 0 0 0
130 }
131  
132 0 return $return;
133  
134 } # end areInHostPool
135  
136 10 1;
137  
138 __END__
« blib/lib/Net/Peep/Host.pm ↑ Summary blib/lib/Net/Peep/BC.pm »