doy / try-tiny

minimal try/catch with proper preservation of $@
http://metacpan.org/release/Try-Tiny
10 stars 15 forks source link

package a; try { die "b" }; dies #26

Open vytas-dauksa opened 8 years ago

vytas-dauksa commented 8 years ago

Not sure if it's a bug in Perl or Try::Tiny, but consider this one liner: perl -MTry::Tiny -E 'package one; Try::Tiny::try { die "doesnt die here"; }; try { die "but dies here..."; };'

tried on: perl 5.14.2, 5.18. 5.20, 5.22 Try::Tiny 0.09, 0.19, 0.22

mauke commented 8 years ago

This is a bug in your code. You're doing the equivalent of

package main;
use Try::Tiny;
package one;
try { ... };

I.e. you're importing try into main:: but trying to use it from one::, where no such sub is defined. This (for stupid reasons) makes perl parse it as do { ... }->try():

$ perl -MO=Deparse -e 'try { die "..." }'
do {
    die '...'
}->try;
-e syntax OK

(And by "stupid reasons" I mean indirect object syntax.)