Reader/Role/Sysreader.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 91.0% 61 / 67 CC 6 SCAR 9.3
CC
6
Cov
91%
_read
5.0
_build_data_source_size
2.0
_build_data_source
2.0
CRAP 2.5
« Reader/Decoder.pm ↑ Summary Reader/Role/NodeReader.pm »
1 package MaxMind::DB::Reader::Role::Sysreader;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 our $VERSION = '1.000014';
9  
10 21 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use MaxMind::DB::Types qw( FileHandle Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 21 has data_source => (
16 is => 'ro',
17 isa => FileHandle,
18 lazy => 1,
19 builder => '_build_data_source',
20 );
21  
22 21 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 17069 ▶sub _read {
Subroutine _read: called CC=5 SCAR=16.1
31 17069 my $self = shift;
32 17069 my $buffer = shift;
33 17069 my $offset = shift;
34 17069 my $wanted_size = shift;
35 17069 my $seek_from_end = shift;
36  
37 17069 my $source = $self->data_source;
38 17069 ▶ seek $source, $offset, $seek_from_end ? 2 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$seek_from_end ? : 21 17048 17069
39  
40 17069 my $read_offset = 0;
41 17069 while (1) {
42 my $read_size = read(
43 $source,
44 17070 ${$buffer},
45 $wanted_size,
46 $read_offset,
47 );
48  
49 17070 ▶ confess $! unless defined $read_size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read_size 0 17070 17070
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 17070 ▶ confess 'Attempted to read past the end of a file/memory buffer'
Branch: 1 branch
BranchTrueFalseTotal
if $read_size == 0 1 17069 17070
56 if $read_size == 0;
57  
58 17069 ▶ return if $wanted_size == $read_size;
Branch: 1 branch
BranchTrueFalseTotal
if $wanted_size == $read_size 17068 1 17069
59  
60 1 $wanted_size -= $read_size;
61 1 $read_offset += $read_size;
62 }
63  
64 0 return;
65 }
66 ## use critic
67  
68 0 ▶sub _build_data_source {
Subroutine _build_data_source: not called CC=1 SCAR=6.9
69 0 my $class = ref shift;
70  
71 0 die
72 "You must provide a data_source parameter to the constructor for $class";
73 }
74  
75 58 ▶sub _build_data_source_size {
Subroutine _build_data_source_size: called CC=2 SCAR=7.1
76 58 my $self = shift;
77  
78 58 ▶ my @stat = stat( $self->data_source ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
my(@stat) = stat $self->data_source or die $! 58 0 58
79 58 return $stat[7];
80 }
81  
82 21 1;
« Reader/Decoder.pm ↑ Summary Reader/Role/NodeReader.pm »