| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 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.')
MC/DC0%0/1
shift() || confess('Cannot add host to host pool: Host not found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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.')
MC/DC0%0/1
shift() || confess('Cannot get host by name: No name found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$host->name eq $name or $host->name eq "localhost"
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"
| |||||||||||||||||||||||||||||
| 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.')
MC/DC0%0/1
shift() || confess('Cannot get host by IP address: No address found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$host->ip eq $addr or $host->ip eq "127.0.0.1"
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"
| |||||||||||||||||||||||||||||
| 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.')
MC/DC0%0/1
shift() || confess('Cannot add hosts: No hosts found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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.')
MC/DC0%0/1
shift() || confess('Cannot check whether host is in pool: No host found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 125 | 0 | $got = $self->getHostByAddr($nameOrIp); | |||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | 0 | $got = $self->getHostByName($nameOrIp); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $return++ if $got; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | return $return; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | } # end areInHostPool | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 10 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||