pfenwick/autodie — Issue #6: Remove local $@; eval { ... } in autodie::exception
Author: miyagawa
Created: 2011-11-03 14:45:02+00:00
State: open

Try the following code (assuming you have Plack installed :D) and open the localhost:5000 in the browser:

plackup -e 'sub { use autodie; open my $fh, "<:utf8", "/tmp/x/y/z" }'

you'll a stacktrace of:

Internal autodie::exception error: Don't know how to format mode '<:utf8'. at ...

This is fundamentally because autodie::exception internally localizes $@ and tries _format_open_with_mode() with eval, causing it to overwrite the captured error from StackTrace middleware.

There are probably two separate issues here:

* Could it be rewritten so that it doesn't use local $@ and eval {}, like just returning undef (`return;`) instead of throwing errors in the _format_open_with_mode()? Fiddling with exceptions in autodie::exception sounds like a cause of troubles :)
* The open mode detecter that is being discussed doesn't support PerlIO like this one `<:utf8` - it would be nice if we detect that. Or at least you can change the $mode detector to be relaxed like using regexes instead of an exact match - IMO.