File Coverage

blib/lib/Data/CompactReadonly/V0/Collection.pm
Criterion Covered Total %
statement 33 33 100.0
branch 6 6 100.0
condition 3 3 100.0
subroutine 12 12 100.0
pod 0 2 0.0
total 54 56 96.4


line stmt bran cond sub pod time code
1             package Data::CompactReadonly::V0::Collection;
2             our $VERSION = '0.0.6';
3              
4 9     9   66 use warnings;
  9         17  
  9         265  
5 9     9   53 use strict;
  9         15  
  9         177  
6 9     9   37 use base 'Data::CompactReadonly::V0::Node';
  9         29  
  9         1148  
7              
8 9     9   60 use Scalar::Util qw(blessed);
  9         14  
  9         416  
9 9     9   3694 use Data::CompactReadonly::V0::Scalar;
  9         55  
  9         2865  
10              
11             sub _numeric_type_for_length {
12 1590     1590   2182 my $invocant = shift();
13 1590 100       10782 (my $class = blessed($invocant) ? blessed($invocant) : $invocant) =~ s/(Text|Array|Dictionary)/Scalar/;
14 1590         5136 return $class;
15             }
16              
17             sub count {
18 349     349 0 3287 my $self = shift;
19 349 100 100     1058 if($self->{cache} && exists($self->{cache}->{count})) {
    100          
20 13         35 return $self->{cache}->{count};
21             } elsif($self->{cache}) {
22 5         15 return $self->{cache}->{count} = $self->_count();
23             } else {
24 331         625 return $self->_count();
25             }
26             }
27              
28             sub _count {
29 336     336   445 my $self = shift;
30 336         1065 $self->_seek($self->_offset());
31 336         1058 return $self->_numeric_type_for_length()->_init(root => $self->_root());
32             }
33              
34             sub id {
35 6     6 0 14 my $self = shift;
36 6         14 return $self->_offset();
37             }
38              
39             sub _scalar_type_bytes {
40 686     686   898 my $self = shift;
41 686         1172 return $self->_numeric_type_for_length()->_num_bytes();
42             }
43              
44             sub _encode_ptr {
45 131312     131312   290309 my($class, %args) = @_;
46             return Data::CompactReadonly::V0::Scalar->_encode_word_as_number_of_bytes(
47             $args{pointer},
48             $args{ptr_size}
49 131312         336044 );
50             }
51              
52             sub _decode_ptr {
53 686     686   2356 goto &Data::CompactReadonly::V0::Scalar::_decode_word;
54             }
55              
56             1;