| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package DBM::Deep::Sector::File; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 50 |  |  | 50 |  | 869 | use 5.008_004; | 
|  | 50 |  |  |  |  | 175 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 50 |  |  | 50 |  | 270 | use strict; | 
|  | 50 |  |  |  |  | 97 |  | 
|  | 50 |  |  |  |  | 1389 |  | 
| 6 | 50 |  |  | 50 |  | 318 | use warnings FATAL => 'all'; | 
|  | 50 |  |  |  |  | 128 |  | 
|  | 50 |  |  |  |  | 2259 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 50 |  |  | 50 |  | 322 | use base qw( DBM::Deep::Sector ); | 
|  | 50 |  |  |  |  | 119 |  | 
|  | 50 |  |  |  |  | 23661 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 50 |  |  | 50 |  | 26804 | use DBM::Deep::Sector::File::BucketList (); | 
|  | 50 |  |  |  |  | 151 |  | 
|  | 50 |  |  |  |  | 1263 |  | 
| 11 | 50 |  |  | 50 |  | 24979 | use DBM::Deep::Sector::File::Index (); | 
|  | 50 |  |  |  |  | 147 |  | 
|  | 50 |  |  |  |  | 1288 |  | 
| 12 | 50 |  |  | 50 |  | 24822 | use DBM::Deep::Sector::File::Null (); | 
|  | 50 |  |  |  |  | 147 |  | 
|  | 50 |  |  |  |  | 1455 |  | 
| 13 | 50 |  |  | 50 |  | 26891 | use DBM::Deep::Sector::File::Reference (); | 
|  | 50 |  |  |  |  | 157 |  | 
|  | 50 |  |  |  |  | 1504 |  | 
| 14 | 50 |  |  | 50 |  | 25592 | use DBM::Deep::Sector::File::Scalar (); | 
|  | 50 |  |  |  |  | 150 |  | 
|  | 50 |  |  |  |  | 19303 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | my $STALE_SIZE = 2; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub base_size { | 
| 19 | 71530 |  |  | 71530 | 0 | 109573 | my $self = shift; | 
| 20 | 71530 |  |  |  |  | 139156 | 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 | 816 | my $self = shift; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 465 |  |  |  |  | 1229 | my $e = $self->engine; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 465 |  |  |  |  | 1269 | $e->storage->print_at( $self->offset, $e->SIG_FREE ); | 
| 31 |  |  |  |  |  |  | # Skip staleness counter | 
| 32 | 465 |  |  |  |  | 1670 | $e->storage->print_at( $self->offset + $self->base_size, | 
| 33 |  |  |  |  |  |  | chr(0) x ($self->size - $self->base_size), | 
| 34 |  |  |  |  |  |  | ); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 465 |  |  |  |  | 1983 | my $free_meth = $self->free_meth; | 
| 37 | 465 |  |  |  |  | 1270 | $e->$free_meth( $self->offset, $self->size ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 465 |  |  |  |  | 1473 | 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 | 23034 |  |  | 23034 | 0 | 38827 | my $self = shift; | 
| 51 | 23034 |  |  |  |  | 41593 | my ($engine, $offset) = @_; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Add a catch for offset of 0 or 1 | 
| 54 | 23034 | 100 | 100 |  |  | 86013 | return if !$offset || $offset <= 1; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 23030 |  |  |  |  | 53582 | my $type = $engine->storage->read_at( $offset, 1 ); | 
| 57 | 23030 | 50 |  |  |  | 66784 | return if $type eq chr(0); | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 23030 | 100 | 100 |  |  | 149642 | if ( $type eq $engine->SIG_ARRAY || $type eq $engine->SIG_HASH ) { | 
|  |  | 100 | 100 |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 60 | 8976 |  |  |  |  | 48046 | 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 | 5766 |  |  |  |  | 29074 | 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 |  |  |  |  | 21730 | 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 |  |  |  |  | 157 | 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 |  |  |  |  | 21087 | 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 |  |  |  |  | 51 | 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__ |