1 |
# -*- Mode: Perl -*- |
# -*- Mode: Cperl -*- |
2 |
# Index.pm -- |
# Index.pm -- |
3 |
# ITIID : $ITI$ $Header $__Header$ |
# ITIID : $ITI$ $Header $__Header$ |
4 |
# Author : Ulrich Pfeifer |
# Author : Ulrich Pfeifer |
18 |
use DB_File; |
use DB_File; |
19 |
use Fcntl; |
use Fcntl; |
20 |
|
|
|
sub fail { |
|
|
$@ .= join "\n", @_; |
|
|
return undef; |
|
|
} |
|
|
|
|
21 |
sub new { |
sub new { |
22 |
my $type = shift; |
my $type = shift; |
23 |
my %parm = @_; |
my %parm = @_; |
24 |
my $self = {}; |
my $self = {}; |
25 |
|
|
26 |
$self->{file} = $parm{file} or return fail("No file specified"); |
unless ($self->{file} = $parm{file}) { |
27 |
$self->{attr} = $parm{attr} or return fail("No attributes specified"); |
require Carp; |
28 |
|
Carp::croak("No file specified"); |
29 |
|
} |
30 |
|
unless ($self->{attr} = $parm{attr}) { |
31 |
|
require Carp; |
32 |
|
Carp::croak("No attributes specified"); |
33 |
|
} |
34 |
bless $self, ref($type) || $type; |
bless $self, ref($type) || $type; |
35 |
} |
} |
36 |
|
|
38 |
my $self = shift; |
my $self = shift; |
39 |
if ((caller)[0] eq 'WAIT::Table') { # Table knows about this |
if ((caller)[0] eq 'WAIT::Table') { # Table knows about this |
40 |
my $file = $self->{file}; |
my $file = $self->{file}; |
|
|
|
41 |
! (!-e $file or unlink $file); |
! (!-e $file or unlink $file); |
42 |
} else { # notify our database |
} else { # notify our database |
43 |
fail ref($self)."::drop called directly"; |
require Carp; |
44 |
|
Carp::croak(ref($self)."::drop called directly"); |
45 |
} |
} |
46 |
} |
} |
47 |
|
|
88 |
my $self = shift; |
my $self = shift; |
89 |
my %parm = @_; |
my %parm = @_; |
90 |
my @keys = @{$self->{attr}->[0]}; |
my @keys = @{$self->{attr}->[0]}; |
91 |
|
|
92 |
defined $self->{db} or $self->open; |
defined $self->{db} or $self->open; |
93 |
|
|
94 |
my $key = join($;, map($parm{$_}, @keys)); |
my $key = join($;, map($parm{$_}, @keys)); |
103 |
defined $self->{db} or $self->open; |
defined $self->{db} or $self->open; |
104 |
|
|
105 |
my $tuple = join($;, map($parm{$_}, @{$self->{attr}})); |
my $tuple = join($;, map($parm{$_}, @{$self->{attr}})); |
106 |
|
|
107 |
delete $self->{db}->{$tuple}; |
delete $self->{db}->{$tuple}; |
108 |
} |
} |
109 |
|
|
129 |
sub open_scan { |
sub open_scan { |
130 |
my $self = shift; |
my $self = shift; |
131 |
my $code = shift; |
my $code = shift; |
132 |
|
|
133 |
$self->{dbh} or $self->open; |
$self->{dbh} or $self->open; |
134 |
new WAIT::IndexScan $self, $code; |
new WAIT::IndexScan $self, $code; |
135 |
} |
} |