Skip Menu |

This queue is for tickets about the autodie CPAN distribution.

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

Owner: Nobody in particular
Requestors: mschwern [...]

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

Subject: Check for error on implicit close.
Download (untitled) / with headers
text/plain 1.2k
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.
Download (untitled) / with headers
text/plain 616b
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

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to