From: Rafael Garcia-Suarez Date: Fri, 6 Mar 2009 14:01:34 +0000 (+0100) Subject: Make the "..." flip-flop operator work in scalar context in when() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e03d7438337d3d902ac13cc268ff27c33c4bbe8;p=p5sagit%2Fp5-mst-13.2.git Make the "..." flip-flop operator work in scalar context in when() --- diff --git a/op.c b/op.c index 943837e..fe0ad14 100644 --- a/op.c +++ b/op.c @@ -5231,7 +5231,14 @@ S_looks_like_bool(pTHX_ const OP *o) || cSVOPo->op_sv == &PL_sv_no) return TRUE; + else + return FALSE; + case OP_FLOP: + /* Detect "..." flip-flop operator */ + if (cUNOPo->op_first->op_flags & OPf_SPECIAL) + return TRUE; + /* FALL THROUGH */ default: return FALSE; diff --git a/t/op/switch.t b/t/op/switch.t index 5568cb0..e01ce2f 100644 --- a/t/op/switch.t +++ b/t/op/switch.t @@ -8,7 +8,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 109; +use Test::More tests => 113; # The behaviour of the feature pragma should be tested by lib/switch.t # using the tests in t/lib/switch/*. This file tests the behaviour of @@ -510,6 +510,17 @@ sub bar {"bar"} } { + my $n = 0; + for my $l qw(a b c d) { + given ($l) { + when ($_ eq "b" ... $_ eq "c") { $n = 1 } + default { $n = 0 } + } + ok(($n xor $l =~ /[ad]/), 'when(E1...E2) evaluates in boolean context'); + } +} + +{ my $ok = 0; given("foo") { when((1 == $ok) || "foo") {