line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MaxMind::DB::Reader::Role::Sysreader; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
176487
|
use strict; |
|
21
|
|
|
|
|
34
|
|
|
21
|
|
|
|
|
587
|
|
4
|
21
|
|
|
21
|
|
87
|
use warnings; |
|
21
|
|
|
|
|
31
|
|
|
21
|
|
|
|
|
532
|
|
5
|
21
|
|
|
21
|
|
81
|
use namespace::autoclean; |
|
21
|
|
|
|
|
25
|
|
|
21
|
|
|
|
|
126
|
|
6
|
21
|
|
|
21
|
|
1076
|
use autodie; |
|
21
|
|
|
|
|
28
|
|
|
21
|
|
|
|
|
146
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.000012'; |
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
21
|
|
65214
|
use Carp qw( confess ); |
|
21
|
|
|
|
|
31
|
|
|
21
|
|
|
|
|
1420
|
|
11
|
21
|
|
|
21
|
|
89
|
use MaxMind::DB::Types qw( FileHandle Int ); |
|
21
|
|
|
|
|
26
|
|
|
21
|
|
|
|
|
887
|
|
12
|
|
|
|
|
|
|
|
13
|
21
|
|
|
21
|
|
78
|
use Moo::Role; |
|
21
|
|
|
|
|
26
|
|
|
21
|
|
|
|
|
163
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has data_source => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => FileHandle, |
18
|
|
|
|
|
|
|
lazy => 1, |
19
|
|
|
|
|
|
|
builder => '_build_data_source', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has _data_source_size => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => Int, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
builder => '_build_data_source_size', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _read { |
30
|
16381
|
|
|
16381
|
|
482319
|
my $self = shift; |
31
|
16381
|
|
|
|
|
13154
|
my $buffer = shift; |
32
|
16381
|
|
|
|
|
11187
|
my $offset = shift; |
33
|
16381
|
|
|
|
|
11894
|
my $wanted_size = shift; |
34
|
16381
|
|
|
|
|
10801
|
my $seek_from_end = shift; |
35
|
|
|
|
|
|
|
|
36
|
16381
|
|
|
|
|
26870
|
my $source = $self->data_source(); |
37
|
16381
|
100
|
|
|
|
321322
|
seek $source, $offset, $seek_from_end ? 2 : 0; |
38
|
|
|
|
|
|
|
|
39
|
16381
|
|
|
|
|
421314
|
my $read_offset = 0; |
40
|
16381
|
|
|
|
|
12522
|
while (1) { |
41
|
|
|
|
|
|
|
my $read_size = read( |
42
|
|
|
|
|
|
|
$source, |
43
|
16382
|
|
|
|
|
14740
|
${$buffer}, |
|
16382
|
|
|
|
|
33574
|
|
44
|
|
|
|
|
|
|
$wanted_size, |
45
|
|
|
|
|
|
|
$read_offset, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
16382
|
50
|
|
|
|
486448
|
confess $! unless defined $read_size; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# This error message doesn't provide much context, but it should only |
51
|
|
|
|
|
|
|
# be thrown because of a fundamental logic error in the reader code, |
52
|
|
|
|
|
|
|
# _or_ because the writer generated a database with broken pointers |
53
|
|
|
|
|
|
|
# and/or broken data elements. |
54
|
16382
|
100
|
|
|
|
21631
|
confess 'Attempted to read past the end of a file/memory buffer' |
55
|
|
|
|
|
|
|
if $read_size == 0; |
56
|
|
|
|
|
|
|
|
57
|
16381
|
100
|
|
|
|
35661
|
return if $wanted_size == $read_size; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
2
|
$wanted_size -= $read_size; |
60
|
1
|
|
|
|
|
2
|
$read_offset += $read_size; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _build_data_source { |
67
|
0
|
|
|
0
|
|
0
|
my $class = ref shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
die |
70
|
|
|
|
|
|
|
"You must provide a data_source parameter to the constructor for $class"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _build_data_source_size { |
74
|
58
|
|
|
58
|
|
3429
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
58
|
50
|
|
|
|
171
|
my @stat = stat( $self->data_source ) or die $!; |
77
|
58
|
|
|
|
|
3158
|
return $stat[7]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |