Eric Wilhelm wrote:
>> You don't want to delete someone else's $SIG{__DIE__}.
> 
> No, I do.  Why would anyone else's $SIG{__DIE__} be in my code?  Now, 
> maybe you're going to say that someone might use my module and be upset 
> because their broken $SIG{__DIE__} is broken.

Yes, exactly.  Especially when module A has an impolite global SIGDIE that
it needs and its used by innocent third party user B along with your
vigilante global SIGDIE-killing module C.

The innocent user loses.

Put another way... be lax in what you accept, strict in what you output.

Also this:

eval { delete $SIG{__DIE__};  $obj->isa($class) }

is no shorter than this:

eval { local $SIG{__DIE__};  $obj->isa($class) }



>> And how can 
>> you know if it checks $^S (most don't)?
> 
> Maybe some juggling of exit and die.  Hmm, sounds like a job for 
> chromatic.  Acme::OhNoYouDidn::t?  Or, you could just curry it into a 
> sub that does check $^S if you wanted to be safe and weren't concerned 
> about the call stack.  Or you could always just walk down the hall and 
> tell whoever wrote it to fix it.

That's a long bloody hall you've got there for CPAN code.  And how do you
know the user didn't intend it to run even if its in an eval?

The idea of wrapping it (not currying, that's something else) in a "return
unless $^S" is interesting, but unfortunately $SIG{__DIE__} can be set at
runtime so you'd have to be constantly checking it which again is no better
than "local $SIG{__DIE__}"

Finally, $^S often doesn't work.  See the $SIG{__DIE__} in Test::Builder for
the awful details.

Hey, there's an example of a legit global $SIG{__DIE__} that doesn't use $^S! :)


>> which 
>> would be great but nobody does which brings me right back to "it
>> shouldn't be so hard to do it right!"
> 
> Why doesn't anybody do it right?  Yes, the docs say that it was an
> accident that $SIG{__DIE__} gets called from within an eval and "that 
> may be fixed in the future."  But, it's very clear in both perlvar and 
> perlfunc#die, so why bother with the eval {local $SIG{__DIE__}; ...} 
> mess?  Just cause broken code to break instead of working around it.

BECAUSE WE ALL THROUGHLY STUDY THE DOCUMENTATION, RIGHT?!

Yeah.

People do it wrong because its easier to do it that way.  And it usually
works fine.  Most people don't even know about $^S.  Hell, even the
designers didn't think of it as evidenced by the accidental feature.

Doing it slightly wrong but usable is easier than doing it right.  That's
why nobody does it right.  Design failure.

Reply via email to