/[wait]/cvs-head/lib/WAIT/Index.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /cvs-head/lib/WAIT/Index.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (hide annotations)
Sun Nov 12 01:21:05 2000 UTC (23 years, 6 months ago) by laperla
File size: 2776 byte(s)
Index needs some $VERSION so that others can reliably say it was loaded

1 ulpfr 13 # -*- Mode: Cperl -*-
2 ulpfr 10 # Index.pm --
3     # ITIID : $ITI$ $Header $__Header$
4     # Author : Ulrich Pfeifer
5     # Created On : Thu Aug 8 13:05:10 1996
6     # Last Modified By: Ulrich Pfeifer
7     # Last Modified On: Sun Nov 22 18:44:43 1998
8     # Language : CPerl
9     # Update Count : 107
10     # Status : Unknown, Use with caution!
11     #
12     # Copyright (c) 1996-1997, Ulrich Pfeifer
13     #
14    
15     package WAIT::Index;
16     use WAIT::IndexScan;
17     use strict;
18     use DB_File;
19     use Fcntl;
20 laperla 29 use vars qw($VERSION);
21 ulpfr 10
22 laperla 29 $VERSION = "1.801"; # Table.pm tests if we are loaded by checking $VERSION
23    
24 ulpfr 10 sub new {
25     my $type = shift;
26     my %parm = @_;
27     my $self = {};
28    
29 ulpfr 13 unless ($self->{file} = $parm{file}) {
30     require Carp;
31     Carp::croak("No file specified");
32     }
33     unless ($self->{attr} = $parm{attr}) {
34     require Carp;
35     Carp::croak("No attributes specified");
36     }
37 ulpfr 10 bless $self, ref($type) || $type;
38     }
39    
40     sub drop {
41     my $self = shift;
42     if ((caller)[0] eq 'WAIT::Table') { # Table knows about this
43     my $file = $self->{file};
44     ! (!-e $file or unlink $file);
45 ulpfr 13 } else { # notify our database
46     require Carp;
47     Carp::croak(ref($self)."::drop called directly");
48 ulpfr 10 }
49     }
50    
51     sub open {
52     my $self = shift;
53     my $file = $self->{file};
54    
55     if (exists $self->{dbh}) {
56     $self->{dbh};
57     } else {
58     $self->{dbh} = tie(%{$self->{db}}, 'DB_File', $file,
59     $self->{mode}, 0664, $DB_BTREE);
60     }
61     }
62    
63     sub insert {
64     my $self = shift;
65     my $key = shift;
66     my %parm = @_;
67    
68     defined $self->{db} or $self->open;
69    
70     my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));
71    
72     if (exists $self->{db}->{$tuple}) {
73     # duplicate entry
74     return undef;
75     }
76     $self->{db}->{$tuple} = $key;
77     }
78    
79     sub have {
80     my $self = shift;
81     my %parm = @_;
82    
83     defined $self->{db} or $self->open;
84    
85     my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));
86    
87     exists $self->{db}->{$tuple} && $self->{db}->{$tuple};
88     }
89    
90     sub fetch {
91     my $self = shift;
92     my %parm = @_;
93     my @keys = @{$self->{attr}->[0]};
94 ulpfr 13
95 ulpfr 10 defined $self->{db} or $self->open;
96    
97     my $key = join($;, map($parm{$_}, @keys));
98     $self->{db}->{$key};
99     }
100    
101     sub delete {
102     my $self = shift;
103     my $key = shift;
104     my %parm = @_;
105    
106     defined $self->{db} or $self->open;
107    
108 ulpfr 19 my $tuple = join($;, map($parm{$_}||"", @{$self->{attr}}));
109 ulpfr 13
110 ulpfr 10 delete $self->{db}->{$tuple};
111     }
112    
113     sub sync {
114     my $self = shift;
115     $self->{dbh}->sync if $self->{dbh};
116     }
117    
118     sub close {
119     my $self = shift;
120    
121     delete $self->{scans} if defined $self->{scans};
122    
123     if ($self->{dbh}) {
124     delete $self->{dbh};
125     untie %{$self->{db}};
126     delete $self->{db};
127     }
128     }
129    
130     #sub DESTROY { $_[0]->close }
131    
132     sub open_scan {
133     my $self = shift;
134     my $code = shift;
135 ulpfr 13
136 ulpfr 10 $self->{dbh} or $self->open;
137     new WAIT::IndexScan $self, $code;
138     }
139    
140     1;

Properties

Name Value
cvs2svn:cvs-rev 1.2

  ViewVC Help
Powered by ViewVC 1.1.26