| forks-BerkeleyDB documentation | Contained in the forks-BerkeleyDB distribution. |
forks::BerkeleyDB::shared::scalar - class for tie-ing scalars to BerkeleyDB Recno
Helper class for forks::BerkeleyDB::shared. See documentation there.
Eric Rybski <rybskej@yahoo.com>.
Copyright (c) 2006-2009 Eric Rybski <rybskej@yahoo.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| forks-BerkeleyDB documentation | Contained in the forks-BerkeleyDB distribution. |
package forks::BerkeleyDB::shared::scalar; $VERSION = 0.060; use strict; use warnings; use BerkeleyDB 0.27; use vars qw(@ISA); @ISA = qw(BerkeleyDB::Recno); #--------------------------------------------------------------------------- sub new { my $type = shift; my $class = ref($type) || $type; my $self = $class->SUPER::new(@_); return undef unless defined $self; return bless($self, $class); } # standard Perl feature methods implemented: # TIESCALAR # FETCH, STORE # UNTIE, DESTROY #--------------------------------------------------------------------------- *TIESCALAR = *TIESCALAR = \&new; #--------------------------------------------------------------------------- sub FETCH { my ($key, $value) = (0, undef); return undef unless $_[0]->db_get($key, $value) == 0; return $value; } sub STORE { my $key = 0; if (defined $_[1]) { return undef unless $_[0]->db_put($key, $_[1]) == 0; } else { no warnings 'uninitialized'; return undef unless $_[0]->db_put($key, $_[1]) == 0; } return $_[1]; } #--------------------------------------------------------------------------- sub UNTIE { eval { $_[0]->db_sync(); }; } sub DESTROY { # eval { $_[0]->db_sync(); }; $_[0]->SUPER::DESTROY(@_) if $_[0]; } #--------------------------------------------------------------------------- 1; __END__