Skip to content

Commit addf3ca

Browse files
authored
Merge pull request #2052 from Grinnz/scalar_eval
ensure eval is always called in scalar context (#2051)
2 parents a46fbb7 + b896aad commit addf3ca

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

lib/Mojo/IOLoop/Client.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use Scalar::Util qw(weaken);
1010
use Socket qw(IPPROTO_TCP SOCK_STREAM TCP_NODELAY);
1111

1212
# Non-blocking name resolution requires Net::DNS::Native
13-
use constant NNR => $ENV{MOJO_NO_NNR} ? 0 : eval { require Net::DNS::Native; Net::DNS::Native->VERSION('0.15'); 1 };
13+
use constant NNR => $ENV{MOJO_NO_NNR} ? 0 : !!eval { require Net::DNS::Native; Net::DNS::Native->VERSION('0.15'); 1 };
1414
my $NDN;
1515

1616
# SOCKS support requires IO::Socket::Socks
1717
use constant SOCKS => $ENV{MOJO_NO_SOCKS}
1818
? 0
19-
: eval { require IO::Socket::Socks; IO::Socket::Socks->VERSION('0.64'); 1 };
19+
: !!eval { require IO::Socket::Socks; IO::Socket::Socks->VERSION('0.64'); 1 };
2020
use constant READ => SOCKS ? IO::Socket::Socks::SOCKS_WANT_READ() : 0;
2121
use constant WRITE => SOCKS ? IO::Socket::Socks::SOCKS_WANT_WRITE() : 0;
2222

lib/Mojo/IOLoop/TLS.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use Mojo::IOLoop;
66
use Scalar::Util qw(weaken);
77

88
# TLS support requires IO::Socket::SSL
9-
use constant TLS => $ENV{MOJO_NO_TLS} ? 0 : eval { require IO::Socket::SSL; IO::Socket::SSL->VERSION('2.009'); 1 };
9+
use constant TLS => $ENV{MOJO_NO_TLS} ? 0 : !!eval { require IO::Socket::SSL; IO::Socket::SSL->VERSION('2.009'); 1 };
1010
use constant READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
1111
use constant WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;
1212

lib/Mojo/JSON.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Scalar::Util qw(blessed);
1010
# For better performance Cpanel::JSON::XS is required
1111
use constant JSON_XS => $ENV{MOJO_NO_JSON_XS}
1212
? 0
13-
: eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('4.09'); 1 };
13+
: !!eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('4.09'); 1 };
1414

1515
our @EXPORT_OK = qw(decode_json encode_json false from_json j to_json true);
1616

@@ -49,7 +49,7 @@ sub from_json {
4949

5050
sub j {
5151
return encode_json($_[0]) if ref $_[0] eq 'ARRAY' || ref $_[0] eq 'HASH';
52-
return eval { decode_json($_[0]) };
52+
return scalar eval { decode_json($_[0]) };
5353
}
5454

5555
sub to_json { _encode_value(shift) }

lib/Mojo/Util.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Time::HiRes ();
2222
use Unicode::Normalize ();
2323

2424
# Check for monotonic clock support
25-
use constant MONOTONIC => eval { !!Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) };
25+
use constant MONOTONIC => !!eval { Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) };
2626

2727
# Punycode bootstring parameters
2828
use constant {

0 commit comments

Comments
 (0)