doy / try-tiny

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

Import 'import' instead of inheriting it #11

Closed ilmari closed 10 years ago

ilmari commented 10 years ago

This fixes errors when the first use of Try::Tiny happens during global destruction on Perl >= 5.10.0.

The problem is that the inheritance caches don't get invalidated during global destruction, and base.pm skips classes that the calling class already inherits from, thus populating an initial empty inheritance cache, which doesn't get invalidated when it adds the class to @ISA.

doy commented 10 years ago

Do you have a test for this? I can't seem to reproduce it (I get this same result on all perls from 5.8 to 5.18):

$ perl -e'{ package Foo; sub DESTROY { require Try::Tiny; Try::Tiny::try { warn "foo" } } }; our %foo; bless \%foo, "Foo";' 
foo at -e line 1 during global destruction.
ilmari commented 10 years ago

The problem is caused when a module importing try/catch from Try::Tiny is loaded during global destruction, in which case the subs aren't exported to it, since 'use base' doesn't work.

Because exceptions during global destruction are converted to warnings and don't affect the exit status, testing would involve using Capture::Tiny, which until yesterday (version 0.23) didn't install on 5.6. Now that that's fixed, I'll gladly write some tests, if that's an acceptable test prereq.

doy commented 10 years ago

Yes, that's fine - just make it an author dependency (and have the test skip if it's not installed).