doy / try-tiny

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

Named try/catch/finally blocks #3

Closed 2shortplanks closed 11 years ago

2shortplanks commented 12 years ago

Hello!

This pull request names the try/catch/finally blocks if Sub::Name is installed.

Consider:

package Foo;

use Try::Tiny;

sub wibble {
    try {
        die "Not enough kittens";
    } catch {
        die "OH NOES!";
    }
}

package main;

Foo::wibble()

This normally produces:

client-169:~ mark$ perl -MCarp::Always foo.pl
OH NOES! at foo.pl line 9.
    Foo::__ANON__('Not enough kittens at foo.pl line 7.\x{a}\x{9}Foo::__ANON__() called ...') called at /Users/mark/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Try/Tiny.pm line 108
    Try::Tiny::try('CODE(0x7fdb02802f90)', 'Try::Tiny::Catch=REF(0x7fdb0281a0a0)') called at foo.pl line 11
    Foo::wibble() called at foo.pl line 15

But with my pull request produces

client-169:~ mark$ perl -MCarp::Always foo.pl
OH NOES! at foo.pl line 9.
    Foo::catch {...} ('Not enough kittens at foo.pl line 7.\x{a}\x{9}Foo::try {...}() called...') called at /Users/mark/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Try/Tiny.pm line 108
    Try::Tiny::try('CODE(0x7fb0c9802f90)', 'Try::Tiny::Catch=REF(0x7fb0c981a0d0)') called at foo.pl line 11
    Foo::wibble() called at foo.pl line 15

(I also changed the github page in the docu since it's terribly out of date)

ribasushi commented 11 years ago

This sounds like a decent idea - did you receive any feedback yet?

doy commented 11 years ago

Can you rebase this, and also add some tests?

2shortplanks commented 11 years ago

Rebased, with tests

doy commented 11 years ago

Thanks, merged.