I suppose you probably hit this problem more often than many of the rest of us ;-) Then again, you may notice more than the rest of us...

What surprised me when I looked at the doc was that we actually had to type "eval" ourselves. I kind of expected it to take a coderef or string, and perform the eval itself. (This may have still required "sub" since prototyping wouldn't work for this, and since you're using objects where I don't think prototyping works anyway.)

A bit more thinking, and I'm wondering why all the overhead in the first place. If you had an exportable SafeEval (maybe two - one taking strings, the other taking a code ref via a prototype to look more like the built-in eval) which automatically created the object and returned that, it would definitely make this much simpler. And simpler means faster adoption. And that means more safe perl code out there. IMO, it may even make it harder to misuse the module (again, producing more safe code).

use Devel::EvalError; my $ee = EvalExpectOne { ...; 1 }; ... $ee->Reuse(); $ee = EvalExpectOneStr "..."; # EvalExpectOneStr could append the "; 1 +" to the end automatically
These eval functions would be able to set up all the handlers, do the eval, and take down all the handlers before returning back. That should also get rid of your overlapping issues - there'd be no hanging-on of previous handlers - the only way to overlap really would be having one eval inside another (directly or indirectly).

Then, for absolute convenience, I'd suggest that EvalExpectOne probably could do everything via Contextual::Return:

return BOOL { $obj->Succeeded() } STR { $obj->Reason() } LIST { $obj->AllReasons() };
But that's probably getting too convoluted ;-) ("Too much black magic")


In reply to Re: Devel::EvalError lives by Tanktalus
in thread Devel::EvalError lives by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.