/[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.2 - (hide annotations) (download)
Wed Aug 6 02:54:40 2003 UTC (23 years, 1 month ago) by wakaba
Branch: MAIN
Branch point for: branch-suikawiki-1
Changes since 1.1: +14 -13 lines
Minor but important bug fixes

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24