doy / try-tiny

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

->export_to_level no longer available #14

Closed tm604 closed 10 years ago

tm604 commented 10 years ago

Hi there,

In 0.18 and below, Try::Tiny was inheriting from Exporter - which is useful due to the extra utility methods such as ->export_to_level:

use base 'Exporter';

Since 0.19 this appears to have changed to pick up ->import only:

use Exporter 5.57 'import';

due to https://github.com/doy/try-tiny/pull/11 . This breaks modules which rely on ->export_to_level (http://www.cpantesters.org/cpan/report/0c0e931e-87bd-11e3-a68e-81a05d7e0655) for applying the try/catch imports to their caller.

parent.pm does not appear to exhibit the same problem - on 5.8.9-5.18.2 modifying to use parent qw(Exporter); passes cleanly for me (where base.pm fails). If I'm missing something else and inheritance is generally problematic, or you don't want the extra dependency on parent.pm, any chance you could extend to import the export_to_level sub? (I can raise a pull request with either option)

use Exporter 5.57 qw(import export_to_level);

Presumably this same issue affects any module which inherits a class (using base.pm) that the caller also inherits from, so patching Try::Tiny for this case seems more of a workaround than a real fix - any other module which relies on 'use base' could also exhibit the same issue. Granted, it's a workaround which solves a genuine issue, but it seems like something that should be fixed or at least documented in base.pm.

cheers,

Tom

doy commented 10 years ago

I recommend using import::into rather than relying on the undocumented fact that Try::Tiny inherits the Exporter API.