1 |
# -*- Mode: Perl -*- |
2 |
# $Basename$ |
3 |
# $Revision: 1.2 $ |
4 |
# Author : Marc Lehmann |
5 |
# Created On : June 2000 |
6 |
# Last Modified By: Ulrich Pfeifer |
7 |
# Last Modified On: Fri Dec 29 12:56:35 2000 |
8 |
# Language : CPerl |
9 |
|
10 |
package WAIT::Document::Multi; |
11 |
|
12 |
use WAIT::Document::Base; |
13 |
use base 'WAIT::Document::Base'; |
14 |
|
15 |
=head1 NAME |
16 |
|
17 |
WAIT::Document::Multi - access class that joins multiple access objects into a single one |
18 |
|
19 |
=head1 SYNOPSIS |
20 |
|
21 |
use WAIT::Document::Multi; |
22 |
|
23 |
tie %acc, WAIT::Document::Multi::, |
24 |
access1 => <first access object>, |
25 |
access2 => <second acces sobject>; |
26 |
|
27 |
=head1 DESCRIPTION |
28 |
|
29 |
This WAIT access class accepts any number of "domain name" => "access |
30 |
object" pairs and creates a unified view over all of these access objects. |
31 |
|
32 |
The access objects must be actual objects, not tied hash references. |
33 |
|
34 |
The document id's are generated by appending the domain name, a binary |
35 |
zero and the document id of the underlying access object. |
36 |
|
37 |
=cut |
38 |
|
39 |
sub new { |
40 |
my $class = shift, |
41 |
my %unused; |
42 |
tie %unused, $class, @_; |
43 |
} |
44 |
|
45 |
sub TIEHASH { |
46 |
my $type = shift; |
47 |
my %acc = @_; |
48 |
my ($fst, %nxt); |
49 |
for (keys %acc) { |
50 |
$nxt{$_} = $fst; $fst = $_; |
51 |
} |
52 |
bless { |
53 |
acc => \%acc, |
54 |
fst => $fst, |
55 |
nxt => \%nxt, |
56 |
}, ref $type || $type; |
57 |
} |
58 |
|
59 |
sub FETCH { |
60 |
my $self = shift; |
61 |
my ($dom, $key) = split /\x00/, shift, 2; |
62 |
$self->{acc}{$dom}->FETCH($key); |
63 |
} |
64 |
|
65 |
sub FIRSTKEY { |
66 |
my $self = shift; |
67 |
my $dom = $self->{fst}; |
68 |
"$dom\x00".$self->{acc}{$dom}->FIRSTKEY; |
69 |
} |
70 |
|
71 |
sub NEXTKEY { |
72 |
my $self = shift; |
73 |
my ($dom, $key) = split /\x00/, shift, 2; |
74 |
my $nxt = $self->{acc}{$dom}->NEXTKEY($key); |
75 |
unless ($nxt) { |
76 |
$dom = $self->{nxt}{$dom}; |
77 |
return unless $dom; |
78 |
$nxt = $self->{acc}{$dom}->FIRSTKEY; |
79 |
} |
80 |
"$dom\x00$nxt"; |
81 |
} |
82 |
|
83 |
=head1 AUTHOR |
84 |
|
85 |
Marc Lehmann <pcg@goof.com> |
86 |
http://www.goof.com/pcg/marc/ |
87 |
|
88 |
=cut |
89 |
|
90 |
1; |
91 |
|