blib/lib/DBM/Deep/Iterator/File.pm

filter: Statementstmt 92.5% 50 / 54 Branchbran 84.6% 22 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 90.1% 82 / 91 CC 14 SCAR 19.3
CC
14
Cov
90%
get_next_key
11.1
get_sector_iterator
4.2
BEGIN
1.0
CRAP 6.9
« blib/lib/DBM/Deep/Sector/DBI.pm ↑ Summary blib/lib/DBM/Deep/Storage/DBI.pm »
1 package DBM::Deep::Iterator::File;
2  
3 48 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 48 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 48 ▶use base qw( DBM::Deep::Iterator );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 48 ▶use DBM::Deep::Iterator::File::BucketList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 48 ▶use DBM::Deep::Iterator::File::Index ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 299 ▶sub reset { $_[0]{breadcrumbs} = []; return }
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
12  
13 sub get_sector_iterator {
14 355 ▶ my $self = shift;
Subroutine get_sector_iterator: called CC=4 SCAR=14.3
Pod undocumented
15 355 my ($loc) = @_;
16  
17 355 ▶ my $sector = $self->{engine}->load_sector( $loc )
Branch: 1 branch
BranchTrueFalseTotal
my $sector = $self->{"engine"}->load_sector($loc) or return 0 355 355
18 or return;
19  
20 355 ▶ if ( $sector->isa( 'DBM::Deep::Sector::File::Index' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sector->isa('DBM::Deep::Sector::File::Index')) { } 16 339 355
elsif ($sector->isa('DBM::Deep::Sector::File::BucketList')) { } 339 0 339
21 16 return DBM::Deep::Iterator::File::Index->new({
22 iterator => $self,
23 sector => $sector,
24 });
25 }
26 elsif ( $sector->isa( 'DBM::Deep::Sector::File::BucketList' ) ) {
27 339 return DBM::Deep::Iterator::File::BucketList->new({
28 iterator => $self,
29 sector => $sector,
30 });
31 }
32  
33 0 DBM::Deep->_throw_error( "get_sector_iterator(): Why did $loc make a $sector?" );
34 }
35  
36 sub get_next_key {
37 531 ▶ my $self = shift;
Subroutine get_next_key: called CC=11 SCAR=24.1
Pod documented
38 531 my ($obj) = @_;
39  
40 531 my $crumbs = $self->{breadcrumbs};
41 531 my $e = $self->{engine};
42  
43 531 ▶ unless ( @$crumbs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$crumbs) 153 378 531
44 # This will be a Reference sector
45 my $sector = $e->load_sector( $self->{base_offset} )
46 # If no sector is found, this must have been deleted from under us.
47 153 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sector = $e->load_sector($self->{"base_offset"}) or return 1 152 153
48  
49 152 ▶ if ( $sector->staleness != $obj->_staleness ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sector->staleness != $obj->_staleness) 0 152 152
50 0 return;
51 }
52  
53 152 ▶ my $loc = $sector->get_blist_loc
Branch: 1 branch
BranchTrueFalseTotal
my $loc = $sector->get_blist_loc or return 5 147 152
54 or return;
55  
56 147 push @$crumbs, $self->get_sector_iterator( $loc );
57 }
58  
59 FIND_NEXT_KEY: {
60 # We're at the end.
61 525 ▶ unless ( @$crumbs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$crumbs) 146 5988 6134
62 146 $self->reset;
63 146 return;
64 }
65  
66 5988 my $iterator = $crumbs->[-1];
67  
68 # This level is done.
69 5988 ▶ if ( $iterator->at_end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator->at_end) 354 5634 5988
70 354 pop @$crumbs;
71 354 redo FIND_NEXT_KEY;
72 }
73  
74 5634 ▶ if ( $iterator->isa( 'DBM::Deep::Iterator::File::Index' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator->isa("DBM::Deep::Iterator::File::Index")) 224 5410 5634
75 # If we don't have any more, it will be caught at the
76 # prior check.
77 224 ▶ if ( my $next = $iterator->get_next_iterator ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $iterator->get_next_iterator) 208 16 224
78 208 push @$crumbs, $next;
79 }
80 224 redo FIND_NEXT_KEY;
81 }
82  
83 5410 ▶ unless ( $iterator->isa( 'DBM::Deep::Iterator::File::BucketList' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iterator->isa("DBM::Deep::Iterator::File::BucketList")) 0 5410 5410
84 0 DBM::Deep->_throw_error(
85 "Should have a bucketlist iterator here - instead have $iterator"
86 );
87 }
88  
89 # At this point, we have a BucketList iterator
90 5410 my $key = $iterator->get_next_key;
91 5410 ▶ if ( defined $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 379 5031 5410
92 379 return $key;
93 }
94 #XXX else { $iterator->set_to_end() } ?
95  
96 # We hit the end of the bucketlist iterator, so redo
97 5031 redo FIND_NEXT_KEY;
98 }
99  
100 0 DBM::Deep->_throw_error( "get_next_key(): How did we get here?" );
101 }
102  
103 48 1;
104 __END__
« blib/lib/DBM/Deep/Sector/DBI.pm ↑ Summary blib/lib/DBM/Deep/Storage/DBI.pm »