/[wait]/cvs-head/lib/WAIT/IndexScan.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/IndexScan.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Fri Apr 28 15:41:10 2000 UTC (24 years ago) by unknown
Original Path: branches/CPAN/lib/WAIT/IndexScan.pm
File size: 1965 byte(s)
This commit was manufactured by cvs2svn to create branch 'CPAN'.
1 ulpfr 10 # -*- Mode: Perl -*-
2     # IndexScan.pm --
3     # ITIID : $ITI$ $Header $__Header$
4     # Author : Ulrich Pfeifer
5     # Created On : Mon Aug 12 14:05:14 1996
6     # Last Modified By: Ulrich Pfeifer
7     # Last Modified On: Sun Nov 22 18:44:43 1998
8     # Language : CPerl
9     # Update Count : 65
10     # Status : Unknown, Use with caution!
11     #
12     # Copyright (c) 1996-1997, Ulrich Pfeifer
13     #
14    
15     package WAIT::IndexScan;
16    
17     use strict;
18     use DB_File;
19     use Fcntl;
20    
21     sub fail {
22     $@ .= join "\n", @_;
23     return undef;
24     }
25    
26     sub new {
27     my $type = shift;
28     my $index = shift;
29     my $code = shift;
30     my ($first, $tid) = ('', '');
31    
32     # find the first key
33     $index->{dbh}->seq($first, $tid, R_FIRST)
34     and return fail("Could not open scan");
35     # Not sure about this. R_FIRST sets $tid to no-of-records?
36     # $index->{dbh}->seq($first, $tid, R_NEXT);
37     # register to avoid unnecessary position calls
38     $index->{scans}++;
39    
40     bless {Index => $index, code => $code,
41     nextk => $first, tid => $tid}, $type or ref($type);
42     }
43    
44     sub next {
45     my $self = shift;
46     my $dbh = $self->{Index}->{dbh};
47     my ($key, $tid, $ntid);
48    
49     if (defined $self->{nextk}) {
50     fail("Cannot scan closed index"),return unless $dbh;
51     $key = $self->{nextk};
52    
53     if ($self->{Index}->{scans} > 1) {
54     # Another scan is open. Reset the cursor
55     $dbh->seq($key, $tid, R_CURSOR);
56     } else {
57     $tid = $self->{tid};
58     }
59     if ($dbh->seq($self->{nextk}, $self->{tid}, R_NEXT)) {
60     # current tuple is last one
61     delete $self->{nextk};
62     }
63    
64     my @tuple = split /$;/, $key;
65     my %tuple = (_id => $tid);
66     for (@{$self->{Index}->{attr}}) {
67     $tuple{$_} = shift @tuple;
68     }
69    
70     if ($self->{code}) { # test condition
71     &{$self->{code}}(\%tuple)? %tuple : $self->next;
72     } else {
73     %tuple;
74     }
75     } else {
76     return;
77     }
78     }
79    
80     sub close { undef $_[0]} # force DESTROY
81     sub DESTROY {
82     shift->{Index}->{scans}--;
83     }
84    
85     1;

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26