| IO-File-Lockable documentation | Contained in the IO-File-Lockable distribution. |
IO::File::fcntl - extension of IO::File for fcntl
use IO::File::fcntl;
my $fh = new IO::File::fcntl($filename); # auto lock_(ex|sh)
my $fh = new IO::File::fcntl($filename,'<'); # auto lock_ex
my $fh = new IO::File::fcntl($filename,'>','lock_sh');
my $fh = new IO::File::fcntl($filename,'<','lock_ex',60);
etc,etc....
IO::File::fcntl inherits from IO::File::Lockable.
creates a IO::File::fcntl.
Shin Honda (makoto[at]cpan.org,makoto[at]cpan.jp)
Copyright (c) 2004- Shin Honda. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| IO-File-Lockable documentation | Contained in the IO-File-Lockable distribution. |
package IO::File::fcntl; use strict; use base qw(IO::File::Lockable); use vars qw($VERSION); use Fcntl; $VERSION = '0.31'; ###################################################################### sub DESTROY :method {shift->fcntl_un} sub fcntl_ :method {CORE::fcntl($_[0],$_[1],$_[2])} ##### override sub lock_ex :method {shift->fcntl_ex(@_)} sub lock_sh :method {shift->fcntl_sh(@_)} sub lock_un :method {shift->fcntl_un(@_)} ##### fcntl oop i/f sub fcntl :method { my $fh = shift; my $lock = shift; my $timeout = shift || 0; return $fh unless($fh->opened); return $fh->set_timeout( $timeout => sub {fcntl_($fh,F_SETLKW,pack('ssx32',$lock,0));$fh} ); } sub fcntl_sh :method {shift->fcntl(F_RDLCK,@_)} sub fcntl_ex :method {shift->fcntl(F_WRLCK,@_)} sub fcntl_un :method {shift->fcntl(F_UNLCK,@_)} 1; __END__