26 |
my %parm = @_; |
my %parm = @_; |
27 |
my $self = {}; |
my $self = {}; |
28 |
|
|
29 |
for my $x (qw(file attr env subname maindbfile tablename)) { |
for my $x (qw(path attr env subname maindbfile tablename)) { |
30 |
unless ($self->{$x} = $parm{$x}) { |
unless ($self->{$x} = $parm{$x}) { |
31 |
require Carp; |
require Carp; |
32 |
Carp::croak("No $x specified"); |
Carp::croak("No $x specified"); |
48 |
sub drop { |
sub drop { |
49 |
my $self = shift; |
my $self = shift; |
50 |
if ((caller)[0] eq 'WAIT::Table') { # Table knows about this |
if ((caller)[0] eq 'WAIT::Table') { # Table knows about this |
51 |
my $file = $self->{file}; |
my $path = $self->{path}; |
52 |
! (!-e $file or unlink $file); |
! (!-e $path or unlink $path); |
53 |
} else { # notify our database |
} else { # notify our database |
54 |
require Carp; |
require Carp; |
55 |
Carp::croak(ref($self)."::drop called directly"); |
Carp::croak(ref($self)."::drop called directly"); |
58 |
|
|
59 |
sub open { |
sub open { |
60 |
my $self = shift; |
my $self = shift; |
61 |
my $file = $self->{file}; |
my $path = $self->{path}; |
62 |
|
|
63 |
if (exists $self->{dbh}) { |
if (exists $self->{dbh}) { |
64 |
$self->{dbh}; |
$self->{dbh}; |
66 |
my $flags; |
my $flags; |
67 |
if ($self->{mode} & O_RDWR) { |
if ($self->{mode} & O_RDWR) { |
68 |
$flags = DB_CREATE; # | DB_INIT_MPOOL | DB_INIT_CDB; |
$flags = DB_CREATE; # | DB_INIT_MPOOL | DB_INIT_CDB; |
69 |
# warn "Flags on index $file set to 'writing'"; |
# warn "Flags on index $path set to 'writing'"; |
70 |
} else { |
} else { |
71 |
$flags = DB_RDONLY; |
$flags = DB_RDONLY; |
72 |
# warn "Flags on index $file set to 'readonly'"; |
# warn "Flags on index $path set to 'readonly'"; |
73 |
} |
} |
74 |
$self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree', |
$self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree', |
75 |
# Filename => $file, |
# Filename => $path, |
76 |
Filename => $self->maindbfile, |
Filename => $self->maindbfile, |
77 |
$self->{env} ? (Env => $self->{env}) : (), |
$self->{env} ? (Env => $self->{env}) : (), |
78 |
Subname => join("/",$self->tablename,$self->subname), |
Subname => join("/",$self->tablename,$self->subname), |
148 |
if ($self->{dbh}) { |
if ($self->{dbh}) { |
149 |
delete $self->{dbh}; |
delete $self->{dbh}; |
150 |
untie %{$self->{db}}; |
untie %{$self->{db}}; |
151 |
for my $att (qw(db file maindbfile)) { |
for my $att (qw(db path maindbfile)) { |
152 |
delete $self->{$att}; |
delete $self->{$att}; |
153 |
} |
} |
154 |
} |
} |