BerkeleyDB/shared/hash.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 92 CC 9 SCAR 21.2
CC
9
Cov
0%
STORE
20.0
DELETE
12.0
new
6.0
CRAP 8.3
1 package forks::BerkeleyDB::shared::hash;
2  
3 $VERSION = 0.060;
4 use strict;
5 use warnings;
6 use BerkeleyDB 0.27;
7 use vars qw(@ISA);
8 @ISA = qw(BerkeleyDB::Btree);
9  
10 #---------------------------------------------------------------------------
11 sub new {
12 my $type = shift;
13 my $class = ref($type) || $type;
14 my $self = $class->SUPER::new(@_);
15 return undef unless defined $self;
16 return bless($self, $class);
17 }
18  
19 # standard Perl feature methods implemented:
20 # TIEHASH
21 # FETCH, STORE
22 # CLEAR, DELETE
23 # EXISTS
24 # FIRSTKEY, NEXTKEY
25 # SCALAR
26 # UNTIE, DESTROY
27  
28 #---------------------------------------------------------------------------
29 *TIEHASH = *TIEHASH = \&new;
30  
31 #---------------------------------------------------------------------------
32 sub FETCH {
33 my $value = undef;
34 $_[0]->db_get($_[1], $value);
35 return $value;
36 }
37  
38 sub STORE {
39 if (defined $_[2]) {
40 return undef unless $_[0]->db_put($_[1], $_[2]) == 0;
41 } else {
42 no warnings 'uninitialized';
43 return undef unless $_[0]->db_put($_[1], $_[2]) == 0;
44 }
45 return $_[2];
46 }
47  
48 #---------------------------------------------------------------------------
49 sub DELETE {
50 my $self = shift;
51 return undef unless @_;
52 my $key = shift;
53 my $value = undef;
54 my $cursor = $self->db_cursor(DB_WRITECURSOR);
55 return undef unless $cursor->c_get($key, $value, DB_SET) == 0; #set cursor position
56 $cursor->c_del();
57 $cursor->c_close();
58 return $value;
59 }
60  
61 sub CLEAR {
62 my $self = shift;
63 my $count = 0;
64 $self->truncate($count);
65 return defined $count && $count > 0 ? 1 : 0;
66 }
67  
68 #---------------------------------------------------------------------------
69 #sub EXISTS {} #use BerkeleyDB.pm method
70  
71 #---------------------------------------------------------------------------
72 #sub FIRSTKEY {} #use BerkeleyDB.pm method
73  
74 #sub NEXTKEY {} #use BerkeleyDB.pm method
75  
76 #---------------------------------------------------------------------------
77 #sub SCALAR {} #use BerkeleyDB.pm method (or FIRSTKEY if SCALAR not defined)
78  
79 #---------------------------------------------------------------------------
80 sub UNTIE {
81 eval { $_[0]->db_sync(); };
82 }
83  
84 sub DESTROY {
85 # eval { $_[0]->db_sync(); };
86 $_[0]->SUPER::DESTROY(@_) if $_[0];
87 }
88  
89 #---------------------------------------------------------------------------
90 1;
91  
92 __END__