Subject: | Check for error on implicit close. |
Wouldn't it be cool if...
use autodie;
{
open my $fh, ">", $file;
print $fh @a_lot_of_stuff;
}
Failed when it ran out of disk space? This does.
use autodie;
{
open my $fh, ">", $file;
print $fh @a_lot_of_stuff;
close $fh;
}
But because the implicit close of a lexical filehandle is so convenient
one would not bother with an explicit one.
I'm throwing this out there to see if there's a clever way to implement
it. One is to have open() return a glob object which does an explicit
close() on DESTROY.
This would also offer a solution to another problem...
Can't close(GLOB(0x803704)) filehandle: 'No space left on device'
It would allow open to attach the original filename to the filehandle
object which can be used to generate better error messages down the line.
On the down side, it will break code that expects open() to return a
non-blessed reference. autodie is lexical, but filehandles get passed
around.
One work around would be to take advantage of the IO::Handle magic.
autodie could treat the filehandle as an inside out object to store data
on it and put accessor methods into IO::Handle. It could add an
IO::Handle::DESTROY to do the extra close.