line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Farly::IPv4::Address;
|
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
35918
|
use 5.008008;
|
|
19
|
|
|
|
|
67
|
|
|
19
|
|
|
|
|
721
|
|
4
|
19
|
|
|
19
|
|
97
|
use strict;
|
|
19
|
|
|
|
|
65
|
|
|
19
|
|
|
|
|
621
|
|
5
|
19
|
|
|
19
|
|
107
|
use warnings FATAL => 'all';
|
|
19
|
|
|
|
|
28
|
|
|
19
|
|
|
|
|
857
|
|
6
|
19
|
|
|
19
|
|
86
|
use Carp;
|
|
19
|
|
|
|
|
42
|
|
|
19
|
|
|
|
|
1576
|
|
7
|
19
|
|
|
19
|
|
10662
|
use Farly::IPv4::Object;
|
|
19
|
|
|
|
|
68
|
|
|
19
|
|
|
|
|
12339
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Farly::IPv4::Object);
|
10
|
|
|
|
|
|
|
our $VERSION = '0.26';
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new {
|
13
|
626
|
|
|
626
|
1
|
2078
|
my ( $class, $address ) = @_;
|
14
|
|
|
|
|
|
|
|
15
|
626
|
50
|
|
|
|
1696
|
confess "IP address required"
|
16
|
|
|
|
|
|
|
unless ( defined($address) );
|
17
|
|
|
|
|
|
|
|
18
|
626
|
50
|
|
|
|
1525
|
carp "invalid constructor arguments"
|
19
|
|
|
|
|
|
|
if ( scalar(@_) > 2 );
|
20
|
|
|
|
|
|
|
|
21
|
626
|
|
|
|
|
1305
|
$address =~ s/\s+//g;
|
22
|
|
|
|
|
|
|
|
23
|
626
|
100
|
|
|
|
3452
|
if ( $address =~ /^((\d{1,3})((\.)(\d{1,3})){3})$/ ) {
|
|
|
100
|
|
|
|
|
|
24
|
463
|
|
|
|
|
2946
|
$address = pack( "C4", split( /\./, $address ) );
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
elsif ( $address =~ /^\d+$/ ) {
|
27
|
161
|
|
|
|
|
529
|
$address = pack( "N", $address );
|
28
|
|
|
|
|
|
|
}
|
29
|
|
|
|
|
|
|
else {
|
30
|
2
|
|
|
|
|
451
|
confess "invalid address $address";
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
623
|
|
|
|
|
2281
|
my $ip = bless( \$address, $class );
|
34
|
|
|
|
|
|
|
|
35
|
623
|
50
|
33
|
|
|
1543
|
confess "invalid address $address"
|
36
|
|
|
|
|
|
|
unless ( $ip->address() >= 0 && $ip->address() <= 4294967295 );
|
37
|
|
|
|
|
|
|
|
38
|
623
|
|
|
|
|
2397
|
return $ip;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub address {
|
42
|
3704
|
|
|
3704
|
1
|
3608
|
return unpack( "N", ${ $_[0] } );
|
|
3704
|
|
|
|
|
15278
|
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub inverse {
|
46
|
251
|
|
|
251
|
1
|
483
|
return ~$_[0]->address() & 4294967295;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub first {
|
50
|
323
|
|
|
323
|
1
|
570
|
return $_[0]->address();
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub last {
|
54
|
171
|
|
|
171
|
1
|
305
|
return $_[0]->address();
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub start {
|
58
|
0
|
|
|
0
|
1
|
0
|
return Farly::IPv4::Address->new( $_[0]->address() );
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub end {
|
62
|
0
|
|
|
0
|
1
|
0
|
return Farly::IPv4::Address->new( $_[0]->address() );
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub dottedDecimalFormat {
|
66
|
433
|
|
|
433
|
1
|
586
|
return join( ".", unpack( 'C4', ${ $_[0] } ) );
|
|
433
|
|
|
|
|
3682
|
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub as_string {
|
70
|
433
|
|
|
433
|
1
|
2072
|
return $_[0]->dottedDecimalFormat();
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub iter {
|
74
|
1
|
|
|
1
|
1
|
5
|
my @iter = ( Farly::IPv4::Range->new( $_[0]->first(), $_[0]->last() ) );
|
75
|
1
|
|
|
|
|
4
|
return @iter;
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1;
|
79
|
|
|
|
|
|
|
__END__
|