/[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.1 - (hide annotations) (download)
Wed Aug 6 01:26:14 2003 UTC (23 years, 1 month ago) by wakaba
Branch: MAIN
New or bug fix

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     require SuikaWiki::DB::Util;
18     require Yuki::YukiWikiDBNS;
19     my $Self = '.';
20     my $Parent = '..';
21     my $Sep = '//';
22     my $DB_Module = q(Yuki::YukiWikiDBNS);
23    
24     sub new ($%) {
25     my ($class, %o) = @_;
26     my $self = bless {}, $class;
27     if ($o{-lock}) {
28     $self->{lock} = SuikaWiki::DB::Util->new_lock ($self->{lock});
29     $self->{lock}->lock;
30     }
31     $self->{error} = SuikaWiki::DB::Util->error_handler;
32     my %db;
33     $self->{db_instance} = tie (%db, $DB_Module => $o{directory},
34     -lock => 0,
35     -backup => $o{use_history},
36     -logfile => $o{logfile},
37     -extension => $o{suffix},
38     )
39     or &{$self->{-error_handler}} (level => 'fatal',
40     method => q(new),
41     file => $o{directory},
42     msg => qq(Can't open database));
43     $self->{db_hash} = \%db;
44     $self;
45     }
46    
47     sub get ($$$) {
48     my ($self, $prop, $key) = @_;
49     $self->{db_hash}->{ $self->__name2name ($record) };
50     }
51    
52     sub set ($$$$) {
53     my ($self, $prop, $key => $value) = @_;
54     $self->{db_hash}->{ $self->__name2name ($record) } = $value;
55     }
56    
57     sub exist ($$$) {
58     my ($self, $prop, $key) = @_;
59     exist $self->{db_hash}->{ $self->__name2name ($record) };
60     }
61    
62     sub delete ($$$) {
63     my ($self, $prop, $key) = @_;
64     delete $self->{db_hash}->{ $self->__name2name ($record) };
65     }
66    
67     sub keys ($$;%) {
68     my ($self, $prop, %opt) = @_;
69     $self->{db_instance}->list_items (ns => $self->__name2ns ($opt{ns}),
70     type => $opt{type},
71     recursive => $opt{recursive});
72     }
73    
74     sub __name2name ($$) {
75     my ($self, $key) = @_;
76     $self->{error}->raise (type => 'KEY_INVALID_NAME', key => $key)
77     if $self->__check_name ($key);
78     join '//', @$key;
79     }
80    
81     sub __name2ns ($$) {
82     my ($self, $key) = @_;
83     $self->{error}->raise (type => 'KEY_INVALID_NS_NAME', key => $key)
84     if $self->__check_name ($key);
85     $key = $self->__name2name ($key) . $Sep;
86     }
87    
88     sub __check_name ($$) {
89     my ($self, $key) = @_;
90     for (@$key) {
91     return 0 unless $_; # '' or 0 or undef
92     return 0 if index ($_, $Sep) > -1;
93     return 0 if $_ eq $Self || $_ eq $Parent;
94     }
95     return 1;
96     }
97    
98     sub close ($) {
99     my $self = shift;
100     untie %{$self->{db_hash}};
101     $self->{db_instance} = undef;
102     $self->{db_hash} = undef;
103     }
104    
105     sub DESTROY ($) {
106     my $self = shift;
107     $self->close if $self->{db_instance};
108     }
109    
110     =head1 METHODS
111    
112     This module provides common interface of SuikaWiki WikiDatabase
113     modules. See C<SuikaWiki::DB>.
114    
115     =head2 CONSTRUCTOR'S OPTIONS
116    
117     @@ TBD
118    
119     =head1 AUTHOR
120    
121     Wakaba <[email protected]>.
122    
123     =head1 LICENSE
124    
125     Copyright 2003 Wakaba <[email protected]>
126    
127     This program is free software; you can redistribute it and/or
128     modify it under the same terms as Perl itself.
129    
130     =cut
131    
132     1; # $Date: $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24