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.1.0';
3              
4 10     10   83 use warnings;
  10         21  
  10         655  
5 10     10   124 use strict;
  10         33  
  10         388  
6 10     10   53 use base 'Data::CompactReadonly::V0::Node';
  10         17  
  10         1556  
7              
8 10     10   120 use Scalar::Util qw(blessed);
  10         48  
  10         715  
9 10     10   5505 use Data::CompactReadonly::V0::Scalar;
  10         34  
  10         4743  
10              
11             sub _numeric_type_for_length {
12 1728     1728   16019 my $invocant = shift();
13 1728 100       15947 (my $class = blessed($invocant) ? blessed($invocant) : $invocant) =~ s/(Text|Array|Dictionary)/Scalar/;
14 1728         8002 return $class;
15             }
16              
17             sub count {
18 369     369 0 10150 my $self = shift;
19 369 100 100     1821 if($self->{cache} && exists($self->{cache}->{count})) {
    100          
20 13         42 return $self->{cache}->{count};
21             } elsif($self->{cache}) {
22 5         19 return $self->{cache}->{count} = $self->_count();
23             } else {
24 351         986 return $self->_count();
25             }
26             }
27              
28             sub _count {
29 356     356   621 my $self = shift;
30 356         1246 $self->_seek($self->_offset());
31 356         1304 return $self->_numeric_type_for_length()->_init(root => $self->_root());
32             }
33              
34             sub id {
35 6     6 0 17 my $self = shift;
36 6         25 return $self->_offset();
37             }
38              
39             sub _scalar_type_bytes {
40 754     754   1622 my $self = shift;
41 754         1987 return $self->_numeric_type_for_length()->_num_bytes();
42             }
43              
44             sub _encode_ptr {
45 131339     131339   422731 my($class, %args) = @_;
46             return Data::CompactReadonly::V0::Scalar->_encode_word_as_number_of_bytes(
47             $args{pointer},
48             $args{ptr_size}
49 131339         458499 );
50             }
51              
52             sub _decode_ptr {
53 754     754   3341 goto &Data::CompactReadonly::V0::Scalar::_decode_word;
54             }
55              
56             1;