line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyIp::Address; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
4
|
use base "Math::BigInt"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5971
|
|
5
|
1
|
|
|
1
|
|
27804
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
6
|
1
|
|
|
1
|
|
659
|
use Net::TinyIp::Address::v4; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
16513
|
use Net::TinyIp::Address::v6; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
324
|
use overload q{""} => \&human_readable; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub from_bin { |
12
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
13
|
0
|
|
|
|
|
|
my $big_int = $class->SUPER::new( @_ ); |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
return bless $big_int, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub from_hex { |
19
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
20
|
0
|
|
|
|
|
|
my $big_int = $class->SUPER::new( @_ ); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
return bless $big_int, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub from_cidr { |
26
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
27
|
0
|
|
|
|
|
|
my $prefix = shift; |
28
|
0
|
|
|
|
|
|
my $length = $class->get( "bits_length" ); |
29
|
0
|
|
|
|
|
|
my $self = $class->from_bin( "0b1" ); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self = ( $self << $prefix ) - 1; |
32
|
0
|
|
|
|
|
|
$self = $self << ( $length - $prefix ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get { |
38
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
39
|
0
|
|
|
|
|
|
my $what = uc shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
$class = ref $class |
42
|
|
|
|
|
|
|
if ref $class; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
my $ret = do { |
45
|
1
|
|
|
1
|
|
268
|
no strict "refs"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
362
|
|
46
|
0
|
|
|
|
|
|
${ "${class}::$what" }; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
or croak "No $what exists."; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $ret; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
sub version { shift->get( "version" ) } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub cidr { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
( my $bin_str = $self->as_bin ) =~ s{\A 0b }{}msx; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
return 0 if length( $bin_str ) < $self->get( "bits_length" ); |
60
|
0
|
|
|
|
|
|
return length sprintf "%s", $bin_str =~ m{\A (1+) }msx; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub human_readable { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
0
|
|
|
|
my $format = shift || $self->get( "block_format" ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
( my $bin_str = $self->as_bin ) =~ s{\A 0b }{}msx; |
68
|
0
|
|
|
|
|
|
$bin_str = "0" x ( $self->get( "bits_length" ) - length $bin_str ) . $bin_str; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $bits_per_block = $self->get( "bits_per_block" ); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return join $self->get( "separator" ), map { sprintf $format, eval "0b$_" } ( $bin_str =~ m{ (\d{$bits_per_block}) }gmsx ); |
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |