| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MaxMind::DB::Reader::Role::HasMetadata; |
|
2
|
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
12595
|
use strict; |
|
|
21
|
|
|
|
|
64
|
|
|
|
21
|
|
|
|
|
685
|
|
|
4
|
21
|
|
|
21
|
|
127
|
use warnings; |
|
|
21
|
|
|
|
|
449
|
|
|
|
21
|
|
|
|
|
628
|
|
|
5
|
21
|
|
|
21
|
|
130
|
use namespace::autoclean; |
|
|
21
|
|
|
|
|
45
|
|
|
|
21
|
|
|
|
|
136
|
|
|
6
|
21
|
|
|
21
|
|
1689
|
use autodie; |
|
|
21
|
|
|
|
|
75
|
|
|
|
21
|
|
|
|
|
132
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require bytes; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.000014'; |
|
11
|
21
|
|
|
21
|
|
114990
|
use Carp qw( confess ); |
|
|
21
|
|
|
|
|
50
|
|
|
|
21
|
|
|
|
|
1509
|
|
|
12
|
21
|
|
|
21
|
|
156
|
use List::AllUtils qw( min ); |
|
|
21
|
|
|
|
|
56
|
|
|
|
21
|
|
|
|
|
1751
|
|
|
13
|
21
|
|
|
21
|
|
3121
|
use MaxMind::DB::Reader::Decoder; |
|
|
21
|
|
|
|
|
60
|
|
|
|
21
|
|
|
|
|
712
|
|
|
14
|
21
|
|
|
21
|
|
10178
|
use MaxMind::DB::Metadata; |
|
|
21
|
|
|
|
|
156634
|
|
|
|
21
|
|
|
|
|
823
|
|
|
15
|
21
|
|
|
21
|
|
163
|
use MaxMind::DB::Types qw( Int Metadata ); |
|
|
21
|
|
|
|
|
51
|
|
|
|
21
|
|
|
|
|
1136
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
21
|
|
|
21
|
|
139
|
use Moo::Role; |
|
|
21
|
|
|
|
|
46
|
|
|
|
21
|
|
|
|
|
148
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
with 'MaxMind::DB::Reader::Role::Sysreader'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has metadata => ( |
|
22
|
|
|
|
|
|
|
is => 'ro', |
|
23
|
|
|
|
|
|
|
isa => Metadata, |
|
24
|
|
|
|
|
|
|
init_arg => undef, |
|
25
|
|
|
|
|
|
|
lazy => 1, |
|
26
|
|
|
|
|
|
|
builder => '_build_metadata', |
|
27
|
|
|
|
|
|
|
handles => [ |
|
28
|
|
|
|
|
|
|
'binary_format_major_version', |
|
29
|
|
|
|
|
|
|
'binary_format_minor_version', |
|
30
|
|
|
|
|
|
|
'build_epoch', |
|
31
|
|
|
|
|
|
|
'database_type', |
|
32
|
|
|
|
|
|
|
'description', |
|
33
|
|
|
|
|
|
|
'ip_version', |
|
34
|
|
|
|
|
|
|
'languages', |
|
35
|
|
|
|
|
|
|
'node_count', |
|
36
|
|
|
|
|
|
|
'record_size', |
|
37
|
|
|
|
|
|
|
], |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has _data_section_end => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
writer => '_set_data_section_end', |
|
43
|
|
|
|
|
|
|
isa => Int, |
|
44
|
|
|
|
|
|
|
init_arg => undef, |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $MetadataStartMarker = "\xab\xcd\xefMaxMind.com"; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _build_metadata { |
|
50
|
21
|
|
|
21
|
|
51
|
my $self = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# We need to make sure that whatever chunk we read will have the metadata |
|
53
|
|
|
|
|
|
|
# in it. The description metadata key is a hash of descriptions, one per |
|
54
|
|
|
|
|
|
|
# language. The description could be something verbose like "GeoIP 2.0 |
|
55
|
|
|
|
|
|
|
# City Database, Multilingual - English, Chinese (Taiwan), Chinese |
|
56
|
|
|
|
|
|
|
# (China), French, German, Portuguese" (but with c. 20 languages). That |
|
57
|
|
|
|
|
|
|
# comes out to about 250 bytes _per key_. Multiply that by 20 languages, |
|
58
|
|
|
|
|
|
|
# and the description alon ecould use up about 5k. The other keys in the |
|
59
|
|
|
|
|
|
|
# metadata are very, very tiny. |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# Given all this, reading 20k seems fairly future-proof. We'd have to have |
|
62
|
|
|
|
|
|
|
# extremely long descriptions or descriptions in 80 languages before this |
|
63
|
|
|
|
|
|
|
# became too long. |
|
64
|
|
|
|
|
|
|
|
|
65
|
21
|
|
|
|
|
371
|
my $size = $self->_data_source_size; |
|
66
|
|
|
|
|
|
|
|
|
67
|
21
|
|
|
|
|
718
|
my $last_bytes = min( $size, 20 * 1024 ); |
|
68
|
21
|
|
|
|
|
71
|
my $last_block = q{}; |
|
69
|
21
|
|
|
|
|
186
|
$self->_read( \$last_block, -$last_bytes, $last_bytes, 'seek from end' ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
21
|
|
|
|
|
109
|
my $start = ( $size - $last_bytes ) |
|
72
|
|
|
|
|
|
|
+ rindex( $last_block, $MetadataStartMarker ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
21
|
100
|
|
|
|
299
|
confess 'Error opening database file "' |
|
75
|
|
|
|
|
|
|
. $self->file |
|
76
|
|
|
|
|
|
|
. q{": The MaxMind DB file contains invalid metadata.} |
|
77
|
|
|
|
|
|
|
if $start < 0; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# XXX - this is really gross but I couldn't come up with a better way to |
|
80
|
|
|
|
|
|
|
# factor this out that doesn't involve either looking for the metadata |
|
81
|
|
|
|
|
|
|
# marker multiple times _or_ storing the whole metadata raw chunk in |
|
82
|
|
|
|
|
|
|
# memory so we can calculate this later |
|
83
|
20
|
|
|
|
|
535
|
$self->_set_data_section_end( $size - ( $last_bytes - $start ) ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitCallsToUnexportedSubs) |
|
86
|
20
|
|
|
|
|
800
|
$start += bytes::length($MetadataStartMarker); |
|
87
|
|
|
|
|
|
|
## use critic |
|
88
|
|
|
|
|
|
|
|
|
89
|
20
|
|
|
|
|
2699
|
my $raw = MaxMind::DB::Reader::Decoder->new( |
|
90
|
|
|
|
|
|
|
data_source => $self->data_source, |
|
91
|
|
|
|
|
|
|
pointer_base => $start, |
|
92
|
|
|
|
|
|
|
)->decode($start); |
|
93
|
|
|
|
|
|
|
|
|
94
|
20
|
|
|
|
|
669
|
my $metadata = MaxMind::DB::Metadata->new($raw); |
|
95
|
|
|
|
|
|
|
|
|
96
|
20
|
|
|
|
|
23598
|
return $metadata; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |