Tie::Handle::Flock - exclusive locking write handle


Tie-Handle-Flock documentation Contained in the Tie-Handle-Flock distribution.

Index


Code Index:

NAME

Top

Tie::Handle::Flock - exclusive locking write handle

VERSION

Top

Version 0.01

SYNOPSIS

Top

	use Tie::Handle::Flock;

	tie *FH, 'Tie::Handle::Flock', '>', 'some_file.txt';

	print FH "exclusive lock obtained for duration of the write\n";

METHODS

Top

WRITE

method called when something writes to the filehandle

PRINT

method called when something prints to the filehandle

PRINTF

method called when something prints formatted text to the filehandle

lock

method called to obtoin an exclusive lock on the filehandle prior to any write activity

unlock

method called to release the exclusive lock after the write is complete

AUTHOR

Top

Ivan Heffner, <iheffner at gmail.com>

BUGS

Top

Please report any bugs or feature requests to bug-tie-handle-flock at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tie-Handle-Flock. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Tie::Handle::Flock




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tie-Handle-Flock

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Tie-Handle-Flock

* CPAN Ratings

http://cpanratings.perl.org/d/Tie-Handle-Flock

* Search CPAN

http://search.cpan.org/dist/Tie-Handle-Flock/

COPYRIGHT & LICENSE

Top


Tie-Handle-Flock documentation Contained in the Tie-Handle-Flock distribution.

package Tie::Handle::Flock;

use warnings;
use strict;

require Tie::Handle;
our @ISA = qw(Tie::StdHandle);
our $VERSION = '0.01';

use Fcntl qw(:flock :seek);

# WRITE this, scalar, length, offset
sub WRITE {
	my $fh = shift;
	$fh->lock();
	$fh->SUPER::WRITE( @_ );
	$fh->unlock();
}

# PRINT this, LIST
sub PRINT {
	my $fh = shift;
	$fh->lock();
	$fh->SUPER::PRINT( @_ );
	$fh->unlock();
}

# PRINTF this, format, LIST
sub PRINTF {
	my $fh = shift;
	$fh->lock();
	$fh->SUPER::PRINTF( @_ );
	$fh->unlock();
}

sub lock {
	my ($fh) = @_;
	flock($fh, LOCK_EX);
	seek( $fh, 0, SEEK_END );
}

sub unlock {
	my ($fh) = @_;
	flock($fh, LOCK_UN);
}


__PACKAGE__; # End of Tie::Handle::Flock

__END__