7 # (c) 2004 Straylight/Edgeware
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of the Perl interface to Catacomb.
14 # Catacomb/Perl is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # Catacomb/Perl is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with Catacomb/Perl; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #----- Key data -------------------------------------------------------------
30 package Catacomb
::Key
::Data
::StructTie
;
34 sub TIEHASH
{ bless [$_[1], []], $_[0]; }
35 sub FETCH
{ $_[0][0]->find($_[1]); }
36 sub EXISTS
{ !!$_[0][0]->find($_[1]); }
37 sub DELETE
{ $_[0][0]->del($_[1]); }
38 sub STORE
{ $_[0][0]->find($_[1], $_[2]); }
43 my $i = $kd->iterate();
44 $kd->del($k) while my $k = $i->next();
51 my $i = $kd->iterate();
53 while (my $k = $i->next()) {
59 sub NEXTKEY
{ shift(@
{$_[0][1]}); }
61 package Catacomb
::Key
::Data
::Structured
;
62 sub open { my %h; tie
%h, Catacomb
::Key
::Data
::StructTie
, $_[0]; \
%h; }
64 foreach $i (qw(Binary Encrypted MP EC String Structured
)) {
65 @
{"Catacomb::Key::Data::${i}::ISA"} = qw(Catacomb
::Key
::Data
);
68 #----- Actual keys ----------------------------------------------------------
70 package Catacomb
::Key
::Attrs
;
73 sub TIEHASH
{ bless [$_[1], []], $_[0]; }
74 sub FETCH
{ $_[0][0]->getattr($_[1]); }
75 sub EXISTS
{ defined($_[0][0]->getattr($_[1])); }
76 sub STORE
{ $_[0][0]->putattr($_[1], $_[2]); }
77 sub DELETE
{ $_[0][0]->putattr($_[1]); }
81 my $i = $k->attriter();
83 while (my $a = $i->next()) { push(@a, $a); }
87 sub NEXTKEY
{ shift(@
{$_[0][1]}); }
89 package Catacomb
::Key
;
92 croak
("Usage: Catacomb::Key::attrs(k)") unless @_ == 1;
94 tie
%a, Catacomb
::Key
::Attrs
, @_;
98 #----- That's all, folks ----------------------------------------------------