/[wait]/trunk/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

Diff of /trunk/lib/WAIT/Index.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 113 by dpavlin, Tue Jul 13 17:41:12 2004 UTC revision 114 by dpavlin, Tue Jul 13 21:27:27 2004 UTC
# Line 26  sub new { Line 26  sub new {
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");
# Line 48  for my $accessor (qw(maindbfile tablenam Line 48  for my $accessor (qw(maindbfile tablenam
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");
# Line 58  sub drop { Line 58  sub drop {
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};
# Line 66  sub open { Line 66  sub open {
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),
# Line 148  sub close { Line 148  sub close {
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    }    }

Legend:
Removed from v.113  
changed lines
  Added in v.114

  ViewVC Help
Powered by ViewVC 1.1.26