| 1 |
wakaba |
1.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 |
wakaba |
1.3 |
our $VERSION=do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 20 |
wakaba |
1.1 |
|
| 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 |
wakaba |
1.3 |
|
| 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 |
wakaba |
1.1 |
|
| 41 |
|
|
=cut |
| 42 |
|
|
|
| 43 |
|
|
sub new ($%) { |
| 44 |
wakaba |
1.3 |
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 |
wakaba |
1.1 |
} |
| 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 |
wakaba |
1.2 |
Returns whether readable or not. |
| 78 |
wakaba |
1.1 |
|
| 79 |
|
|
=item 1/0 = $locker->writable () |
| 80 |
|
|
|
| 81 |
wakaba |
1.2 |
Returns whether writable or not. |
| 82 |
|
|
|
| 83 |
|
|
=item 1/0 = $locker->appendable |
| 84 |
|
|
|
| 85 |
|
|
Returns whether line-appendable or not. |
| 86 |
wakaba |
1.1 |
|
| 87 |
|
|
=item 1/0 = $locker->locked () |
| 88 |
|
|
|
| 89 |
|
|
Returns whether locked or not. |
| 90 |
|
|
|
| 91 |
|
|
=cut |
| 92 |
|
|
|
| 93 |
wakaba |
1.3 |
sub readable ($) { shift->{option}->{readable} } |
| 94 |
|
|
sub writable ($) { shift->{option}->{writable} } |
| 95 |
|
|
sub appendable ($) { shift->{option}->{appendable} } |
| 96 |
wakaba |
1.1 |
|
| 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 |
wakaba |
1.3 |
1; # $Date: 2004/04/02 04:32:48 $ |