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, which is simpler than what is used by DirDB. As I understand it, recent unices can flock over NFS. To avoid getting an empty string by slurping a file during the moment between when it is opened and truncated for writing and when the lock is obtained, we open the file twice when we write to it, once to set up an exclusive lock and once to truncate and write.

Some slurping modules on CPAN don't do any locking at all.

Tie::Slurp::ReadOnly works the same as Tie::Slurp, except that STORE croaks.

EXPORT

None by default.

HISTORY

0.01

sysread, syswrite, flock.

AUTHOR

David Nicol, <davidnico@cpan.org>

SEE ALSO

File::Slurp Abigail's comparison of slurping idioms on p5p, October 2003 DirDB module