# from Smylers
# on Wednesday 23 April 2008 14:51:

>Why would it being under his control mean he didn't want to test for
> it?

He didn't say anything about testing for it.  Ovid said he was thinking 
about changing his code to e.g. "open(my $fh, '<', $file) or EXIT;", 
which IMO is not required because that would mean you ended up with a 
$SIG{__DIE__} in scope from 'main', aka t/foo.t.

  # dienow.pm
  package dienow; use warnings; use strict; use Carp ();

  use Class::Accessor::Classy; with 'new'; no Class::Accessor::Classy;
  use overload '&{}' => sub {sub{die @_}}, fallback => 1;

  $SIG{__DIE__} = __PACKAGE__->new;

  my $ended = 0; END {$ended = 1};
  sub DESTROY { return if($ended); Carp::carp("bad bunny"); exit(1); }

  1;

There.  If anyone sets a global die handler, we complain and stop.

Apparently 'die' from inside the DESTROY() of the object in 
$SIG{__DIE__} doesn't work... fancy that. ;-)

For extra points, wrap any existing die handler so that the load order 
determines which ones are okay.  Other than that, I think it just needs 
a better name.

For those thinking "but you now always have a die handler", I say "yes, 
but it is not a _broken_ one".

  perl -e 'use dienow; eval{ die "foo!";}; warn "eval works: $@"'

  perl -e 'use dienow; die "foo!";'

--Eric
-- 
So malloc calls a timeout and starts rummaging around the free chain,
sorting things out, and merging adjacent small free blocks into larger
blocks. This takes 3 1/2 days.
--Joel Spolsky
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------

Reply via email to