File Coverage

blib/lib/Number/Phone/NO/Data.pm
Criterion Covered Total %
statement 30 31 96.7
branch 16 24 66.6
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 50 60 83.3


line stmt bran cond sub pod time code
1             package
2             Number::Phone::NO::Data;
3              
4 5     5   54209 use strict;
  5         14  
  5         370  
5 5     5   31 use warnings;
  5         10  
  5         191  
6              
7 5     5   5349 use DBM::Deep;
  5         79322  
  5         120  
8             our $db = DBM::Deep->new( { fh => \*DATA, type => DBM::Deep->TYPE_ARRAY, locking => 0 });
9             our $count = 1164;
10             our $DEBUG = 0;
11             sub lookup {
12 132     132 0 2556 my $nr = shift;
13 132         205 my $f = shift;
14 132         182 my $t = shift;
15 132 100       313 $f = 0 unless defined $f;
16 132 100       252 $t = $count unless defined $t;
17            
18 132         723 my $delta = sprintf("%d", ($t - $f) / 2);
19 132         261 my $bucket_id = $f + $delta;
20 132 50       294 die "bad bucket_id: $bucket_id out of range" if ($bucket_id > $count);
21 132 50       256 warn "lookup: $nr -- $f - $t, looking in $bucket_id" if $DEBUG;
22 132         568 my $bucket = $db->get($bucket_id);
23            
24 132 50       196305 warn $bucket->{from} . " - " . $bucket->{to} if $DEBUG;
25            
26 132 100       863 if ($nr < $bucket->{from}) {
    100          
27            
28 63         70694 my $new_id = $f + $delta;
29 63 50       182 warn "below our bucket, looking in $f - $new_id" if $DEBUG;
30 63 50       138 return unless $delta; # if $delta is 0 we are in the last possible bucket
31 63         226 return lookup($nr, $f, $new_id);
32            
33             } elsif ($nr > $bucket->{to}) {
34            
35 57         127040 my $new_id = $bucket_id;
36 57 50       174 warn "above our bucket, looking in $new_id - $t" if $DEBUG;
37 57 100       134 return unless $delta; # if $delta is 0 we are in the last possible bucket
38 56         281 return lookup($nr, $new_id, $t);
39             } else {
40             # # YAY :p
41 12         26744 return $bucket;
42 0 0         warn "our bucket, yay" if $DEBUG;
43             }
44             }
45             1;
46              
47             __DATA__