line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyIp; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
511
|
use Net::TinyIp::Address; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
318
|
use overload q{""} => \&human_readable; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.08"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
1
|
|
|
1
|
|
1
|
my $class = shift; |
12
|
1
|
|
|
|
|
2
|
my @tags = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
33
|
foreach my $tag ( @tags ) { |
15
|
0
|
|
|
|
|
|
my $module = join q{::}, $class, "Util", join q{}, map { ucfirst } split m{_}, $tag; |
|
0
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
eval "require $module" |
17
|
|
|
|
|
|
|
or die; |
18
|
0
|
|
|
|
|
|
$module->import; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
24
|
0
|
|
|
|
|
|
my $address = shift; |
25
|
0
|
|
|
|
|
|
my %self; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my( $host, $cidr ) = split m{/}, $address; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
my $version = $host =~ m{[.]} ? 4 : $host =~ m{[:]} ? 6 : undef; |
|
|
0
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $module = join q{::}, $class, "Address", "v$version"; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
unless ( defined $cidr ) { |
33
|
0
|
|
|
|
|
|
$cidr = $module->get( "bits_length" ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self{host} = $module->from_string( $host ); |
37
|
0
|
|
|
|
|
|
$self{mask} = $module->from_cidr( $cidr ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return bless \%self, $class; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub network { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $network = $self->host & $self->mask; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $network; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub broadcast { |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my $neg = ( ref $self->mask ) |
52
|
|
|
|
|
|
|
->from_bin( "0b1" ) |
53
|
|
|
|
|
|
|
->blsft( $self->mask->get( "bits_length" ) ) |
54
|
|
|
|
|
|
|
->bsub( 1 ) |
55
|
|
|
|
|
|
|
->bxor( $self->mask ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return $self->network | $neg; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub host { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
64
|
0
|
|
|
|
|
|
$self->{host} = shift; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self->{host}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub mask { |
71
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
74
|
0
|
|
|
|
|
|
$self->{mask} = shift; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $self->{mask}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub human_readable { |
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return join q{/}, $self->host, $self->mask->cidr; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |