From 0b3515d47ca3e6ed0b420d045fa244ab5781858f Mon Sep 17 00:00:00 2001 From: fukachan Date: Sat, 24 Feb 2001 13:30:34 +0000 Subject: clean up documents on File:: --- fml/lib/File/SimpleLock.pm | 53 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'fml/lib/File/SimpleLock.pm') diff --git a/fml/lib/File/SimpleLock.pm b/fml/lib/File/SimpleLock.pm index 1afa0b3c..e15fdb24 100644 --- a/fml/lib/File/SimpleLock.pm +++ b/fml/lib/File/SimpleLock.pm @@ -11,6 +11,9 @@ package File::SimpleLock; use vars qw(%LockedFileHandle %FileIsLocked @ISA $Error); use strict; use Carp; +use File::Errors; + +@ISA = qw(File::Errors); =head1 NAME @@ -18,7 +21,7 @@ File::SimpleLock - simple lock by flock(2) =head1 SYNOPSIS - require File::SimpleLock; + use File::SimpleLock; my $lockobj = new File::SimpleLock; $lockobj->lock( { file => $lock_file } ) || croak "fail to lock"; @@ -28,17 +31,20 @@ File::SimpleLock - simple lock by flock(2) =head1 DESCRIPTION -File::SimpleLock.pm contains several interfaces for several files, +File::SimpleLock module contains several interfaces for several files, for example, Lockfiles, sysLock() (not yet implemented). -=item Lock( $message ) +=head1 METHODS -The argument is the message to Lock. +=head2 C -=cut +flock(2) for $args->{ file }; -require Exporter; -@ISA = qw(Exporter); +=head2 C + +unlock flock(2) for $args->{ file }; + +=cut # constants @@ -58,26 +64,12 @@ sub new } -sub _error_reason -{ - my $msg = @_; - $Error = $msg; -} - - -sub error -{ - my ($self) = @_; - $Error; -} - - sub lock { my ($self, $args) = @_; my $file = $args->{ file }; - _simple_flock($file); + $self->_simple_flock($file); } @@ -86,14 +78,14 @@ sub unlock my ($self, $args) = @_; my $file = $args->{ file }; - _simple_funlock($file); + $self->_simple_funlock($file); } sub _simple_flock { - my ($file) = @_; + my ($self, $file) = @_; use FileHandle; my $fh = new FileHandle $file; @@ -105,7 +97,7 @@ sub _simple_flock eval q{ $r = flock($fh, &LOCK_EX); }; - _error_reason($@) if $@; + $self->error_reason($@) if $@; if ($r) { $FileIsLocked{ $file } = 1; @@ -113,7 +105,7 @@ sub _simple_flock } } else { - _error_reason("cannot open $file"); + $self->error_reason("cannot open $file"); } return 0; @@ -122,7 +114,7 @@ sub _simple_flock sub _simple_funlock { - my ($file) = @_; + my ($self, $file) = @_; return 0 unless $FileIsLocked{ $file }; return 0 unless $LockedFileHandle{ $file }; @@ -133,7 +125,7 @@ sub _simple_funlock eval q{ $r = flock($fh, &LOCK_UN); }; - _error_reason($@) if $@; + $self->error_reason($@) if $@; if ($r) { delete $FileIsLocked{ $file }; @@ -147,7 +139,8 @@ sub _simple_funlock =head1 SEE ALSO -L +L, +L, =head1 AUTHOR @@ -155,7 +148,7 @@ Ken'ichi Fukamachi > =head1 COPYRIGHT -Copyright (C) 2000 Ken'ichi Fukamachi +Copyright (C) 2000,2001 Ken'ichi Fukamachi All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -- cgit v1.2.1