line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Works::Types; |
2
|
|
|
|
|
|
|
$Net::Works::Types::VERSION = '0.20'; |
3
|
4
|
|
|
4
|
|
15
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
114
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
83
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
13
|
use Carp qw( confess ); |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
154
|
|
7
|
4
|
|
|
4
|
|
16
|
use Exporter qw( import ); |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
78
|
|
8
|
4
|
|
|
4
|
|
15
|
use Scalar::Util (); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
83
|
|
9
|
4
|
|
|
4
|
|
2932
|
use Sub::Quote qw( quote_sub ); |
|
4
|
|
|
|
|
43407
|
|
|
4
|
|
|
|
|
1174
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
Int |
13
|
|
|
|
|
|
|
IPInt |
14
|
|
|
|
|
|
|
IPVersion |
15
|
|
|
|
|
|
|
PrefixLength |
16
|
|
|
|
|
|
|
NetWorksAddress |
17
|
|
|
|
|
|
|
PackedBinary |
18
|
|
|
|
|
|
|
Str |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
my $t = quote_sub( |
23
|
|
|
|
|
|
|
q{ |
24
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) |
25
|
|
|
|
|
|
|
or Net::Works::Types::_confess( |
26
|
|
|
|
|
|
|
'%s is not a valid integer for an IP address', |
27
|
|
|
|
|
|
|
$_[0] |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
4
|
0
|
28
|
sub Int () { $t } |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
my $t = quote_sub( |
37
|
|
|
|
|
|
|
q{ |
38
|
|
|
|
|
|
|
( |
39
|
|
|
|
|
|
|
defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) |
40
|
|
|
|
|
|
|
|| ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Math::UInt128') ) ) |
41
|
|
|
|
|
|
|
) |
42
|
|
|
|
|
|
|
or Net::Works::Types::_confess( |
43
|
|
|
|
|
|
|
'%s is not a valid integer for an IP address', |
44
|
|
|
|
|
|
|
defined $_[0] ? $_[0] : 'undef' |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
7
|
0
|
28
|
sub IPInt () { $t } |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
my $t = quote_sub( |
54
|
|
|
|
|
|
|
q{ |
55
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] && ( $_[0] == 4 || $_[0] == 6 ) ) |
56
|
|
|
|
|
|
|
or Net::Works::Types::_confess( |
57
|
|
|
|
|
|
|
'%s is not a valid IP version (4 or 6)', |
58
|
|
|
|
|
|
|
defined $_[0] ? $_[0] : 'undef' |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
4
|
0
|
12
|
sub IPVersion () { $t } |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
my $t = quote_sub( |
68
|
|
|
|
|
|
|
q{ |
69
|
|
|
|
|
|
|
( !ref $_[0] && defined $_[0] && $_[0] =~ /^[0-9]+\z/ && $_[0] <= 128 ) |
70
|
|
|
|
|
|
|
or Net::Works::Types::_confess( |
71
|
|
|
|
|
|
|
'%s is not a valid IP network prefix length (0-128)', |
72
|
|
|
|
|
|
|
defined $_[0] ? $_[0] : 'undef' |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
3
|
0
|
11
|
sub PrefixLength () { $t } |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
my $t = quote_sub( |
82
|
|
|
|
|
|
|
q{ |
83
|
|
|
|
|
|
|
( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Net::Works::Address') ) |
84
|
|
|
|
|
|
|
or Net::Works::Types::_confess( |
85
|
|
|
|
|
|
|
'%s is not a Net::Works::Address object', |
86
|
|
|
|
|
|
|
$_[0] |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
6
|
|
|
6
|
0
|
18
|
sub NetWorksAddress () { $t } |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
my $t = quote_sub( |
96
|
|
|
|
|
|
|
q{ |
97
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] ) |
98
|
|
|
|
|
|
|
or Net::Works::Types::_confess( '%s is not binary data', $_[0] ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
4
|
0
|
19
|
sub PackedBinary () { $t } |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
my $t = quote_sub( |
107
|
|
|
|
|
|
|
q{ |
108
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] ) |
109
|
|
|
|
|
|
|
or Net::Works::Types::_confess( '%s is not a string', $_[0] ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
7
|
|
|
7
|
0
|
31
|
sub Str () { $t } |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _confess { |
117
|
32
|
|
|
32
|
|
1009
|
local $Carp::Internal{__PACKAGE__} = 1; |
118
|
|
|
|
|
|
|
|
119
|
32
|
50
|
|
|
|
8681
|
confess sprintf( |
120
|
|
|
|
|
|
|
$_[0], |
121
|
|
|
|
|
|
|
defined $_[1] ? $_[1] : 'undef' |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |