package Foo::DBM; use strict; use vars qw /$VERSION @ISA/; $VERSION = 1.0; use Exporter; @ISA = qw/Exporter/; use GDBM_File; use Storable qw/freeze thaw/; sub new { my ($class, $path, $type, $key) = @_; my $self = { PATH => $path, TYPE => $type, KEY => $key, RECORD => { +} }; bless $self, $class; $self->read if $key; $self; } sub read { my $self = shift; die "Can't read without knowing what" unless $self->{KEY}; my $filename = "$self->{PATH}/$self->{TYPE}"; $filename =~ s/\/\//\//g; my %file; tie %file, 'GDBM_File', $filename, GDBM_READER || die $!; my $rec = $file{$self->{KEY}}; $self->{RECORD} = thaw $rec; untie %file; 1; } sub save { my $self = shift; die "Can't write without knowing where" unless $self->{KEY}; my $filename = "$self->{PATH}/$self->{TYPE}"; $filename =~ s/\/\//\//g; my %file; tie %file, 'GDBM_File', $filename, GDBM_WRCREAT, 0640 || die $!; my $rec = freeze $self->{RECORD}; $file{$self->{KEY}} = $rec; untie %file; 1; } 1;
Janitored: <readmore> tags added by davido.
In reply to GDBM_File dies without telling why by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |