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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sat Apr 17 04:15:39 2004 UTC (22 years, 3 months ago) by wakaba
Branch: MAIN
Branch point for: paragraph-200404
Changes since 1.1: +7 -2 lines
Count.pm: New

1 wakaba 1.1
2     =head1 NAME
3    
4     SuikaWiki::DB::FileSystem::Base
5    
6     =head1 SYNOPSIS
7    
8     package Example::WikiDBModule;
9     push our @ISA, 'SuikaWiki::DB::FileSystem::Base';
10    
11     sub ... {
12    
13     }
14    
15     ...
16    
17     =head1 DESCRIPTION
18    
19    
20    
21     This module is part of SuikaWiki.
22    
23     =cut
24    
25     package SuikaWiki::DB::FileSystem::LeafFile;
26     use strict;
27 wakaba 1.2 our $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
28 wakaba 1.1 require SuikaWiki::DB::FileSystem::Base;
29     push our @ISA, 'SuikaWiki::DB::FileSystem::Base';
30     use IO::File;
31    
32     sub get ($$$;%) {
33     my ($self, $prop, $key, %opt) = @_;
34     report SuikaWiki::DB::Util::Error
35     -type => 'KEY_INVALID_NAME', key => $key,
36     -object => $self, method => 'get'
37     unless $opt{no_key_check} or
38     $self->__check_key (key => $key);
39    
40     unless ($self->{opened}->{$prop}) {
41     local $Error::Depth = $Error::Depth + 1;
42     $self->open_prop (prop => $prop);
43     }
44    
45     my $path = $self->__key2filepath (key => $key);
46    
47     if (-e $path) {
48     my $file = new IO::File $path, '<'
49     or report SuikaWiki::DB::Util::Error
50     -type => 'FILE_READ_FAILURE',
51     -object => $self, method => 'get',
52     file => $path, msg => $!;
53     binmode $file;
54     local $/ = undef;
55     return scalar <$file>;
56     } else {
57     return undef;
58     }
59     }
60    
61     sub set ($$$$;%) {
62     my ($self, $prop, $key, $val, %opt) = @_;
63 wakaba 1.2 report SuikaWiki::DB::Util::Error
64     -type => 'KEY_INVALID_NAME', key => $key,
65     -object => $self, method => 'set'
66     unless $opt{no_key_check} or
67     $self->__check_key (key => $key);
68 wakaba 1.1
69     unless ($self->{opened}->{$prop}) {
70     local $Error::Depth = $Error::Depth + 1;
71     $self->open_prop (prop => $prop);
72     }
73    
74     if ($self->{lock} and not $self->{lock}->writable) {
75     report SuikaWiki::DB::Util::Error
76     -type => 'KEY_SAVE_LOCKED',
77     -object => $self, method => 'set',
78     key => $key,
79     prop => $prop;
80     return 0;
81     }
82    
83     $self->__make_directory (directory => $self->__key2dirpath (fullkey => $key));
84     my $path = $self->__key2filepath (key => $key);
85     my $file = new IO::File $path, '>'
86     or report SuikaWiki::DB::Util::Error
87     -type => 'FILE_WRITE_FAILURE',
88     -object => $self, method => 'set',
89     file => $path, msg => $!;
90     binmode $file;
91     print $file $val;
92     close $file;
93     1;
94     }
95    
96     =head1 LICENSE
97    
98     Copyright 2004 Wakaba <[email protected]>. All rights reserved.
99    
100     This program is free software; you can redistribute it and/or
101     modify it under the same terms as Perl itself.
102    
103     =cut
104    
105 wakaba 1.2 1; # $Date: 2004/04/02 04:32:26 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24