Reader/Role/NodeReader.pm

filter: Statementstmt 100% 39 / 39 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 98.1% 54 / 55 CC 4 SCAR 6.6
CC
4
Cov
98%
_split_node_into_records
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Reader/Role/Sysreader.pm ↑ Summary Reader/Role/Reader.pm »
1 package MaxMind::DB::Reader::Role::NodeReader;
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 MaxMind::DB::Types qw( Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 21 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 21 with 'MaxMind::DB::Reader::Role::HasMetadata';
15  
16 21 has _node_byte_size => (
17 is => 'ro',
18 isa => Int,
19 init_arg => undef,
20 lazy => 1,
21 builder => '_build_node_byte_size',
22 );
23  
24 21 has _search_tree_size => (
25 is => 'ro',
26 isa => Int,
27 init_arg => undef,
28 lazy => 1,
29 builder => '_build_search_tree_size',
30 );
31  
32 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
33 14723 ▶sub _read_node {
Subroutine _read_node: called CC=1 SCAR=0.0
34 14723 my $self = shift;
35 14723 my $node_num = shift;
36  
37 14723 my $node = q{};
38 14723 $self->_read(
39 \$node,
40 $node_num * $self->_node_byte_size,
41 $self->_node_byte_size,
42 );
43  
44 14723 return $self->_split_node_into_records($node);
45 }
46  
47 14723 ▶sub _split_node_into_records {
Subroutine _split_node_into_records: called CC=4 SCAR=13.9
48 14723 my $self = shift;
49 14723 my $node = shift;
50  
51 14723 ▶ if ( $self->record_size == 24 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->record_size == 24) { } 5683 9040 14723
elsif ($self->record_size == 28) { } 4556 4484 9040
elsif ($self->record_size == 32) { } 4484 0 4484
52 5683 return unpack( NN => pack( 'xa*xa*' => unpack( a3a3 => $node ) ) );
53 }
54 elsif ( $self->record_size == 28 ) {
55 4556 my ( $left_bytes, $middle_byte, $right_bytes )
56 = unpack( a3Ca3 => $node );
57  
58 return (
59 4556 unpack(
60 N => pack( 'Ca*', ( $middle_byte & 0xf0 ) >> 4, $left_bytes )
61 ),
62 unpack(
63 N => pack( 'Ca*', ( $middle_byte & 0x0f ), $right_bytes )
64 )
65 );
66 }
67 elsif ( $self->record_size == 32 ) {
68 4484 return unpack( NN => $node );
69 }
70 }
71  
72 19 ▶sub _build_node_byte_size {
Subroutine _build_node_byte_size: called CC=1 SCAR=0.0
73 19 my $self = shift;
74  
75 19 return $self->record_size * 2 / 8;
76 }
77  
78 17 ▶sub _build_search_tree_size {
Subroutine _build_search_tree_size: called CC=1 SCAR=0.0
79 17 my $self = shift;
80  
81 17 return $self->node_count * $self->_node_byte_size;
82 }
83  
84 21 1;
« Reader/Role/Sysreader.pm ↑ Summary Reader/Role/Reader.pm »