File Coverage

blib/lib/DBM/Deep/Sector/File.pm
Criterion Covered Total %
statement 47 49 95.9
branch 14 16 87.5
condition 9 9 100.0
subroutine 12 13 92.3
pod 0 4 0.0
total 82 91 90.1


line stmt bran cond sub pod time code
1             package DBM::Deep::Sector::File;
2              
3 50     50   880 use 5.008_004;
  50         176  
4              
5 50     50   254 use strict;
  50         104  
  50         1299  
6 50     50   301 use warnings FATAL => 'all';
  50         131  
  50         1922  
7              
8 50     50   299 use base qw( DBM::Deep::Sector );
  50         123  
  50         23044  
9              
10 50     50   25750 use DBM::Deep::Sector::File::BucketList ();
  50         140  
  50         1182  
11 50     50   23505 use DBM::Deep::Sector::File::Index ();
  50         132  
  50         1219  
12 50     50   23723 use DBM::Deep::Sector::File::Null ();
  50         137  
  50         1340  
13 50     50   26317 use DBM::Deep::Sector::File::Reference ();
  50         148  
  50         1833  
14 50     50   23800 use DBM::Deep::Sector::File::Scalar ();
  50         141  
  50         19469  
15              
16             my $STALE_SIZE = 2;
17              
18             sub base_size {
19 71536     71536 0 106023 my $self = shift;
20 71536         134719 return $self->engine->SIG_SIZE + $STALE_SIZE;
21             }
22              
23 0     0 0 0 sub free_meth { die "free_meth must be implemented in a child class" }
24              
25             sub free {
26 465     465 0 809 my $self = shift;
27              
28 465         1213 my $e = $self->engine;
29              
30 465         1238 $e->storage->print_at( $self->offset, $e->SIG_FREE );
31             # Skip staleness counter
32 465         1639 $e->storage->print_at( $self->offset + $self->base_size,
33             chr(0) x ($self->size - $self->base_size),
34             );
35              
36 465         2051 my $free_meth = $self->free_meth;
37 465         1187 $e->$free_meth( $self->offset, $self->size );
38              
39 465         1455 return;
40             }
41              
42             #=head2 load( $offset )
43             #
44             #This will instantiate and return the sector object that represents the data
45             #found at $offset.
46             #
47             #=cut
48              
49             sub load {
50 23033     23033 0 38052 my $self = shift;
51 23033         41765 my ($engine, $offset) = @_;
52              
53             # Add a catch for offset of 0 or 1
54 23033 100 100     83089 return if !$offset || $offset <= 1;
55              
56 23029         50988 my $type = $engine->storage->read_at( $offset, 1 );
57 23029 50       62855 return if $type eq chr(0);
58              
59 23029 100 100     144779 if ( $type eq $engine->SIG_ARRAY || $type eq $engine->SIG_HASH ) {
    100 100        
    100          
    100          
    100          
    50          
60 8976         45715 return DBM::Deep::Sector::File::Reference->new({
61             engine => $engine,
62             type => $type,
63             offset => $offset,
64             });
65             }
66             # XXX Don't we need key_md5 here?
67             elsif ( $type eq $engine->SIG_BLIST ) {
68 5765         28390 return DBM::Deep::Sector::File::BucketList->new({
69             engine => $engine,
70             type => $type,
71             offset => $offset,
72             });
73             }
74             elsif ( $type eq $engine->SIG_INDEX ) {
75 4089         20141 return DBM::Deep::Sector::File::Index->new({
76             engine => $engine,
77             type => $type,
78             offset => $offset,
79             });
80             }
81             elsif ( $type eq $engine->SIG_NULL ) {
82 27         182 return DBM::Deep::Sector::File::Null->new({
83             engine => $engine,
84             type => $type,
85             offset => $offset,
86             });
87             }
88             elsif ( $type eq $engine->SIG_DATA || $type eq $engine->SIG_UNIDATA ) {
89 4167         19093 return DBM::Deep::Sector::File::Scalar->new({
90             engine => $engine,
91             type => $type,
92             offset => $offset,
93             });
94             }
95             # This was deleted from under us, so just return and let the caller figure it out.
96             elsif ( $type eq $engine->SIG_FREE ) {
97 5         31 return;
98             }
99              
100 0           DBM::Deep->_throw_error( "'$offset': Don't know what to do with type '$type'" );
101             }
102              
103             1;
104             __END__