Thread (12 messages) flat view 12 messages, 5 authors, 2016-06-15

Re: [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional

From: Randal L. Schwartz <hidden>
Date: 2016-06-15 22:42:22

quoted
quoted
quoted
quoted
"Eric" == Eric Wong [off-list ref] writes:
Eric> +my $have_email_valid = eval { require Email::Valid or undef };

This is not necessary... if eval fails, it returns undef by definition.  Your
code presumes that the non-zero last-expression-evaluated of a require is also
returned from the require, which I believe is only accidentally true, although
the behavior may be recently documented and therefore promised.  (On perl 5.8,
it looks a bit fishy to me at a quick glance.)

My favorite idiom for a possibly failing eval-step is:

        my $can_I_do_this = eval { riskything; 1 };

If riskything fails, eval returns undef.  If it succeeds, it evaluates the 1,
and returns that.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[off-list ref] <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help