/[pub]/suikawiki/script/lib/SuikaWiki/DB/Lock/NoLock.pm
Suika

Contents of /suikawiki/script/lib/SuikaWiki/DB/Lock/NoLock.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Mon Apr 5 06:09:23 2004 UTC (22 years, 3 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, release-3-0-0, HEAD
Branch point for: paragraph-200404, helowiki, helowiki-2005
Changes since 1.2: +23 -8 lines
Customizable -able

1
2 =head1 NAME
3
4 SuikaWiki::DB::Lock::NoLock - SuikaWiki: "No lock" Locking Implementation
5
6 =head1 DESCRIPTION
7
8 C<SuikaWiki::DB::Lock::NoLock> implements locking interface that
9 actually make nothing done. This module can be used in context where
10 SuikaWiki WikiDB interface requires some lock module implementation
11 but locking is not necessary (or not preferred).
12
13 This module is part of SuikaWiki.
14
15 =cut
16
17 package SuikaWiki::DB::Lock::NoLock;
18 use strict;
19 our $VERSION=do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
20
21 =head1 METHODS
22
23 =over 4
24
25 =item $locker = SuikaWiki::DB::Lock::NoLock->new (%options)
26
27 Generates a new instance of this module.
28
29 Options:
30
31 =over 4
32
33 =item appendable => 1/0 (Default 1)
34
35 =item readable => 1/0 (Default 1)
36
37 =item writable => 1/0 (Default 0)
38
39 =back
40
41 =cut
42
43 sub new ($%) {
44 my $self = bless {}, shift;
45 my %opt = @_;
46 $self->{option}->{readable} = defined $opt{readable} ? $opt{readable} : 1;
47 $self->{option}->{writable} = defined $opt{writable} ? $opt{writable} : 0;
48 $self->{option}->{appendable} = defined $opt{appendable} ? $opt{appendable} : 1;
49 $self;
50 }
51
52 =item 1/0 = $locker->lock ()
53
54 Lock. Returns C<1> if lock is successed. Otherwise C<0> is returned.
55
56 =cut
57
58 sub lock ($) {
59 my $self = shift;
60 $self->{locked} ? 1 : "0 but true";
61 }
62
63 =item 1/0 = $locker->unlock ()
64
65 Unlock. Returns C<1> if unlock is success. C<-1> if lock file is
66 lost. Otherwise C<0> is returned.
67
68 =cut
69
70 sub unlock ($) {
71 my $self = shift;
72 $self->{locked} ? 1 : "0 but true";
73 }
74
75 =item 1/0 = $locker->readable ()
76
77 Returns whether readable or not.
78
79 =item 1/0 = $locker->writable ()
80
81 Returns whether writable or not.
82
83 =item 1/0 = $locker->appendable
84
85 Returns whether line-appendable or not.
86
87 =item 1/0 = $locker->locked ()
88
89 Returns whether locked or not.
90
91 =cut
92
93 sub readable ($) { shift->{option}->{readable} }
94 sub writable ($) { shift->{option}->{writable} }
95 sub appendable ($) { shift->{option}->{appendable} }
96
97 sub locked ($) { "0 but true" }
98
99 =head1 EXAMPLE
100
101 require SuikaWiki::DB::Lock::NoLock;
102 my $locker = SuikaWiki::DB::Lock::NoLock->new;
103
104 $locker->lock or die "Can't lock";
105
106 open DATA, 'foo.txt';
107 while (<DATA>) {
108 # something
109 }
110 close DATA;
111
112 open NEWDATA, '>', 'bar.txt';
113 # something
114 close NEWDATA;
115
116 $locker->unlock or die "Can't unlock";
117
118 =head1 SEE ALSO
119
120 SuikaWiki:"SuikaWiki//WikiDB"
121 <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki%2F%2FWikiDB>,
122 L<SuikaWiki::DB::Util::Lock>
123
124 =head1 LICENSE
125
126 Copyright 2003-2004 Wakaba <w@suika.fam.cx>. All rights reserved.
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 1; # $Date: 2004/04/02 04:32:48 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24