| 1 | package Net::Peep::Host; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 13 | require 5.00503; | |||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | # use warnings; # commented out for 5.005 compatibility | ||||||||||||||||||||
| 6 | 13 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 13 | ▶ | use Socket; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 13 | require Exporter; | |||||||||||||||||||
| 9 | 13 | ▶ | use Net::Peep::Log; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 13 | ▶ | use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD @Attributes $LOGGER }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 13 | @ISA = qw(Exporter); | |||||||||||||||||||
| 14 | 13 | %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); | |||||||||||||||||||
| 15 | 13 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 16 | 13 | @EXPORT = qw( ); | |||||||||||||||||||
| 17 | 13 | $VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 13 | $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 | |||||||||||||||||||||
| 28 | } # end sub new | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | sub name { | ||||||||||||||||||
|
Subroutine
name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | # if the host name has been explicitly set, retrieve the set value | ||||||||||||||||||||
| 33 | # ... if not obtain the value by gethostbyaddr | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||
| 36 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 0 | $self->{'NAME'} = shift; | |||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||
| 39 | 0 | ▶ | if (exists $self->{'NAME'}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 40 | 0 | return $self->{'NAME'}; | |||||||||||||||||||
| 41 | } elsif (exists $self->{'IP'}) { | ||||||||||||||||||||
| 42 | 0 | my $iaddr = inet_aton($self->{'IP'}); | |||||||||||||||||||
| 43 | 0 | my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyaddr($iaddr,AF_INET); | |||||||||||||||||||
| 44 | 0 | ▶ | return $name ? $name : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||
| 46 | 0 | confess "Cannot obtain host name: No host name or IP address has been specified."; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | } # end sub name | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub ip { | ||||||||||||||||||
|
Subroutine
ip: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # if the host IP address has been explicitly set, retrieve the set | ||||||||||||||||||||
| 55 | # value ... if not obtain the value by gethostbyname | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||
| 58 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | $self->{'IP'} = shift; | |||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||
| 61 | 0 | ▶ | if (exists $self->{'IP'}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 62 | 0 | return $self->{'IP'}; | |||||||||||||||||||
| 63 | } elsif (exists $self->{'NAME'}) { | ||||||||||||||||||||
| 64 | 0 | my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($self->{'NAME'}); | |||||||||||||||||||
| 65 | 0 | ▶ | if (@addrs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | my $ip = inet_ntoa($addrs[0]); | |||||||||||||||||||
| 67 | 0 | ▶ | return $ip ? $ip : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||
| 69 | 0 | confess "Cannot obtain IP address: Could not get host by name for ".$self->{'NAME'}."."; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||
| 72 | 0 | confess "Cannot obtain IP address: No host name or IP address has been specified."; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | } # end sub ip | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | sub isIP { | ||||||||||||||||||
|
Subroutine
isIP: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||
| 81 | 0 | ▶ | my $ip = shift || confess "Hostname or IP address not found."; | ||||||||||||||||||
|
Condition0%0/2
shift() || confess('Hostname or IP address not found.')
MC/DC0%0/1
shift() || confess('Hostname or IP address not found.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | return $ip =~ /^(\d+\.)+\d+$/ ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | } # end sub isIP | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 13 | 1; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||