/[pub]/suikawiki/script/lib/SuikaWiki/DB/FileSystem/YukiWikiDBNS.pm
Suika

Contents of /suikawiki/script/lib/SuikaWiki/DB/FileSystem/YukiWikiDBNS.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Sat Dec 6 02:20:07 2003 UTC (22 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +74 -50 lines
Now subclass of Util::template

1 wakaba 1.1
2     =head1 NAME
3    
4     SuikaWiki::DB::FileSystem::YukiWikiDBNS --- SuikaWiki WikiDatabase: WikiDatabase interface wrapper for Yuki::YukiWikiDBNS
5    
6     =head1 DESCRIPTION
7    
8     This module wrappes Yuki::YukiWikiDBNS (directory structuring extended
9     version of Yuki::YukiWikiDB2) for WikiDatabase common interface of
10     SuikaWiki.
11    
12     This module is part of SuikaWiki.
13    
14     =cut
15    
16     package SuikaWiki::DB::FileSystem::YukiWikiDBNS;
17 wakaba 1.2 use strict;
18 wakaba 1.6 our $VERSION = do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
19 wakaba 1.1 require SuikaWiki::DB::Util;
20     require Yuki::YukiWikiDBNS;
21 wakaba 1.6 push our @ISA, 'SuikaWiki::DB::Util::template';
22 wakaba 1.1 my $Self = '.';
23     my $Parent = '..';
24     my $Sep = '//';
25     my $DB_Module = q(Yuki::YukiWikiDBNS);
26    
27     sub new ($%) {
28 wakaba 1.6 my $self = shift->SUPER::new (@_);
29     $self->{option} = {@_};
30     $self;
31     }
32    
33     sub ___open_prop ($$) {
34     my ($self, $opt) = @_;
35     return "0 but true" if defined $self->{db_instance};
36     local $Error::Depth = $Error::Depth + 1;
37 wakaba 1.1 my %db;
38 wakaba 1.6 $self->{db_instance} = tie (%db, $DB_Module => $self->{option}->{directory},
39 wakaba 1.3 -lock => 0, ## Yuki::YukiWikiDBNS's lock is buggy
40 wakaba 1.6 -backup => $self->{option}->{use_history},
41     -logfile => $self->{option}->{logfile},
42     -extension => $self->{option}->{suffix},
43 wakaba 1.1 )
44 wakaba 1.6 or report SuikaWiki::DB::Util::Error
45     -type => 'DB_OPEN',
46     -object => $self, method => q(new),
47     file => $self->{option}->{directory};
48 wakaba 1.1 $self->{db_hash} = \%db;
49 wakaba 1.6 1;
50 wakaba 1.1 }
51    
52     sub get ($$$) {
53     my ($self, $prop, $key) = @_;
54 wakaba 1.6 unless ($self->{opened}->{$prop}) {
55     local $Error::Depth = $Error::Depth + 1;
56     $self->open_prop (prop => $prop);
57     }
58 wakaba 1.2 $self->{db_hash}->{ $self->__name2name ($key) };
59 wakaba 1.1 }
60    
61     sub set ($$$$) {
62     my ($self, $prop, $key => $value) = @_;
63 wakaba 1.6 unless ($self->{opened}->{$prop}) {
64     local $Error::Depth = $Error::Depth + 1;
65     $self->open_prop (prop => $prop);
66     }
67     if (not $self->{lock} or $self->{lock}->writable) {
68 wakaba 1.3 $self->{db_hash}->{ $self->__name2name ($key) } = $value;
69     } else {
70 wakaba 1.6 report SuikaWiki::DB::Util::Error
71     -type => 'KEY_SAVE_LOCKED',
72     -object => $self, method => 'set',
73     key => $key,
74     prop => $prop;
75 wakaba 1.3 }
76 wakaba 1.1 }
77    
78     sub exist ($$$) {
79     my ($self, $prop, $key) = @_;
80 wakaba 1.6 unless ($self->{opened}->{$prop}) {
81     local $Error::Depth = $Error::Depth + 1;
82     $self->open_prop (prop => $prop);
83     }
84 wakaba 1.5 CORE::exists $self->{db_hash}->{ $self->__name2name ($key) };
85 wakaba 1.1 }
86    
87     sub delete ($$$) {
88     my ($self, $prop, $key) = @_;
89 wakaba 1.6 unless ($self->{opened}->{$prop}) {
90     local $Error::Depth = $Error::Depth + 1;
91     $self->open_prop (prop => $prop);
92     }
93     if (not $self->{lock} or $self->{lock}->writable) {
94 wakaba 1.5 CORE::delete $self->{db_hash}->{ $self->__name2name ($key) };
95 wakaba 1.3 } else {
96 wakaba 1.6 report SuikaWiki::DB::Util::Error
97     -type => 'KEY_SAVE_LOCKED',
98     -object => $self, method => 'delete',
99     key => $key,
100     prop => $prop;
101 wakaba 1.3 }
102 wakaba 1.1 }
103    
104     sub keys ($$;%) {
105     my ($self, $prop, %opt) = @_;
106 wakaba 1.6 unless ($self->{opened}->{$prop}) {
107     local $Error::Depth = $Error::Depth + 1;
108     $self->open_prop (prop => $prop);
109     }
110     map {[split /\Q$Sep\E/o, $_]}
111 wakaba 1.3 $self->{db_instance}->list_items ({ns => $self->__name2ns ($opt{-ns}||[]),
112     type => ($opt{-type} eq 'ns'?'ns':'key'),
113     recursive => $opt{-recursive}});
114 wakaba 1.1 }
115    
116     sub __name2name ($$) {
117     my ($self, $key) = @_;
118 wakaba 1.6 local $Error::Depth = $Error::Depth + 1;
119     report SuikaWiki::DB::Util::Error
120     type => 'KEY_INVALID_NAME', -key => $key,
121     -object => $self, method => '__name2name',
122 wakaba 1.3 unless $self->__check_name ($key);
123 wakaba 1.6 join $Sep, @$key;
124 wakaba 1.1 }
125    
126     sub __name2ns ($$) {
127     my ($self, $key) = @_;
128 wakaba 1.3 return '' if scalar @$key == 0 || (scalar @$key == 1 && $key->[0] eq '');
129 wakaba 1.6 local $Error::Depth = $Error::Depth + 1;
130     report SuikaWiki::DB::Util::Error
131     type => 'KEY_INVALID_NS_NAME', -key => $key,
132     -object => $self, method => '__name2ns'
133 wakaba 1.3 unless $self->__check_name ($key);
134 wakaba 1.1 $key = $self->__name2name ($key) . $Sep;
135 wakaba 1.3 $key eq $Sep ? undef : $key;
136 wakaba 1.1 }
137    
138     sub __check_name ($$) {
139     my ($self, $key) = @_;
140 wakaba 1.5 return 0 unless ref $key;
141 wakaba 1.1 for (@$key) {
142     return 0 unless $_; # '' or 0 or undef
143     return 0 if index ($_, $Sep) > -1;
144     return 0 if $_ eq $Self || $_ eq $Parent;
145     }
146     return 1;
147     }
148    
149 wakaba 1.6 sub ___close_prop ($$) {
150     # no-op
151     }
152    
153     sub close ($;%) {
154 wakaba 1.1 my $self = shift;
155     untie %{$self->{db_hash}};
156 wakaba 1.6 delete $self->{db_instance};
157     delete $self->{db_hash};
158     delete $self->{opened};
159 wakaba 1.3 $self->{lock}->unlock if $self->{lock};
160 wakaba 1.6 report SuikaWiki::DB::Util::Error
161     -type => 'DB_CLOSED',
162     -object => $self, method => 'close';
163 wakaba 1.1 }
164    
165     =head1 METHODS
166    
167     This module provides common interface of SuikaWiki WikiDatabase
168     modules. See C<SuikaWiki::DB>.
169    
170     =head2 CONSTRUCTOR'S OPTIONS
171    
172     @@ TBD
173    
174     =head1 AUTHOR
175    
176     Wakaba <[email protected]>.
177    
178     =head1 LICENSE
179    
180     Copyright 2003 Wakaba <[email protected]>
181    
182     This program is free software; you can redistribute it and/or
183     modify it under the same terms as Perl itself.
184    
185     =cut
186    
187 wakaba 1.6 1; # $Date: 2003/12/01 07:44:51 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24