NAME
Tie::Slurp - tie a scalar to a named file
SYNOPSIS
use Tie::Slurp;
tie my $template => Tie::Slurp::ReadOnly => 'template';
tie my $output => Tie::Slurp => 'output';
($output = $template) =~ s/\[(\w+)\]/$data{$1}/g;
DESCRIPTION
Tie::Slurp associates a scalar with a named file. Read the scalar, the file is read. Write to the scalar, the file gets clobbered. Flock is used for collision avoidance.
Tie::Slurp::ReadOnly works the same as Tie::Slurp, except that STORE croaks.
CAVEAT
Though Tie::Slurp does flock, it still has a 'race condition' problem in many cases. When you do something to the STOREed data, the tied file opens and locks first to FETCH, and closes here once. Then the FETCHed data gets changed, and the file opens and locks again to STORE them. So, if someone access the file while you are changing your data, something unwanted may happen. Tie::Slurp is useful, but don't use it under severe conditions.
HISTORY
- 0.02 (ishigaki)
-
enabled strict and warnings. rewrote
STOREalong the perlopentut way. rewrote test to use Test::More. rewrote pod and added caveat on 'race condition'. - 0.01 (nicol)
-
sysread, syswrite, flock.
AUTHOR
David Nicol, <davidnico@cpan.org>
CO-MAINTAINER
Kenichi Ishigaki, <ishigaki@cpan.org>
SEE ALSO
Abigail's comparison of slurping idioms on p5p, October 2003