[Pdx-pm] solving File::Temp API friction

Eric Wilhelm scratchcomputing at gmail.com
Wed Feb 27 01:34:53 PST 2008

Hi all,

I always have trouble remembering how to operate the File::Temp API.  
Does the directory delete automatically or do I have to set the cleanup 
flag, where is it and what is it named, why do I have to specify TMPDIR 
if I give it a template, etc, etc.

With directory objects, the temporary directory is always explicit.  
File::Fu->tmp is your friendly File::Spec->tmpdir, so when you call 
temp_dir/temp_file on the toplevel package, it uses /tmp/ for the 
parent.  If you have or create a directory object, that's the parent.

  File::Fu->temp_dir;              # '/tmp/'
  File::Fu->dir->temp_dir;         # './'
  File::Fu->dir("foo")->temp_dir;  # 'foo/'

  File::Fu->temp_file;             # '/tmp/'
  File::Fu->dir->temp_file;        # './'
  File::Fu->dir("foo")->temp_file; # 'foo/'

Now you always know where it is, but without all that extra typing.  You 
can also pass the "first part" of a template with 
$dir->temp_file("foo") instead of "foo" . "X"x10.

But I don't know what to say about the sysopen binmode win32 issue here:


File::Fu v0.0.2 just hit CPAN with a whole pile of new features 
including builtins like readlink() and such, the aforementioned temp 
bits, create(), remove(), find(), and read() (with File::Slurp if you 
have it.)

I'll probably break the .= brokenness later this week and then release 
v0.1.0.  Anyone see anything missing?

[...proprietary software is better than gpl because...] "There is value
in having somebody you can write checks to, and they fix bugs."
--Mike McNamara (president of a commercial software company)

More information about the Pdx-pm-list mailing list