line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MaxMind::DB::Types; |
2
|
|
|
|
|
|
|
$MaxMind::DB::Types::VERSION = '0.031003'; |
3
|
2
|
|
|
2
|
|
16
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
248
|
use Carp qw( confess ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
229
|
|
7
|
2
|
|
|
2
|
|
29
|
use Exporter qw( import ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
101
|
|
8
|
2
|
|
|
2
|
|
2444
|
use List::AllUtils; |
|
2
|
|
|
|
|
15764
|
|
|
2
|
|
|
|
|
265
|
|
9
|
2
|
|
|
2
|
|
20
|
use Scalar::Util (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
10
|
2
|
|
|
2
|
|
9118
|
use Sub::Quote qw( quote_sub ); |
|
2
|
|
|
|
|
9170
|
|
|
2
|
|
|
|
|
2143
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
ArrayRefOfStr |
14
|
|
|
|
|
|
|
Bool |
15
|
|
|
|
|
|
|
Decoder |
16
|
|
|
|
|
|
|
Epoch |
17
|
|
|
|
|
|
|
FileHandle |
18
|
|
|
|
|
|
|
HashRef |
19
|
|
|
|
|
|
|
HashRefOfStr |
20
|
|
|
|
|
|
|
Int |
21
|
|
|
|
|
|
|
MathUUInt128 |
22
|
|
|
|
|
|
|
Metadata |
23
|
|
|
|
|
|
|
Str |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
my $t = quote_sub( |
28
|
|
|
|
|
|
|
q{ |
29
|
|
|
|
|
|
|
( |
30
|
|
|
|
|
|
|
defined $_[0] |
31
|
|
|
|
|
|
|
&& Scalar::Util::reftype( $_[0] ) eq 'ARRAY' |
32
|
|
|
|
|
|
|
&& List::AllUtils::all( |
33
|
|
|
|
|
|
|
sub { defined $_ && !ref $_ }, |
34
|
|
|
|
|
|
|
@{ $_[0] } |
35
|
|
|
|
|
|
|
) |
36
|
|
|
|
|
|
|
) |
37
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
38
|
|
|
|
|
|
|
'%s is not an arrayref', |
39
|
|
|
|
|
|
|
$_[0] |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
2
|
0
|
19
|
sub ArrayRefOfStr () { $t } |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
my $t = quote_sub( |
49
|
|
|
|
|
|
|
q{ |
50
|
|
|
|
|
|
|
( !defined $_[0] || $_[0] eq q{} || "$_[0]" eq '1' || "$_[0]" eq '0' ) |
51
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
52
|
|
|
|
|
|
|
'%s is not a boolean', |
53
|
|
|
|
|
|
|
$_[0] |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
0
|
0
|
sub Bool () { $t } |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
my $t = _object_isa_type('MaxMind::DB::Reader::Decoder'); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
0
|
sub Decoder () { $t } |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
my $t = quote_sub( |
69
|
|
|
|
|
|
|
q{ |
70
|
|
|
|
|
|
|
( |
71
|
|
|
|
|
|
|
defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+$/ ) |
72
|
|
|
|
|
|
|
|| ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Math::UInt128') ) ) |
73
|
|
|
|
|
|
|
) |
74
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
75
|
|
|
|
|
|
|
'%s is not an integer or a Math::UInt128 object', |
76
|
|
|
|
|
|
|
$_[0] |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
2
|
0
|
11
|
sub Epoch () { $t } |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
my $t = quote_sub( |
86
|
|
|
|
|
|
|
q{ |
87
|
|
|
|
|
|
|
( ( defined $_[0] && Scalar::Util::openhandle( $_[0] ) ) |
88
|
|
|
|
|
|
|
|| ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('IO::Handle') ) ) |
89
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
90
|
|
|
|
|
|
|
'%s is not a file handle', |
91
|
|
|
|
|
|
|
$_[0] |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
0
|
0
|
sub FileHandle () { $t } |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
my $t = quote_sub( |
101
|
|
|
|
|
|
|
q{ |
102
|
|
|
|
|
|
|
( defined $_[0] && Scalar::Util::reftype( $_[0] ) eq 'HASH' ) |
103
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
104
|
|
|
|
|
|
|
'%s is not a hashref', |
105
|
|
|
|
|
|
|
$_[0] |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
0
|
0
|
sub HashRef () { $t } |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
my $t = quote_sub( |
115
|
|
|
|
|
|
|
q{ |
116
|
|
|
|
|
|
|
( |
117
|
|
|
|
|
|
|
defined $_[0] |
118
|
|
|
|
|
|
|
&& Scalar::Util::reftype( $_[0] ) eq 'HASH' |
119
|
|
|
|
|
|
|
&& &List::AllUtils::all( |
120
|
|
|
|
|
|
|
sub { defined $_ && !ref $_ }, values %{ $_[0] } |
121
|
|
|
|
|
|
|
) |
122
|
|
|
|
|
|
|
) |
123
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
124
|
|
|
|
|
|
|
'%s is not a hashref of strings', |
125
|
|
|
|
|
|
|
$_[0] |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
2
|
|
|
2
|
0
|
8
|
sub HashRefOfStr () { $t } |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
my $t = quote_sub( |
135
|
|
|
|
|
|
|
q{ |
136
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+$/ ) |
137
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
138
|
|
|
|
|
|
|
'%s is not a valid integer', |
139
|
|
|
|
|
|
|
$_[0] |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
10
|
|
|
10
|
0
|
47
|
sub Int () { $t } |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
{ |
148
|
|
|
|
|
|
|
my $t = quote_sub( |
149
|
|
|
|
|
|
|
q{ |
150
|
|
|
|
|
|
|
( |
151
|
|
|
|
|
|
|
defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+$/ ) |
152
|
|
|
|
|
|
|
|| ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Math::UUInt128') ) ) |
153
|
|
|
|
|
|
|
) |
154
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
155
|
|
|
|
|
|
|
'%s is not a valid integer for an IP address', |
156
|
|
|
|
|
|
|
$_[0] |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
0
|
0
|
0
|
sub IPInt () { $t } |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
my $t = quote_sub( |
166
|
|
|
|
|
|
|
q{ |
167
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] && ( $_[0] == 4 || $_[0] == 6 ) ) |
168
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
169
|
|
|
|
|
|
|
'%s is not a valid IP version (4 or 6)', |
170
|
|
|
|
|
|
|
$_[0] |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
0
|
0
|
0
|
sub IPVersion () { $t } |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
{ |
179
|
|
|
|
|
|
|
my $t = quote_sub( |
180
|
|
|
|
|
|
|
q{ |
181
|
|
|
|
|
|
|
( !ref $_[0] && $_[0] >= 0 && $_[0] <= 128 ) |
182
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
183
|
|
|
|
|
|
|
'%s is not a valid IP network mask length (0-128)', $_[0] ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
0
|
0
|
0
|
sub MaskLength () { $t } |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
{ |
191
|
|
|
|
|
|
|
my $t = _object_isa_type('Math::UInt128'); |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
0
|
0
|
0
|
sub MathUInt128 () { $t } |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
{ |
197
|
|
|
|
|
|
|
my $t = _object_isa_type('MaxMind::DB::Metadata'); |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
0
|
0
|
0
|
sub Metadata () { $t } |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
{ |
203
|
|
|
|
|
|
|
my $t = quote_sub( |
204
|
|
|
|
|
|
|
q{ |
205
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] ) |
206
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( '%s is not binary data', $_[0] ); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
); |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
0
|
0
|
0
|
sub PackedBinary () { $t } |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
{ |
214
|
|
|
|
|
|
|
my $t = quote_sub( |
215
|
|
|
|
|
|
|
q{ |
216
|
|
|
|
|
|
|
( defined $_[0] && !ref $_[0] ) |
217
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( '%s is not a string', $_[0] ); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
); |
220
|
|
|
|
|
|
|
|
221
|
2
|
|
|
2
|
0
|
9
|
sub Str () { $t } |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub _object_isa_type { |
225
|
6
|
|
|
6
|
|
10
|
my $class = shift; |
226
|
|
|
|
|
|
|
|
227
|
6
|
|
|
|
|
1416
|
return quote_sub( |
228
|
|
|
|
|
|
|
qq{ |
229
|
|
|
|
|
|
|
( Scalar::Util::blessed( \$_[0] ) && \$_[0]->isa('$class') ) |
230
|
|
|
|
|
|
|
or MaxMind::DB::Types::_confess( |
231
|
|
|
|
|
|
|
'%s is not a $class object', |
232
|
|
|
|
|
|
|
\$_[0] |
233
|
|
|
|
|
|
|
); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub _confess { |
239
|
0
|
0
|
|
0
|
|
|
confess sprintf( |
240
|
|
|
|
|
|
|
$_[0], |
241
|
|
|
|
|
|
|
defined $_[1] ? overload::StrVal( $_[1] ) : 'undef' |
242
|
|
|
|
|
|
|
); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
1; |