| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MaxMind::DB::Reader::Role::Sysreader; |
|
2
|
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
149693
|
use strict; |
|
|
21
|
|
|
|
|
29
|
|
|
|
21
|
|
|
|
|
503
|
|
|
4
|
21
|
|
|
21
|
|
63
|
use warnings; |
|
|
21
|
|
|
|
|
24
|
|
|
|
21
|
|
|
|
|
417
|
|
|
5
|
21
|
|
|
21
|
|
67
|
use namespace::autoclean; |
|
|
21
|
|
|
|
|
24
|
|
|
|
21
|
|
|
|
|
92
|
|
|
6
|
21
|
|
|
21
|
|
812
|
use autodie; |
|
|
21
|
|
|
|
|
27
|
|
|
|
21
|
|
|
|
|
110
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.000013'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
21
|
|
|
21
|
|
60142
|
use Carp qw( confess ); |
|
|
21
|
|
|
|
|
27
|
|
|
|
21
|
|
|
|
|
1106
|
|
|
11
|
21
|
|
|
21
|
|
83
|
use MaxMind::DB::Types qw( FileHandle Int ); |
|
|
21
|
|
|
|
|
22
|
|
|
|
21
|
|
|
|
|
810
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
21
|
|
|
21
|
|
71
|
use Moo::Role; |
|
|
21
|
|
|
|
|
23
|
|
|
|
21
|
|
|
|
|
107
|
|
|
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
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
|
30
|
|
|
|
|
|
|
sub _read { |
|
31
|
16381
|
|
|
16381
|
|
446830
|
my $self = shift; |
|
32
|
16381
|
|
|
|
|
11174
|
my $buffer = shift; |
|
33
|
16381
|
|
|
|
|
11331
|
my $offset = shift; |
|
34
|
16381
|
|
|
|
|
10568
|
my $wanted_size = shift; |
|
35
|
16381
|
|
|
|
|
10101
|
my $seek_from_end = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
16381
|
|
|
|
|
23522
|
my $source = $self->data_source(); |
|
38
|
16381
|
100
|
|
|
|
284771
|
seek $source, $offset, $seek_from_end ? 2 : 0; |
|
39
|
|
|
|
|
|
|
|
|
40
|
16381
|
|
|
|
|
376996
|
my $read_offset = 0; |
|
41
|
16381
|
|
|
|
|
11680
|
while (1) { |
|
42
|
|
|
|
|
|
|
my $read_size = read( |
|
43
|
|
|
|
|
|
|
$source, |
|
44
|
16382
|
|
|
|
|
11352
|
${$buffer}, |
|
|
16382
|
|
|
|
|
29343
|
|
|
45
|
|
|
|
|
|
|
$wanted_size, |
|
46
|
|
|
|
|
|
|
$read_offset, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
16382
|
50
|
|
|
|
438256
|
confess $! unless defined $read_size; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# This error message doesn't provide much context, but it should only |
|
52
|
|
|
|
|
|
|
# be thrown because of a fundamental logic error in the reader code, |
|
53
|
|
|
|
|
|
|
# _or_ because the writer generated a database with broken pointers |
|
54
|
|
|
|
|
|
|
# and/or broken data elements. |
|
55
|
16382
|
100
|
|
|
|
20999
|
confess 'Attempted to read past the end of a file/memory buffer' |
|
56
|
|
|
|
|
|
|
if $read_size == 0; |
|
57
|
|
|
|
|
|
|
|
|
58
|
16381
|
100
|
|
|
|
33834
|
return if $wanted_size == $read_size; |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
2
|
$wanted_size -= $read_size; |
|
61
|
1
|
|
|
|
|
2
|
$read_offset += $read_size; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
return; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
## use critic |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _build_data_source { |
|
69
|
0
|
|
|
0
|
|
0
|
my $class = ref shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
die |
|
72
|
|
|
|
|
|
|
"You must provide a data_source parameter to the constructor for $class"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _build_data_source_size { |
|
76
|
58
|
|
|
58
|
|
3010
|
my $self = shift; |
|
77
|
|
|
|
|
|
|
|
|
78
|
58
|
50
|
|
|
|
139
|
my @stat = stat( $self->data_source ) or die $!; |
|
79
|
58
|
|
|
|
|
2828
|
return $stat[7]; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |