Skip Menu |

This queue is for tickets about the autodie CPAN distribution.

Report information
The Basics
Id: 52985
Status: resolved
Priority: 0/
Queue: autodie

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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.
Blarf. While the idea of using IO::Handle::DESTROY works A) Perl sends out a "helpful" warning about it, which I suppose isn't so bad, but B) $@ gets lost somewhere along the line and C) the eval block doesn't fail, it looks at the last evaluated lexical statement inside. use IO::Handle; use warnings; no warnings "redefine"; sub IO::Handle::DESTROY { die "DESTRRRRROY!" } print "Eval failed.\n" if !eval { open my $fh, "/dev/null"; }; print "Caught: $@\n"; __END__ (in cleanup) DESTRRRRROY! at - line 5. Caught: (in cleanup) DESTRRRRROY! at - line 5 during global destruction.
Ticket migrated to github as https://github.com/pjf/autodie/issues/96