15 |
|
# items() : return the number of seperate items in the store |
16 |
|
# store(filename) : dump to file |
17 |
|
# restore(filename) : restore from file |
18 |
+ |
# alias(\@refofkeys,\@aliaskeys) : attatch another set of keys to items that |
19 |
+ |
# match the refopfkeys |
20 |
+ |
# note that these are references to the arrays |
21 |
+ |
# unalias(@aliaskeys) :remove an alias |
22 |
|
|
23 |
|
package Utilities::HashDB; |
24 |
|
use Utilities::DataItem; |
41 |
|
push @{$self->{dataitems}}, Utilities::DataItem->new($data, @keys); |
42 |
|
} |
43 |
|
|
44 |
+ |
sub alias { |
45 |
+ |
my $self=shift; |
46 |
+ |
my $keyref=shift; |
47 |
+ |
my $aliaskeys=shift; |
48 |
+ |
|
49 |
+ |
my @objs=$self->match(@{$keyref}); |
50 |
+ |
foreach $obj ( @objs ) { |
51 |
+ |
print "$obj @_\n"; |
52 |
+ |
$obj->alias(@{$aliaskeys}); |
53 |
+ |
} |
54 |
+ |
} |
55 |
+ |
|
56 |
+ |
sub unalias { |
57 |
+ |
my $self=shift; |
58 |
+ |
my @keys=@_; |
59 |
+ |
|
60 |
+ |
my @objs=$self->match(@keys); |
61 |
+ |
foreach $obj ( @objs ) { |
62 |
+ |
$obj->unalias(@_); |
63 |
+ |
} |
64 |
+ |
} |
65 |
+ |
|
66 |
|
sub items { |
67 |
|
my $self=shift; |
68 |
|
return $#{$self->{dataitems}}; |
109 |
|
my $filename=shift; |
110 |
|
|
111 |
|
my $fh=FileHandle->new(); |
112 |
+ |
$fh->autoflush(1); |
113 |
|
open ($fh, ">$filename") or die "Unable to open file $filename\n $!\n"; |
114 |
|
foreach $object ( @{$self->{dataitems}} ) { |
115 |
< |
my $temp=join '::', $object->keys(); |
116 |
< |
$temp=$object->data()."::".$temp; |
90 |
< |
print $fh $temp."\n"; |
115 |
> |
print $fh "\n"; |
116 |
> |
$object->store($fh); |
117 |
|
} |
118 |
|
close $fh; |
119 |
|
} |
121 |
|
sub restore { |
122 |
|
my $self=shift; |
123 |
|
my $filename=shift; |
124 |
< |
my @arr; |
124 |
> |
my @arr=(); |
125 |
> |
my $data; |
126 |
|
|
127 |
|
my $fh=FileHandle->new(); |
128 |
|
open ($fh, "<$filename") or die "Unable to open file $filename\n $!\n"; |
129 |
|
while ( <$fh> ) { |
130 |
< |
next if /^#/; |
104 |
< |
@arr=split ':', $_; |
105 |
< |
$self->setdata(@arr); |
130 |
> |
push @{$self->{dataitems}}, Utilities::DataItem->restore($fh); |
131 |
|
} |
132 |
|
close $fh; |
133 |
|
} |