<HTML> <HEAD> <TITLE>IO::AtomicFile 2.101</TITLE> </HEAD> <BODY bgcolor="#FFFFFF" link="#CC3366" vlink="#993366" alink="#FF6666"> <FONT FACE="sans-serif" SIZE=-1><A HREF="http://www.zeegee.com" TARGET="_top"><IMG SRC="icons/zeegee.gif" ALT="ZeeGee Software" ALIGN="RIGHT" BORDER="0"></A><A NAME="__TOP__"><H1>IO::AtomicFile 2.101</H1> </A> <P><B>This module is <FONT COLOR="#990000">BETA</FONT> code, which means that the interfaces are fairly stable BUT it has not been out in the community long enough to guarantee much testing. Use with caution! Please report any errors back to <A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A> as soon as you can.</B><UL> <LI> <A NAME="menu:NAME"><A HREF="#NAME">NAME</A></A> <LI> <A NAME="menu:SYNOPSIS"><A HREF="#SYNOPSIS">SYNOPSIS</A></A> <LI> <A NAME="menu:DESCRIPTION"><A HREF="#DESCRIPTION">DESCRIPTION</A></A> <LI> <A NAME="menu:AUTHOR"><A HREF="#AUTHOR">AUTHOR</A></A> <LI> <A NAME="menu:REVISION"><A HREF="#REVISION">REVISION</A></A> </UL> <P><HR> <A NAME="NAME"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NAME</H2></A> <P>IO::AtomicFile - write a file which is updated atomically <P><HR> <A NAME="SYNOPSIS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SYNOPSIS</H2></A> <FONT SIZE=3 FACE="courier"><PRE> use IO::AtomicFile; </PRE></FONT> <FONT SIZE=3 FACE="courier"><PRE> ### Write a temp file, and have it install itself when closed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello!\n"; $FH->close || die "couldn't install atomic file: $!"; </PRE></FONT> <FONT SIZE=3 FACE="courier"><PRE> ### Write a temp file, but delete it before it gets installed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello!\n"; $FH->delete; </PRE></FONT> <FONT SIZE=3 FACE="courier"><PRE> ### Write a temp file, but neither install it nor delete it: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello!\n"; $FH->detach; </PRE></FONT> <P><HR> <A NAME="DESCRIPTION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> DESCRIPTION</H2></A> <P>This module is intended for people who need to update files reliably in the face of unexpected program termination. <P>For example, you generally don't want to be halfway in the middle of writing <I>/etc/passwd</I> and have your program terminate! Even the act of writing a single scalar to a filehandle is <I>not</I> atomic. <P>But this module gives you true atomic updates, via rename(). When you open a file <I>/foo/bar.dat</I> via this module, you are <I>actually</I> opening a temporary file <I>/foo/bar.dat..TMP</I>, and writing your output there. The act of closing this file (either explicitly via close(), or implicitly via the destruction of the object) will cause rename() to be called... therefore, from the point of view of the outside world, the file's contents are updated in a single time quantum. <P>To ensure that problems do not go undetected, the "close" method done by the destructor will raise a fatal exception if the rename() fails. The explicit close() just returns undef. <P>You can also decide at any point to trash the file you've been building. <P><HR> <A NAME="AUTHOR"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> AUTHOR</H2></A> <P>Eryq (<I><FILE><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></FILE></I>). President, ZeeGee Software Inc (<I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I>). <P><HR> <A NAME="REVISION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> REVISION</H2></A> <P>$Revision: 2.101 $ <P><HR> <ADDRESS><FONT SIZE=-1> Generated Mon Aug 20 16:36:30 2001 by cvu_pod2html </FONT></ADDRESS> </FONT></BODY> </HTML>