summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANIFEST2
-rw-r--r--cpan/experimental/t/basic.t2
-rw-r--r--gv.c2
-rw-r--r--keywords.c95
-rw-r--r--keywords.h4
-rw-r--r--lib/B/Deparse-core.t2
-rw-r--r--lib/B/Deparse.pm6
-rw-r--r--lib/B/Deparse.t22
-rw-r--r--op.c2
-rw-r--r--opcode.h4
-rw-r--r--perly.act2
-rw-r--r--perly.h4
-rw-r--r--perly.tab4
-rw-r--r--perly.y6
-rw-r--r--pod/perldiag.pod18
-rw-r--r--pod/perlexperiment.pod2
-rw-r--r--pod/perlfunc.pod6
-rw-r--r--pod/perlintro.pod4
-rw-r--r--pod/perlsyn.pod56
-rw-r--r--pod/perltrap.pod5
-rw-r--r--pp_ctl.c4
-rwxr-xr-xregen/keywords.pl4
-rw-r--r--regen/opcodes4
-rw-r--r--t/lib/croak/pp_ctl6
-rw-r--r--t/lib/feature/switch40
-rw-r--r--t/op/coreamp.t7
-rw-r--r--t/op/coresubs.t2
-rw-r--r--t/op/cproto.t2
-rw-r--r--t/op/state.t2
-rw-r--r--t/op/switch.t446
-rw-r--r--t/op/taint.t6
-rw-r--r--t/op/whereso.t (renamed from t/op/when.t)90
-rw-r--r--t/porting/customized.dat2
-rw-r--r--t/run/switches.t2
-rw-r--r--toke.c8
35 files changed, 440 insertions, 433 deletions
diff --git a/MANIFEST b/MANIFEST
index 49ebbb873b..03a002f420 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -5806,7 +5806,7 @@ t/op/ver.t See if v-strings and the %v format flag work
t/op/waitpid.t See if waitpid works
t/op/wantarray.t See if wantarray works
t/op/warn.t See if warn works
-t/op/when.t See if when works
+t/op/whereso.t See if whereso works
t/op/while.t See if while loops work
t/op/write.t See if write works (formats work)
t/op/yadayada.t See if ... works
diff --git a/cpan/experimental/t/basic.t b/cpan/experimental/t/basic.t
index e66b2b9c83..a36943afa2 100644
--- a/cpan/experimental/t/basic.t
+++ b/cpan/experimental/t/basic.t
@@ -21,7 +21,7 @@ if ($] >= 5.010001) {
use experimental 'switch';
sub bar { 1 };
given(1) {
- when (\&bar) {
+ whereso (\&bar) {
pass("bar matches 1");
}
fail("bar matches 1");
diff --git a/gv.c b/gv.c
index 2c9f64c181..015903c4ba 100644
--- a/gv.c
+++ b/gv.c
@@ -535,7 +535,7 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv,
case KEY_s : case KEY_say : case KEY_sort :
case KEY_state: case KEY_sub :
case KEY_tr : case KEY_UNITCHECK: case KEY_unless:
- case KEY_until: case KEY_use : case KEY_when : case KEY_while :
+ case KEY_until: case KEY_use : case KEY_whereso : case KEY_while :
case KEY_x : case KEY_xor : case KEY_y :
return NULL;
case KEY_chdir:
diff --git a/keywords.c b/keywords.c
index 1576d4addf..217efa3b7f 100644
--- a/keywords.c
+++ b/keywords.c
@@ -488,7 +488,7 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
goto unknown;
}
- case 4: /* 40 tokens of length 4 */
+ case 4: /* 39 tokens of length 4 */
switch (name[0])
{
case 'I':
@@ -908,44 +908,33 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
}
case 'w':
- switch (name[1])
+ if (name[1] == 'a')
{
- case 'a':
- switch (name[2])
- {
- case 'i':
- if (name[3] == 't')
- { /* wait */
- return -KEY_wait;
- }
-
- goto unknown;
-
- case 'r':
- if (name[3] == 'n')
- { /* warn */
- return -KEY_warn;
- }
-
- goto unknown;
+ switch (name[2])
+ {
+ case 'i':
+ if (name[3] == 't')
+ { /* wait */
+ return -KEY_wait;
+ }
- default:
- goto unknown;
- }
+ goto unknown;
- case 'h':
- if (name[2] == 'e' &&
- name[3] == 'n')
- { /* when */
- return (all_keywords || FEATURE_SWITCH_IS_ENABLED ? KEY_when : 0);
- }
+ case 'r':
+ if (name[3] == 'n')
+ { /* warn */
+ return -KEY_warn;
+ }
- goto unknown;
+ goto unknown;
- default:
- goto unknown;
+ default:
+ goto unknown;
+ }
}
+ goto unknown;
+
default:
goto unknown;
}
@@ -1887,7 +1876,7 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
goto unknown;
}
- case 7: /* 29 tokens of length 7 */
+ case 7: /* 30 tokens of length 7 */
switch (name[0])
{
case 'D':
@@ -2293,17 +2282,35 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
}
case 'w':
- if (name[1] == 'a' &&
- name[2] == 'i' &&
- name[3] == 't' &&
- name[4] == 'p' &&
- name[5] == 'i' &&
- name[6] == 'd')
- { /* waitpid */
- return -KEY_waitpid;
- }
+ switch (name[1])
+ {
+ case 'a':
+ if (name[2] == 'i' &&
+ name[3] == 't' &&
+ name[4] == 'p' &&
+ name[5] == 'i' &&
+ name[6] == 'd')
+ { /* waitpid */
+ return -KEY_waitpid;
+ }
- goto unknown;
+ goto unknown;
+
+ case 'h':
+ if (name[2] == 'e' &&
+ name[3] == 'r' &&
+ name[4] == 'e' &&
+ name[5] == 's' &&
+ name[6] == 'o')
+ { /* whereso */
+ return (all_keywords || FEATURE_SWITCH_IS_ENABLED ? KEY_whereso : 0);
+ }
+
+ goto unknown;
+
+ default:
+ goto unknown;
+ }
default:
goto unknown;
@@ -3401,5 +3408,5 @@ unknown:
}
/* Generated from:
- * 50664fad65e719c51bf369702163eb7ade79f997461f928cc20f1e1bcf8369b8 regen/keywords.pl
+ * fa7d552d13fad7c3ad101e3f8d5301a9780147c26623ecb3e75f0ec7f0d24cc3 regen/keywords.pl
* ex: set ro: */
diff --git a/keywords.h b/keywords.h
index cd4ecb3631..d630d02190 100644
--- a/keywords.h
+++ b/keywords.h
@@ -260,7 +260,7 @@
#define KEY_waitpid 244
#define KEY_wantarray 245
#define KEY_warn 246
-#define KEY_when 247
+#define KEY_whereso 247
#define KEY_while 248
#define KEY_write 249
#define KEY_x 250
@@ -268,5 +268,5 @@
#define KEY_y 252
/* Generated from:
- * 50664fad65e719c51bf369702163eb7ade79f997461f928cc20f1e1bcf8369b8 regen/keywords.pl
+ * fa7d552d13fad7c3ad101e3f8d5301a9780147c26623ecb3e75f0ec7f0d24cc3 regen/keywords.pl
* ex: set ro: */
diff --git a/lib/B/Deparse-core.t b/lib/B/Deparse-core.t
index 01a9b18305..e1984c8757 100644
--- a/lib/B/Deparse-core.t
+++ b/lib/B/Deparse-core.t
@@ -378,7 +378,7 @@ my %not_tested = map { $_ => 1} qw(
unless
until
use
- when
+ whereso
while
y
);
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm
index fe8abbf4e1..43955a65ce 100644
--- a/lib/B/Deparse.pm
+++ b/lib/B/Deparse.pm
@@ -2246,7 +2246,7 @@ my %feature_keywords = (
state => 'state',
say => 'say',
given => 'switch',
- when => 'switch',
+ whereso => 'switch',
evalbytes=>'evalbytes',
__SUB__ => '__SUB__',
fc => 'fc',
@@ -2541,12 +2541,12 @@ sub pp_continue { unop(@_, "continue"); }
sub pp_leavewhen {
my($self, $op, $cx) = @_;
- my $when = $self->keyword("when");
+ my $whereso = $self->keyword("whereso");
my $enterop = $op->first;
my $cond = $enterop->first;
my $cond_str = $self->deparse($cond, 1);
my $block = $self->deparse($cond->sibling, 0);
- return "$when ($cond_str) {\n\t$block\n\b}\cK";
+ return "$whereso ($cond_str) {\n\t$block\n\b}\cK";
}
sub pp_exists {
diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t
index 156898652c..b8d98caefc 100644
--- a/lib/B/Deparse.t
+++ b/lib/B/Deparse.t
@@ -1023,12 +1023,12 @@ my $b = \{};
my $c = [];
my $d = \[];
####
-# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
+# SKIP ?$] < 5.010 && "smartmatch and given/whereso not implemented on this Perl version"
# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
-# implicit smartmatch in given/when
+# implicit smartmatch in given/whereso
given ('foo') {
- when ('bar') { continue; }
- when ($_ ~~ 'quux') { continue; }
+ whereso ('bar') { continue; }
+ whereso ($_ ~~ 'quux') { continue; }
0;
}
####
@@ -1511,7 +1511,7 @@ $a[0] = 1;
CORE::state $x;
CORE::say $x;
CORE::given ($x) {
- CORE::when (3) {
+ CORE::whereso (3) {
continue;
}
next;
@@ -1527,7 +1527,7 @@ use 1;
CORE::say $_;
CORE::state $x;
CORE::given ($x) {
- CORE::when (3) {
+ CORE::whereso (3) {
continue;
}
next;
@@ -1538,7 +1538,7 @@ CORE::evalbytes '';
CORE::say $_;
CORE::state $x;
CORE::given ($x) {
- CORE::when (3) {
+ CORE::whereso (3) {
continue;
}
next;
@@ -1554,7 +1554,7 @@ use 1;
CORE::say $_;
CORE::state $x;
CORE::given ($x) {
- CORE::when (3) {
+ CORE::whereso (3) {
continue;
}
next;
@@ -1567,7 +1567,7 @@ use feature ':default';
CORE::say $_;
CORE::state $x;
CORE::given ($x) {
- CORE::when (3) {
+ CORE::whereso (3) {
continue;
}
next;
@@ -1598,7 +1598,7 @@ my sub tr;
my sub unless;
my sub until;
my sub use;
-my sub when;
+my sub whereso;
my sub while;
CORE::if ($1) { die; }
CORE::if ($1) { die; }
@@ -1621,7 +1621,7 @@ CORE::unless ($1) { die; }
CORE::until ($1) { die; }
die CORE::until $1;
CORE::use strict;
-CORE::when ($1 ~~ $2) { die; }
+CORE::whereso ($1 ~~ $2) { die; }
CORE::while ($1) { die; }
die CORE::while $1;
####
diff --git a/op.c b/op.c
index 85d786d8a6..761e8dd578 100644
--- a/op.c
+++ b/op.c
@@ -8789,7 +8789,7 @@ Perl_newGIVENOP(pTHX_ OP *cond, OP *block, PADOFFSET defsv_off)
/*
=for apidoc Am|OP *|newWHENOP|OP *cond|OP *block
-Constructs, checks, and returns an op tree expressing a C<when> block.
+Constructs, checks, and returns an op tree expressing a C<whereso> block.
C<cond> supplies the test expression, and C<block> supplies the block
that will be executed if the test evaluates to true; they are consumed
by this function and become part of the constructed op tree.
diff --git a/opcode.h b/opcode.h
index 37089fe3c2..346b991b7c 100644
--- a/opcode.h
+++ b/opcode.h
@@ -767,8 +767,8 @@ EXTCONST char* const PL_op_desc[] = {
"redirect method with known name",
"redirect super method with known name",
"given()",
- "when()",
- "leave when block",
+ "whereso()",
+ "leave whereso block",
"continue",
"open",
"close",
diff --git a/perly.act b/perly.act
index 7594b34b0b..5624140209 100644
--- a/perly.act
+++ b/perly.act
@@ -1977,6 +1977,6 @@ case 2:
/* Generated from:
- * 233778626e1c4f8b4103ca96d66b107b4527a7b7304f05e373aef634cc4b6f81 perly.y
+ * 03a4b1d58244383edfcce2549f649e112744b3efc4083221c08bb0e1e4d221c5 perly.y
* b6fae5748f9bef6db4740aa5e122b84ac5181852d42474d0ecad621fa4253306 regen_perly.pl
* ex: set ro: */
diff --git a/perly.h b/perly.h
index b45c5f6573..837df06c78 100644
--- a/perly.h
+++ b/perly.h
@@ -86,7 +86,7 @@ extern int yydebug;
CONTINUE = 289,
FOR = 290,
GIVEN = 291,
- WHEN = 292,
+ WHERESO = 292,
LOOPEX = 293,
DOTDOT = 294,
YADAYADA = 295,
@@ -180,6 +180,6 @@ int yyparse (void);
/* Generated from:
- * 233778626e1c4f8b4103ca96d66b107b4527a7b7304f05e373aef634cc4b6f81 perly.y
+ * 03a4b1d58244383edfcce2549f649e112744b3efc4083221c08bb0e1e4d221c5 perly.y
* b6fae5748f9bef6db4740aa5e122b84ac5181852d42474d0ecad621fa4253306 regen_perly.pl
* ex: set ro: */
diff --git a/perly.tab b/perly.tab
index 8471be5c1e..175c50c86a 100644
--- a/perly.tab
+++ b/perly.tab
@@ -111,7 +111,7 @@ static const char *const yytname[] =
"METHOD", "FUNCMETH", "THING", "PMFUNC", "PRIVATEREF", "QWLIST",
"FUNC0OP", "FUNC0SUB", "UNIOPSUB", "LSTOPSUB", "PLUGEXPR", "PLUGSTMT",
"LABEL", "FORMAT", "SUB", "ANONSUB", "PACKAGE", "USE", "WHILE", "UNTIL",
- "IF", "UNLESS", "ELSE", "ELSIF", "CONTINUE", "FOR", "GIVEN", "WHEN",
+ "IF", "UNLESS", "ELSE", "ELSIF", "CONTINUE", "FOR", "GIVEN", "WHERESO",
"LOOPEX", "DOTDOT", "YADAYADA", "FUNC0", "FUNC1", "FUNC", "UNIOP",
"LSTOP", "RELOP", "EQOP", "MULOP", "ADDOP", "DOLSHARP", "DO",
"HASHBRACK", "NOAMP", "LOCAL", "MY", "REQUIRE", "COLONATTR",
@@ -1103,6 +1103,6 @@ static const toketypes yy_type_tab[] =
};
/* Generated from:
- * 233778626e1c4f8b4103ca96d66b107b4527a7b7304f05e373aef634cc4b6f81 perly.y
+ * 03a4b1d58244383edfcce2549f649e112744b3efc4083221c08bb0e1e4d221c5 perly.y
* b6fae5748f9bef6db4740aa5e122b84ac5181852d42474d0ecad621fa4253306 regen_perly.pl
* ex: set ro: */
diff --git a/perly.y b/perly.y
index 0c7839c299..7f3fc464aa 100644
--- a/perly.y
+++ b/perly.y
@@ -53,7 +53,7 @@
%token <pval> LABEL
%token <ival> FORMAT SUB ANONSUB PACKAGE USE
%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
-%token <ival> GIVEN WHEN
+%token <ival> GIVEN WHERESO
%token <ival> LOOPEX DOTDOT YADAYADA
%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
%token <ival> RELOP EQOP MULOP ADDOP
@@ -378,7 +378,7 @@ barestmt: PLUGSTMT
$$ = block_end($3, newGIVENOP($4, op_scope($6), 0));
parser->copline = (line_t)$1;
}
- | WHEN '(' remember mexpr ')' mblock
+ | WHERESO '(' remember mexpr ')' mblock
{ $$ = block_end($3, newWHENOP($4, op_scope($6))); }
| WHILE '(' remember texpr ')' mintro mblock cont
{
@@ -531,7 +531,7 @@ sideff : error
| expr FOR expr
{ $$ = newFOROP(0, NULL, $3, $1, NULL);
parser->copline = (line_t)$2; }
- | expr WHEN expr
+ | expr WHERESO expr
{ $$ = newWHENOP($3, op_scope($1)); }
;
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 9ded5065ab..f5e678c908 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -822,9 +822,9 @@ You CAN say
but then $foo no longer contains a glob.
-=item Can't "continue" outside a when block
+=item Can't "continue" outside a whereso block
-(F) You called C<continue>, but you're not inside a C<when> block.
+(F) You called C<continue>, but you're not inside a C<whereso> block.
=item Can't create pipe mailbox
@@ -1076,15 +1076,15 @@ usually double the curlies to get the same effect though, because the
inner curlies will be considered a block that loops once. See
L<perlfunc/last>.
-=item Can't leave "when" outside a loop block
+=item Can't leave "whereso" outside a loop block
-(F) Control reached the end of a C<when> block that isn't inside any
+(F) Control reached the end of a C<whereso> block that isn't inside any
loop (including a C<given> block). An implicit C<next> occurs here,
-which requires a loop to jump to. You probably wanted the C<when> to be
+which requires a loop to jump to. You probably wanted the C<whereso> to be
inside a C<given> block. Note that you won't get this error if the match
-controlling the C<when> fails, or if you use an explicit C<continue> to
+controlling the C<whereso> fails, or if you use an explicit C<continue> to
avoid reaching the end of the block. But if you rely on not reaching the
-implicit C<next> then you probably didn't want C<when>, but rather C<if>.
+implicit C<next> then you probably didn't want C<whereso>, but rather C<if>.
=item Can't linearize anonymous symbol table
@@ -7414,9 +7414,9 @@ but in actual fact, you got
So put in parentheses to say what you really mean.
-=item when is experimental
+=item whereso is experimental
-(S experimental::smartmatch) C<when> is experimental, and its behavior
+(S experimental::smartmatch) C<whereso> is experimental, and its behavior
may change or it may even be removed in any future release of perl.
See the explanation under L<perlsyn/Switch Statements>.
diff --git a/pod/perlexperiment.pod b/pod/perlexperiment.pod
index 566a3e0e97..f750fd2a80 100644
--- a/pod/perlexperiment.pod
+++ b/pod/perlexperiment.pod
@@ -30,7 +30,7 @@ L<[perl #119317]|https://rt.perl.org/rt3/Ticket/Display.html?id=119317>.
For historical reasons, the single experiment covers both the smart
match operator (C<~~>) and the switch-related compound statements
-(given/when), which apart from the shared warning category are now
+(C<given>/C<whereso>), which apart from the shared warning category are now
unrelated in behaviour.
=item Pluggable keywords
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index c7375aa1f8..c304c030e3 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -421,7 +421,7 @@ L<C<time>|/time>, L<C<times>|/times>
C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
-C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
+C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<whereso>,
C<while>, C<x>, C<xor>
=back
@@ -1318,7 +1318,7 @@ using an empty one, logically enough, so L<C<next>|/next LABEL> goes
directly back to check the condition at the top of the loop.
When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
-that exits the current C<when> block, avoiding the implicit C<next>
+that exits the current C<whereso> block, avoiding the implicit C<next>
that happens when execution reaches the end of such a block.
In Perl 5.14 and earlier, this form of
L<C<continue>|/continue BLOCK> was only available when the
@@ -10085,7 +10085,7 @@ Statements">.
=item given
-=item when
+=item whereso
These flow-control keywords related to the experimental switch feature are
documented in L<perlsyn/"Switch Statements">.
diff --git a/pod/perlintro.pod b/pod/perlintro.pod
index 5c168c18e1..f0ab70adf1 100644
--- a/pod/perlintro.pod
+++ b/pod/perlintro.pod
@@ -326,8 +326,8 @@ running the program. Using C<strict> is highly recommended.
=head2 Conditional and looping constructs
-Perl has most of the usual conditional and looping constructs. As of Perl
-5.10, it even has a case/switch statement (spelled C<given>/C<when>). See
+Perl has most of the usual conditional and looping constructs.
+It even has a switch/case statement (spelled C<given>/C<whereso>). See
L<perlsyn/"Switch Statements"> for more details.
The conditions can be any Perl expression. See the list of operators in
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index 06338303db..ae7bb0325a 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -118,7 +118,7 @@ as the last item in a statement.
=head2 Statement Modifiers
X<statement modifier> X<modifier> X<if> X<unless> X<while>
-X<until> X<when> X<foreach> X<for>
+X<until> X<whereso> X<foreach> X<for>
Any simple statement may optionally be followed by a I<SINGLE> modifier,
just before the terminating semicolon (or block ending). The possible
@@ -130,7 +130,7 @@ modifiers are:
until EXPR
for LIST
foreach LIST
- when EXPR
+ whereso EXPR
The C<EXPR> following the modifier is referred to as the "condition".
Its truth or falsehood determines how the modifier will behave.
@@ -211,11 +211,11 @@ it. Future versions of perl might do something different from the
version of perl you try it out on. Here be dragons.
X<my>
-The C<when> modifier is an experimental feature that first appeared in
-Perl 5.12, but behaved quite differently from its present form prior
-to Perl 5.28. To use it, you should include a C<use feature 'switch'>
+The C<whereso> modifier is an experimental feature that first appeared
+with this spelling in Perl 5.28.
+To use it, you should include a C<use feature 'switch'>
declaration, or a declaration that implies it. It behaves like the full
-C<when> statement with block, described in L</"Switch Statements"> below.
+C<whereso> statement with block, described in L</"Switch Statements"> below.
It executes the statement only if the I<EXPR> is true. If the statement
executes, control then implicitly jumps to the end of the dynamically
enclosing loop (usually a C<given> block).
@@ -246,7 +246,7 @@ The following compound statements may be used to control flow:
given (EXPR) BLOCK
- when (EXPR) BLOCK
+ whereso (EXPR) BLOCK
LABEL while (EXPR) BLOCK
LABEL while (EXPR) BLOCK continue BLOCK
@@ -267,7 +267,7 @@ The following compound statements may be used to control flow:
PHASE BLOCK
-The experimental C<given> and C<when> statements are I<not
+The experimental C<given> and C<whereso> statements are I<not
automatically enabled>; see L</"Switch Statements"> below for how to do
so, and the attendant caveats.
@@ -606,9 +606,9 @@ described immediately below remains experimental.
=head2 Switch Statements
-X<switch> X<case> X<given> X<when>
+X<switch> X<case> X<given> X<whereso>
-C<given>, C<when>, and related keywords make up an experimental feature
+C<given>, C<whereso>, and related keywords make up an experimental feature
that first appeared in Perl 5.10, but behaved quite differently from
its present form prior to Perl 5.28. To use it, you should declare
@@ -621,17 +621,17 @@ example:
use v5.14;
Under the "switch" feature, Perl gains the experimental keywords C<given>
-and C<when>. Starting from Perl 5.16, one can
+and C<whereso>. Starting from Perl 5.16, one can
prefix the switch keywords with C<CORE::> to access the feature without
a C<use feature> statement.
The "switch" feature is considered highly experimental; it is subject
-to change with little notice. Uses of the C<given> and C<when> keywords
+to change with little notice. Uses of the C<given> and C<whereso> keywords
will by default warn about their experimental status. Due to historical
links between the two features, these warnings are in the same category
as warnings about the C<~~> (smartmatch) operator being experimental.
-The keywords C<given> and C<when> are analogous to C<switch> and C<case>
+The keywords C<given> and C<whereso> are analogous to C<switch> and C<case>
in C. They're meant to be used together, but can actually be used
independently and mixed with other kinds of compound statement.
@@ -643,7 +643,7 @@ A C<given> construct even counts as a one-iteration loop for the purposes
of loop control, so the C<redo> operator can be used to restart its block,
and C<next> or C<last> can be used to exit the block early.
-C<when> evaluates its argument as a truth value. If the argument
+C<whereso> evaluates its argument as a truth value. If the argument
was false then it does not execute its block, and proceeds to the
following statement. If the argument was true, it executes the block,
then implicitly performs a C<next>, jumping to the end of the closest
@@ -654,31 +654,31 @@ rewritten as
use v5.10.1;
given ($var) {
- when (/^abc/) { $abc = 1 }
- when (/^def/) { $def = 1 }
- when (/^xyz/) { $xyz = 1 }
+ whereso (/^abc/) { $abc = 1 }
+ whereso (/^def/) { $def = 1 }
+ whereso (/^xyz/) { $xyz = 1 }
$nothing = 1;
}
-Or if you prefer the modifier form of C<when>, it can be written with
+Or if you prefer the modifier form of C<whereso>, it can be written with
less punctuation as
use v5.14;
given ($var) {
- $abc = 1 when /^abc/;
- $def = 1 when /^def/;
- $xyz = 1 when /^xyz/;
+ $abc = 1 whereso /^abc/;
+ $def = 1 whereso /^def/;
+ $xyz = 1 whereso /^xyz/;
$nothing = 1;
}
-You can use the C<continue> keyword to exit a C<when>
+You can use the C<continue> keyword to exit a C<whereso>
block, proceeding to the following statement. This is most commonly
done last thing inside the block, to override the implicit C<next>.
For example
given($foo) {
- when (/x/) { say '$foo contains an x'; continue }
- when (/y/) { say '$foo contains a y' }
+ whereso (/x/) { say '$foo contains an x'; continue }
+ whereso (/y/) { say '$foo contains a y' }
say '$foo does not contain a y';
}
@@ -695,7 +695,7 @@ An empty list as soon as an explicit C<next> or C<last> is encountered.
=item *
The value of the last evaluated expression of the successful
-C<when> clause, if there happens to be one.
+C<whereso> clause, if there happens to be one.
=item *
@@ -706,12 +706,12 @@ condition is true.
In both last cases, the last expression is evaluated in the context that
was applied to the C<given> block.
-Note that, unlike C<if> and C<unless>, failed C<when> statements always
+Note that, unlike C<if> and C<unless>, failed C<whereso> statements always
evaluate to an empty list.
-On versions of Perl preceding Perl 5.28, C<given> and C<when> behave
+On versions of Perl preceding Perl 5.28, C<given> and C<whereso> behave
quite differently from their present behaviour. If your code needs to
-run on older versions, avoid C<given> and C<when>.
+run on older versions, avoid C<given> and C<whereso>.
=head2 Goto
X<goto>
diff --git a/pod/perltrap.pod b/pod/perltrap.pod
index acb43925d1..7830b72fc7 100644
--- a/pod/perltrap.pod
+++ b/pod/perltrap.pod
@@ -170,8 +170,9 @@ C<do { } while> construct. See L<perlsyn/"Loop Control">.
=item *
-The switch statement is called C<given>/C<when> and only available in
-perl 5.10 or newer. See L<perlsyn/"Switch Statements">.
+The switch statement is called C<given>/C<whereso> and only available
+in its current form in perl 5.28 or newer. See L<perlsyn/"Switch
+Statements">.
=item *
diff --git a/pp_ctl.c b/pp_ctl.c
index aa8f2cfdb9..f1153ab724 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4626,7 +4626,7 @@ PP(pp_leavewhen)
cxix = dopoptoloop(cxstack_ix);
if (cxix < 0)
- DIE(aTHX_ "Can't leave \"when\" outside a loop block");
+ DIE(aTHX_ "Can't leave \"whereso\" outside a loop block");
oldsp = PL_stack_base + cx->blk_oldsp;
if (gimme == G_VOID)
@@ -4664,7 +4664,7 @@ PP(pp_continue)
cxix = dopoptowhen(cxstack_ix);
if (cxix < 0)
- DIE(aTHX_ "Can't \"continue\" outside a when block");
+ DIE(aTHX_ "Can't \"continue\" outside a whereso block");
if (cxix < cxstack_ix)
dounwind(cxix);
diff --git a/regen/keywords.pl b/regen/keywords.pl
index e7aecf0436..6bebf7d103 100755
--- a/regen/keywords.pl
+++ b/regen/keywords.pl
@@ -39,7 +39,7 @@ my %feature_kw = (
state => 'state',
say => 'say',
given => 'switch',
- when => 'switch',
+ whereso => 'switch',
# continue is already a keyword
evalbytes => 'evalbytes',
__SUB__ => '__SUB__',
@@ -352,7 +352,7 @@ __END__
-waitpid
-wantarray
-warn
-+when
++whereso
+while
-write
-x
diff --git a/regen/opcodes b/regen/opcodes
index 1a1da125c9..1aaee2bec0 100644
--- a/regen/opcodes
+++ b/regen/opcodes
@@ -329,8 +329,8 @@ method_redir redirect method with known name ck_null d.
method_redir_super redirect super method with known name ck_null d.
entergiven given() ck_null d{
-enterwhen when() ck_null d|
-leavewhen leave when block ck_null 1
+enterwhen whereso() ck_null d|
+leavewhen leave whereso block ck_null 1
continue continue ck_null 0
# I/O.
diff --git a/t/lib/croak/pp_ctl b/t/lib/croak/pp_ctl
index 35c833925e..b060d236e7 100644
--- a/t/lib/croak/pp_ctl
+++ b/t/lib/croak/pp_ctl
@@ -6,8 +6,8 @@ dump $label;
EXPECT
Can't find label foo at - line 3.
########
-# NAME when outside given
+# NAME whereso outside given
use 5.01; no warnings 'experimental::smartmatch';
-when(!defined){}
+whereso(!defined){}
EXPECT
-Can't leave "when" outside a loop block at - line 2.
+Can't leave "whereso" outside a loop block at - line 2.
diff --git a/t/lib/feature/switch b/t/lib/feature/switch
index 7d0bfd5e23..5e6269ff0e 100644
--- a/t/lib/feature/switch
+++ b/t/lib/feature/switch
@@ -9,17 +9,17 @@ EXPECT
Unquoted string "given" may clash with future reserved word at - line 3.
given
########
-# No switch; when should be a bareword.
+# No switch; whereso should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
-print STDOUT when;
+print STDOUT whereso;
EXPECT
-Unquoted string "when" may clash with future reserved word at - line 3.
-when
+Unquoted string "whereso" may clash with future reserved word at - line 3.
+whereso
########
# No switch; but continue is still a keyword
print STDOUT continue;
EXPECT
-Can't "continue" outside a when block at - line 2.
+Can't "continue" outside a whereso block at - line 2.
########
# Use switch; so given is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
@@ -27,9 +27,9 @@ given("okay\n") { print }
EXPECT
okay
########
-# Use switch; so when is a keyword
+# Use switch; so whereso is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
-given(1) { when(1) { print "okay" } }
+given(1) { whereso(1) { print "okay" } }
EXPECT
okay
########
@@ -44,35 +44,35 @@ Unquoted string "given" may clash with future reserved word at - line 6.
Okay here
given
########
-# switch out of scope; when should be a bareword.
+# switch out of scope; whereso should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
{ use feature 'switch';
- given (1) { when(1) {print "Okay here\n";} }
+ given (1) { whereso(1) {print "Okay here\n";} }
}
-print STDOUT when;
+print STDOUT whereso;
EXPECT
-Unquoted string "when" may clash with future reserved word at - line 6.
+Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
-when
+whereso
########
# C<no feature 'switch'> should work
use warnings; no warnings 'experimental::smartmatch';
use feature 'switch';
-given (1) { when(1) {print "Okay here\n";} }
+given (1) { whereso(1) {print "Okay here\n";} }
no feature 'switch';
-print STDOUT when;
+print STDOUT whereso;
EXPECT
-Unquoted string "when" may clash with future reserved word at - line 6.
+Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
-when
+whereso
########
# C<no feature> should work too
use warnings; no warnings 'experimental::smartmatch';
use feature 'switch';
-given (1) { when(1) {print "Okay here\n";} }
+given (1) { whereso(1) {print "Okay here\n";} }
no feature;
-print STDOUT when;
+print STDOUT whereso;
EXPECT
-Unquoted string "when" may clash with future reserved word at - line 6.
+Unquoted string "whereso" may clash with future reserved word at - line 6.
Okay here
-when
+whereso
diff --git a/t/op/coreamp.t b/t/op/coreamp.t
index c553a510d1..52e2fd5ff9 100644
--- a/t/op/coreamp.t
+++ b/t/op/coreamp.t
@@ -450,7 +450,7 @@ SKIP:
test_proto 'continue';
$tests ++;
CORE::given(1) {
- CORE::when(1) {
+ CORE::whereso(1) {
&mycontinue();
}
pass "&continue";
@@ -1152,12 +1152,11 @@ like $@, qr'^Undefined format "STDOUT" called',
if (m?__END__?..${\0} and /^[-+](.*)/) {
my $word = $1;
next if
- $word =~ /^(?:s(?:tate|ort|ay|ub)?|d(?:ef
- ault|ump|o)|p(?:rintf?|ackag
+ $word =~ /^(?:s(?:tate|ort|ay|ub)?|d(?:ump|o)|p(?:rintf?|ackag
e)|e(?:ls(?:if|e)|val|q)|g(?:[et]|iven|oto
|rep)|u(?:n(?:less|til)|se)|l(?:(?:as)?t|ocal|e)|re
(?:quire|turn|do)|__(?:DATA|END)__|for(?:each|mat)?|(?:
- AUTOLOA|EN)D|n(?:e(?:xt)?|o)|C(?:HECK|ORE)|wh(?:ile|en)
+ AUTOLOA|EN)D|n(?:e(?:xt)?|o)|C(?:HECK|ORE)|wh(?:ile|ereso)
|(?:ou?|t)r|m(?:ap|y)?|UNITCHECK|q[qrwx]?|x(?:or)?|DEST
ROY|BEGIN|INIT|and|cmp|if|y)\z/x;
$tests ++;
diff --git a/t/op/coresubs.t b/t/op/coresubs.t
index 62210b576d..38c6bc4e6e 100644
--- a/t/op/coresubs.t
+++ b/t/op/coresubs.t
@@ -20,7 +20,7 @@ my %unsupported = map +($_=>1), qw (
format ge given goto grep gt if last le local lt m map my ne next
no or our package print printf q qq qr qw qx redo require
return s say sort state sub tr unless until use
- when while x xor y
+ whereso while x xor y
);
my %args_for = (
dbmopen => '%1,$2,$3',
diff --git a/t/op/cproto.t b/t/op/cproto.t
index 711d253dde..c0951b9c63 100644
--- a/t/op/cproto.t
+++ b/t/op/cproto.t
@@ -276,7 +276,7 @@ wait ()
waitpid ($$)
wantarray ()
warn (@)
-when undef
+whereso undef
while undef
write (;*)
x undef
diff --git a/t/op/state.t b/t/op/state.t
index f7558ba9da..ae4351f641 100644
--- a/t/op/state.t
+++ b/t/op/state.t
@@ -341,7 +341,7 @@ my @spam = qw [spam ham bacon beans];
foreach my $spam (@spam) {
no warnings 'experimental::smartmatch';
given (state $spam = $spam) {
- when ($spam [0]) {ok 1, "given"}
+ whereso ($spam [0]) {ok 1, "given"}
ok 0, "given";
}
}
diff --git a/t/op/switch.t b/t/op/switch.t
index 0b5761bccb..6d756afa86 100644
--- a/t/op/switch.t
+++ b/t/op/switch.t
@@ -19,7 +19,7 @@ plan tests => 161;
# Before loading feature, test the switch ops with CORE::
CORE::given(3) {
- CORE::when(3) { pass "CORE::given and CORE::when"; continue }
+ CORE::whereso(3) { pass "CORE::given and CORE::whereso"; continue }
pass "continue (without feature)";
}
@@ -42,7 +42,7 @@ like($@, qr/^Can't "continue" outside/, "continue outside");
sub be_true {1}
given(my $x = "foo") {
- when(be_true(my $x = "bar")) {
+ whereso(be_true(my $x = "bar")) {
is($x, "bar", "given scope starts");
}
is($x, "foo", "given scope ends");
@@ -57,9 +57,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my $ok;
given(3) {
- when($_ == 2) { $ok = 'two'; }
- when($_ == 3) { $ok = 'three'; }
- when($_ == 4) { $ok = 'four'; }
+ whereso($_ == 2) { $ok = 'two'; }
+ whereso($_ == 3) { $ok = 'three'; }
+ whereso($_ == 4) { $ok = 'four'; }
$ok = 'd';
}
is($ok, 'three', "numeric comparison");
@@ -69,9 +69,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $ok;
use integer;
given(3.14159265) {
- when($_ == 2) { $ok = 'two'; }
- when($_ == 3) { $ok = 'three'; }
- when($_ == 4) { $ok = 'four'; }
+ whereso($_ == 2) { $ok = 'two'; }
+ whereso($_ == 3) { $ok = 'three'; }
+ whereso($_ == 4) { $ok = 'four'; }
$ok = 'd';
}
is($ok, 'three', "integer comparison");
@@ -80,9 +80,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my ($ok1, $ok2);
given(3) {
- when($_ == 3.1) { $ok1 = 'n'; }
- when($_ == 3.0) { $ok1 = 'y'; continue }
- when($_ == "3.0") { $ok2 = 'y'; }
+ whereso($_ == 3.1) { $ok1 = 'n'; }
+ whereso($_ == 3.0) { $ok1 = 'y'; continue }
+ whereso($_ == "3.0") { $ok2 = 'y'; }
$ok2 = 'n';
}
is($ok1, 'y', "more numeric (pt. 1)");
@@ -92,9 +92,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my $ok;
given("c") {
- when($_ eq "b") { $ok = 'B'; }
- when($_ eq "c") { $ok = 'C'; }
- when($_ eq "d") { $ok = 'D'; }
+ whereso($_ eq "b") { $ok = 'B'; }
+ whereso($_ eq "c") { $ok = 'C'; }
+ whereso($_ eq "d") { $ok = 'D'; }
$ok = 'def';
}
is($ok, 'C', "string comparison");
@@ -103,9 +103,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my $ok;
given("c") {
- when($_ eq "b") { $ok = 'B'; }
- when($_ eq "c") { $ok = 'C'; continue }
- when($_ eq "c") { $ok = 'CC'; }
+ whereso($_ eq "b") { $ok = 'B'; }
+ whereso($_ eq "c") { $ok = 'C'; continue }
+ whereso($_ eq "c") { $ok = 'CC'; }
$ok = 'D';
}
is($ok, 'CC', "simple continue");
@@ -114,45 +114,45 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
# Definedness
{
my $ok = 1;
- given (0) { when(!defined) {$ok = 0} }
- is($ok, 1, "Given(0) when(!defined)");
+ given (0) { whereso(!defined) {$ok = 0} }
+ is($ok, 1, "Given(0) whereso(!defined)");
}
{
no warnings "uninitialized";
my $ok = 1;
- given (undef) { when(0) {$ok = 0} }
- is($ok, 1, "Given(undef) when(0)");
+ given (undef) { whereso(0) {$ok = 0} }
+ is($ok, 1, "Given(undef) whereso(0)");
}
{
no warnings "uninitialized";
my $undef;
my $ok = 1;
- given ($undef) { when(0) {$ok = 0} }
- is($ok, 1, 'Given($undef) when(0)');
+ given ($undef) { whereso(0) {$ok = 0} }
+ is($ok, 1, 'Given($undef) whereso(0)');
}
########
{
my $ok = 1;
- given ("") { when(!defined) {$ok = 0} }
- is($ok, 1, 'Given("") when(!defined)');
+ given ("") { whereso(!defined) {$ok = 0} }
+ is($ok, 1, 'Given("") whereso(!defined)');
}
{
no warnings "uninitialized";
my $ok = 1;
- given (undef) { when(0) {$ok = 0} }
- is($ok, 1, 'Given(undef) when(0)');
+ given (undef) { whereso(0) {$ok = 0} }
+ is($ok, 1, 'Given(undef) whereso(0)');
}
########
{
my $ok = 0;
- given (undef) { when(!defined) {$ok = 1} }
- is($ok, 1, "Given(undef) when(!defined)");
+ given (undef) { whereso(!defined) {$ok = 1} }
+ is($ok, 1, "Given(undef) whereso(!defined)");
}
{
my $undef;
my $ok = 0;
- given ($undef) { when(!defined) {$ok = 1} }
- is($ok, 1, 'Given($undef) when(!defined)');
+ given ($undef) { whereso(!defined) {$ok = 1} }
+ is($ok, 1, 'Given($undef) whereso(!defined)');
}
@@ -160,13 +160,13 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my ($ok1, $ok2);
given("Hello, world!") {
- when(/lo/)
+ whereso(/lo/)
{ $ok1 = 'y'; continue}
- when(/no/)
+ whereso(/no/)
{ $ok1 = 'n'; continue}
- when(/^(Hello,|Goodbye cruel) world[!.?]/)
+ whereso(/^(Hello,|Goodbye cruel) world[!.?]/)
{ $ok2 = 'Y'; continue}
- when(/^(Hello cruel|Goodbye,) world[!.?]/)
+ whereso(/^(Hello cruel|Goodbye,) world[!.?]/)
{ $ok2 = 'n'; continue}
}
is($ok1, 'y', "regex 1");
@@ -179,10 +179,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ < 10) { $ok = "ten" }
- when ($_ < 20) { $ok = "twenty" }
- when ($_ < 30) { $ok = "thirty" }
- when ($_ < 40) { $ok = "forty" }
+ whereso ($_ < 10) { $ok = "ten" }
+ whereso ($_ < 20) { $ok = "twenty" }
+ whereso ($_ < 30) { $ok = "thirty" }
+ whereso ($_ < 40) { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -194,10 +194,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ < 10) { $ok = "ten" }
- when ($_ < 20) { $ok = "twenty" }
- when ($_ < 30) { $ok = "thirty" }
- when ($_ < 40) { $ok = "forty" }
+ whereso ($_ < 10) { $ok = "ten" }
+ whereso ($_ < 20) { $ok = "twenty" }
+ whereso ($_ < 30) { $ok = "thirty" }
+ whereso ($_ < 40) { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -208,10 +208,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ <= 10) { $ok = "ten" }
- when ($_ <= 20) { $ok = "twenty" }
- when ($_ <= 30) { $ok = "thirty" }
- when ($_ <= 40) { $ok = "forty" }
+ whereso ($_ <= 10) { $ok = "ten" }
+ whereso ($_ <= 20) { $ok = "twenty" }
+ whereso ($_ <= 30) { $ok = "thirty" }
+ whereso ($_ <= 40) { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -223,10 +223,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ <= 10) { $ok = "ten" }
- when ($_ <= 20) { $ok = "twenty" }
- when ($_ <= 30) { $ok = "thirty" }
- when ($_ <= 40) { $ok = "forty" }
+ whereso ($_ <= 10) { $ok = "ten" }
+ whereso ($_ <= 20) { $ok = "twenty" }
+ whereso ($_ <= 30) { $ok = "thirty" }
+ whereso ($_ <= 40) { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -238,10 +238,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ > 40) { $ok = "forty" }
- when ($_ > 30) { $ok = "thirty" }
- when ($_ > 20) { $ok = "twenty" }
- when ($_ > 10) { $ok = "ten" }
+ whereso ($_ > 40) { $ok = "forty" }
+ whereso ($_ > 30) { $ok = "thirty" }
+ whereso ($_ > 20) { $ok = "twenty" }
+ whereso ($_ > 10) { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -252,10 +252,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ >= 40) { $ok = "forty" }
- when ($_ >= 30) { $ok = "thirty" }
- when ($_ >= 20) { $ok = "twenty" }
- when ($_ >= 10) { $ok = "ten" }
+ whereso ($_ >= 40) { $ok = "forty" }
+ whereso ($_ >= 30) { $ok = "thirty" }
+ whereso ($_ >= 20) { $ok = "twenty" }
+ whereso ($_ >= 10) { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -267,10 +267,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ > 40) { $ok = "forty" }
- when ($_ > 30) { $ok = "thirty" }
- when ($_ > 20) { $ok = "twenty" }
- when ($_ > 10) { $ok = "ten" }
+ whereso ($_ > 40) { $ok = "forty" }
+ whereso ($_ > 30) { $ok = "thirty" }
+ whereso ($_ > 20) { $ok = "twenty" }
+ whereso ($_ > 10) { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -282,10 +282,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ >= 40) { $ok = "forty" }
- when ($_ >= 30) { $ok = "thirty" }
- when ($_ >= 20) { $ok = "twenty" }
- when ($_ >= 10) { $ok = "ten" }
+ whereso ($_ >= 40) { $ok = "forty" }
+ whereso ($_ >= 30) { $ok = "thirty" }
+ whereso ($_ >= 20) { $ok = "twenty" }
+ whereso ($_ >= 10) { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -297,10 +297,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = "25";
my $ok;
given($twenty_five) {
- when ($_ lt "10") { $ok = "ten" }
- when ($_ lt "20") { $ok = "twenty" }
- when ($_ lt "30") { $ok = "thirty" }
- when ($_ lt "40") { $ok = "forty" }
+ whereso ($_ lt "10") { $ok = "ten" }
+ whereso ($_ lt "20") { $ok = "twenty" }
+ whereso ($_ lt "30") { $ok = "thirty" }
+ whereso ($_ lt "40") { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -311,10 +311,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = "25";
my $ok;
given($twenty_five) {
- when ($_ le "10") { $ok = "ten" }
- when ($_ le "20") { $ok = "twenty" }
- when ($_ le "30") { $ok = "thirty" }
- when ($_ le "40") { $ok = "forty" }
+ whereso ($_ le "10") { $ok = "ten" }
+ whereso ($_ le "20") { $ok = "twenty" }
+ whereso ($_ le "30") { $ok = "thirty" }
+ whereso ($_ le "40") { $ok = "forty" }
$ok = "default";
}
is($ok, "thirty", $test);
@@ -325,10 +325,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ ge "40") { $ok = "forty" }
- when ($_ ge "30") { $ok = "thirty" }
- when ($_ ge "20") { $ok = "twenty" }
- when ($_ ge "10") { $ok = "ten" }
+ whereso ($_ ge "40") { $ok = "forty" }
+ whereso ($_ ge "30") { $ok = "thirty" }
+ whereso ($_ ge "20") { $ok = "twenty" }
+ whereso ($_ ge "10") { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -339,10 +339,10 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
my $twenty_five = 25;
my $ok;
given($twenty_five) {
- when ($_ ge "40") { $ok = "forty" }
- when ($_ ge "30") { $ok = "thirty" }
- when ($_ ge "20") { $ok = "twenty" }
- when ($_ ge "10") { $ok = "ten" }
+ whereso ($_ ge "40") { $ok = "forty" }
+ whereso ($_ ge "30") { $ok = "thirty" }
+ whereso ($_ ge "20") { $ok = "twenty" }
+ whereso ($_ ge "10") { $ok = "ten" }
$ok = "default";
}
is($ok, "twenty", $test);
@@ -352,8 +352,8 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my $ok;
given(23) {
- when (2 + 2 == 4) { $ok = 'y'; continue }
- when (2 + 2 == 5) { $ok = 'n' }
+ whereso (2 + 2 == 4) { $ok = 'y'; continue }
+ whereso (2 + 2 == 5) { $ok = 'n' }
}
is($ok, 'y', "Optimized-away comparison");
}
@@ -361,7 +361,7 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my $ok;
given(23) {
- when ($_ == scalar 24) { $ok = 'n'; continue }
+ whereso ($_ == scalar 24) { $ok = 'n'; continue }
$ok = 'y';
}
is($ok,'y','scalar()');
@@ -375,9 +375,9 @@ sub check_outside1 { is($_, "inside", "\$_ is not lexically scoped") }
{
my ($ok_d, $ok_f, $ok_r);
given("op") {
- when(-d) {$ok_d = 1; continue}
- when(!-f) {$ok_f = 1; continue}
- when(-r) {$ok_r = 1; continue}
+ whereso(-d) {$ok_d = 1; continue}
+ whereso(!-f) {$ok_f = 1; continue}
+ whereso(-r) {$ok_r = 1; continue}
}
ok($ok_d, "Filetest -d");
ok($ok_f, "Filetest -f");
@@ -389,7 +389,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given("foo") {
- when(notfoo()) {$ok = 1}
+ whereso(notfoo()) {$ok = 1}
}
ok($ok, "Sub call acts as boolean")
}
@@ -397,7 +397,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given("foo") {
- when(main->notfoo()) {$ok = 1}
+ whereso(main->notfoo()) {$ok = 1}
}
ok($ok, "Class-method call acts as boolean")
}
@@ -406,7 +406,7 @@ sub notfoo {"bar"}
my $ok = 0;
my $obj = bless [];
given("foo") {
- when($obj->notfoo()) {$ok = 1}
+ whereso($obj->notfoo()) {$ok = 1}
}
ok($ok, "Object-method call acts as boolean")
}
@@ -415,7 +415,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given(12) {
- when( /(\d+)/ and ( 1 <= $1 and $1 <= 12 ) ) {
+ whereso( /(\d+)/ and ( 1 <= $1 and $1 <= 12 ) ) {
$ok = 1;
}
}
@@ -425,7 +425,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given(0) {
- when(eof(DATA)) {
+ whereso(eof(DATA)) {
$ok = 1;
}
}
@@ -436,7 +436,7 @@ sub notfoo {"bar"}
my $ok = 0;
my %foo = ("bar", 0);
given(0) {
- when(exists $foo{bar}) {
+ whereso(exists $foo{bar}) {
$ok = 1;
}
}
@@ -446,7 +446,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given(0) {
- when(defined $ok) {
+ whereso(defined $ok) {
$ok = 1;
}
}
@@ -456,10 +456,10 @@ sub notfoo {"bar"}
{
my $ok = 1;
given("foo") {
- when((1 == 1) && "bar") {
+ whereso((1 == 1) && "bar") {
$ok = 2;
}
- when((1 == 1) && $_ eq "foo") {
+ whereso((1 == 1) && $_ eq "foo") {
$ok = 0;
}
}
@@ -470,10 +470,10 @@ sub notfoo {"bar"}
my $n = 0;
for my $l (qw(a b c d)) {
given ($l) {
- when ($_ eq "b" .. $_ eq "c") { $n = 1 }
+ whereso ($_ eq "b" .. $_ eq "c") { $n = 1 }
$n = 0;
}
- ok(($n xor $l =~ /[ad]/), 'when(E1..E2) evaluates in boolean context');
+ ok(($n xor $l =~ /[ad]/), 'whereso(E1..E2) evaluates in boolean context');
}
}
@@ -481,17 +481,17 @@ sub notfoo {"bar"}
my $n = 0;
for my $l (qw(a b c d)) {
given ($l) {
- when ($_ eq "b" ... $_ eq "c") { $n = 1 }
+ whereso ($_ eq "b" ... $_ eq "c") { $n = 1 }
$n = 0;
}
- ok(($n xor $l =~ /[ad]/), 'when(E1...E2) evaluates in boolean context');
+ ok(($n xor $l =~ /[ad]/), 'whereso(E1...E2) evaluates in boolean context');
}
}
{
my $ok = 0;
given("foo") {
- when((1 == $ok) || "foo") {
+ whereso((1 == $ok) || "foo") {
$ok = 1;
}
}
@@ -501,7 +501,7 @@ sub notfoo {"bar"}
{
my $ok = 0;
given("foo") {
- when((1 == $ok || undef) // "foo") {
+ whereso((1 == $ok || undef) // "foo") {
$ok = 1;
}
}
@@ -538,44 +538,44 @@ my $f = tie my $v, "FetchCounter";
{ my $test_name = "Multiple FETCHes in given, due to aliasing";
my $ok;
given($v = 23) {
- when(!defined) {}
- when(sub{0}->()) {}
- when($_ == 21) {}
- when($_ == "22") {}
- when($_ == 23) {$ok = 1}
- when(/24/) {$ok = 0}
+ whereso(!defined) {}
+ whereso(sub{0}->()) {}
+ whereso($_ == 21) {}
+ whereso($_ == "22") {}
+ whereso($_ == 23) {$ok = 1}
+ whereso(/24/) {$ok = 0}
}
is($ok, 1, "precheck: $test_name");
is($f->count(), 4, $test_name);
}
-{ my $test_name = "Only one FETCH (numeric when)";
+{ my $test_name = "Only one FETCH (numeric whereso)";
my $ok;
$v = 23;
is($f->count(), 0, "Sanity check: $test_name");
given(23) {
- when(!defined) {}
- when(sub{0}->()) {}
- when($_ == 21) {}
- when($_ == "22") {}
- when($_ == $v) {$ok = 1}
- when(/24/) {$ok = 0}
+ whereso(!defined) {}
+ whereso(sub{0}->()) {}
+ whereso($_ == 21) {}
+ whereso($_ == "22") {}
+ whereso($_ == $v) {$ok = 1}
+ whereso(/24/) {$ok = 0}
}
is($ok, 1, "precheck: $test_name");
is($f->count(), 1, $test_name);
}
-{ my $test_name = "Only one FETCH (string when)";
+{ my $test_name = "Only one FETCH (string whereso)";
my $ok;
$v = "23";
is($f->count(), 0, "Sanity check: $test_name");
given("23") {
- when(!defined) {}
- when(sub{0}->()) {}
- when($_ eq "21") {}
- when($_ eq "22") {}
- when($_ eq $v) {$ok = 1}
- when(/24/) {$ok = 0}
+ whereso(!defined) {}
+ whereso(sub{0}->()) {}
+ whereso($_ eq "21") {}
+ whereso($_ eq "22") {}
+ whereso($_ eq $v) {$ok = 1}
+ whereso(/24/) {$ok = 0}
}
is($ok, 1, "precheck: $test_name");
is($f->count(), 1, $test_name);
@@ -585,10 +585,10 @@ my $f = tie my $v, "FetchCounter";
{
my $first = 1;
for (1, "two") {
- when ($_ eq "two") {
+ whereso ($_ eq "two") {
is($first, 0, "Loop: second");
}
- when ($_ == 1) {
+ whereso ($_ == 1) {
is($first, 1, "Loop: first");
$first = 0;
}
@@ -598,10 +598,10 @@ my $f = tie my $v, "FetchCounter";
{
my $first = 1;
for $_ (1, "two") {
- when ($_ eq "two") {
+ whereso ($_ eq "two") {
is($first, 0, "Explicit \$_: second");
}
- when ($_ == 1) {
+ whereso ($_ == 1) {
is($first, 1, "Explicit \$_: first");
$first = 0;
}
@@ -617,8 +617,8 @@ my $f = tie my $v, "FetchCounter";
sub bar {$called_bar = 1; "@_" eq "bar"}
my ($matched_foo, $matched_bar) = (0, 0);
given("foo") {
- when((\&bar)->($_)) {$matched_bar = 1}
- when((\&foo)->($_)) {$matched_foo = 1}
+ whereso((\&bar)->($_)) {$matched_bar = 1}
+ whereso((\&foo)->($_)) {$matched_foo = 1}
}
is($called_foo, 1, "foo() was called");
is($called_bar, 1, "bar() was called");
@@ -633,18 +633,18 @@ sub contains_x {
{
my ($ok1, $ok2) = (0,0);
given("foxy!") {
- when(contains_x($_))
+ whereso(contains_x($_))
{ $ok1 = 1; continue }
- when((\&contains_x)->($_))
+ whereso((\&contains_x)->($_))
{ $ok2 = 1; continue }
}
is($ok1, 1, "Calling sub directly (true)");
is($ok2, 1, "Calling sub indirectly (true)");
given("foggy") {
- when(contains_x($_))
+ whereso(contains_x($_))
{ $ok1 = 2; continue }
- when((\&contains_x)->($_))
+ whereso((\&contains_x)->($_))
{ $ok2 = 2; continue }
}
is($ok1, 1, "Calling sub directly (false)");
@@ -655,9 +655,9 @@ sub contains_x {
my($ea, $eb, $ec) = (0, 0, 0);
my $r;
given(3) {
- when(do { $ea++; $_ == 2 }) { $r = "two"; }
- when(do { $eb++; $_ == 3 }) { $r = "three"; }
- when(do { $ec++; $_ == 4 }) { $r = "four"; }
+ whereso(do { $ea++; $_ == 2 }) { $r = "two"; }
+ whereso(do { $eb++; $_ == 3 }) { $r = "three"; }
+ whereso(do { $ec++; $_ == 4 }) { $r = "four"; }
}
is $r, "three", "evaluation count";
is $ea, 1, "evaluation count";
@@ -665,39 +665,39 @@ sub contains_x {
is $ec, 0, "evaluation count";
}
-# Postfix when
+# Postfix whereso
{
my $ok;
given (undef) {
- $ok = 1 when !defined;
+ $ok = 1 whereso !defined;
}
is($ok, 1, "postfix !defined");
}
{
my $ok;
given (2) {
- $ok += 1 when $_ == 7;
- $ok += 2 when $_ == 9.1685;
- $ok += 4 when $_ > 4;
- $ok += 8 when $_ < 2.5;
+ $ok += 1 whereso $_ == 7;
+ $ok += 2 whereso $_ == 9.1685;
+ $ok += 4 whereso $_ > 4;
+ $ok += 8 whereso $_ < 2.5;
}
is($ok, 8, "postfix numeric");
}
{
my $ok;
given ("apple") {
- $ok = 1, continue when $_ eq "apple";
+ $ok = 1, continue whereso $_ eq "apple";
$ok += 2;
- $ok = 0 when $_ eq "banana";
+ $ok = 0 whereso $_ eq "banana";
}
is($ok, 3, "postfix string");
}
{
my $ok;
given ("pear") {
- do { $ok = 1; continue } when /pea/;
+ do { $ok = 1; continue } whereso /pea/;
$ok += 2;
- $ok = 0 when /pie/;
+ $ok = 0 whereso /pie/;
$ok += 4; next;
$ok = 0;
}
@@ -708,50 +708,50 @@ sub contains_x {
my $x = "what";
given(my $x = "foo") {
do {
- is($x, "foo", "scope inside ... when my \$x = ...");
+ is($x, "foo", "scope inside ... whereso my \$x = ...");
continue;
- } when be_true(my $x = "bar");
- is($x, "bar", "scope after ... when my \$x = ...");
+ } whereso be_true(my $x = "bar");
+ is($x, "bar", "scope after ... whereso my \$x = ...");
}
}
{
my $x = 0;
given(my $x = 1) {
- my $x = 2, continue when be_true();
- is($x, undef, "scope after my \$x = ... when ...");
+ my $x = 2, continue whereso be_true();
+ is($x, undef, "scope after my \$x = ... whereso ...");
}
}
-# Tests for last and next in when clauses
+# Tests for last and next in whereso clauses
my $letter;
$letter = '';
LETTER1: for ("a".."e") {
given ($_) {
$letter = $_;
- when ($_ eq "b") { last LETTER1 }
+ whereso ($_ eq "b") { last LETTER1 }
}
$letter = "z";
}
-is($letter, "b", "last LABEL in when");
+is($letter, "b", "last LABEL in whereso");
$letter = '';
LETTER2: for ("a".."e") {
given ($_) {
- when (/b|d/) { next LETTER2 }
+ whereso (/b|d/) { next LETTER2 }
$letter .= $_;
}
$letter .= ',';
}
-is($letter, "a,c,e,", "next LABEL in when");
+is($letter, "a,c,e,", "next LABEL in whereso");
-# Test goto with given/when
+# Test goto with given/whereso
{
my $flag = 0;
goto GIVEN1;
$flag = 1;
GIVEN1: given ($flag) {
- when ($_ == 0) { next; }
+ whereso ($_ == 0) { next; }
$flag = 2;
}
is($flag, 0, "goto GIVEN1");
@@ -759,7 +759,7 @@ is($letter, "a,c,e,", "next LABEL in when");
{
my $flag = 0;
given ($flag) {
- when ($_ == 0) { $flag = 1; }
+ whereso ($_ == 0) { $flag = 1; }
goto GIVEN2;
$flag = 2;
}
@@ -769,30 +769,30 @@ GIVEN2:
{
my $flag = 0;
given ($flag) {
- when ($_ == 0) { $flag = 1; goto GIVEN3; $flag = 2; }
+ whereso ($_ == 0) { $flag = 1; goto GIVEN3; $flag = 2; }
$flag = 3;
}
GIVEN3:
- is($flag, 1, "goto inside given and when");
+ is($flag, 1, "goto inside given and whereso");
}
{
my $flag = 0;
for ($flag) {
- when ($_ == 0) { $flag = 1; goto GIVEN4; $flag = 2; }
+ whereso ($_ == 0) { $flag = 1; goto GIVEN4; $flag = 2; }
$flag = 3;
}
GIVEN4:
- is($flag, 1, "goto inside for and when");
+ is($flag, 1, "goto inside for and whereso");
}
{
my $flag = 0;
GIVEN5:
given ($flag) {
- when ($_ == 0) { $flag = 1; goto GIVEN5; $flag = 2; }
- when ($_ == 1) { next; }
+ whereso ($_ == 0) { $flag = 1; goto GIVEN5; $flag = 2; }
+ whereso ($_ == 1) { next; }
$flag = 3;
}
- is($flag, 1, "goto inside given and when to the given stmt");
+ is($flag, 1, "goto inside given and whereso to the given stmt");
}
# Test do { given } as a rvalue
@@ -805,8 +805,8 @@ GIVEN5:
no warnings 'void';
for (0, 1, 2) {
my $scalar = do { given ($_) {
- when ($_ == 0) { $lexical }
- when ($_ == 2) { 'void'; 8, 9 }
+ whereso ($_ == 0) { $lexical }
+ whereso ($_ == 2) { 'void'; 8, 9 }
@things;
} };
is($scalar, shift(@exp), "rvalue given - simple scalar [$_]");
@@ -819,8 +819,8 @@ GIVEN5:
for (0, 1, 2) {
no warnings 'void';
my $scalar = do { given ($_) {
- $lexical when $_ == 0;
- 8, 9 when $_ == 2;
+ $lexical whereso $_ == 0;
+ 8, 9 whereso $_ == 2;
6, 7;
} };
is($scalar, shift(@exp), "rvalue given - postfix scalar [$_]");
@@ -832,7 +832,7 @@ GIVEN5:
for (0, 1, 2) {
my $scalar = do { given ($_) {
no warnings 'void';
- when ($_ == 0) { 5 }
+ whereso ($_ == 0) { 5 }
8, 9;
} };
is($scalar, shift(@exp), "rvalue given - default scalar [$_]");
@@ -844,8 +844,8 @@ GIVEN5:
my @exp = ('3 4 5', '11 12 13', '8 9');
for (0, 1, 2) {
my @list = do { given ($_) {
- when ($_ == 0) { 3 .. 5 }
- when ($_ == 2) { my $fake = 'void'; 8, 9 }
+ whereso ($_ == 0) { 3 .. 5 }
+ whereso ($_ == 2) { my $fake = 'void'; 8, 9 }
@things;
} };
is("@list", shift(@exp), "rvalue given - simple list [$_]");
@@ -857,8 +857,8 @@ GIVEN5:
my @exp = ('3 4 5', '6 7', '12');
for (0, 1, 2) {
my @list = do { given ($_) {
- 3 .. 5 when $_ == 0;
- @things when $_ == 2;
+ 3 .. 5 whereso $_ == 0;
+ @things whereso $_ == 2;
6, 7;
} };
is("@list", shift(@exp), "rvalue given - postfix list [$_]");
@@ -870,7 +870,7 @@ GIVEN5:
my @exp = ('m o o', '8 10', '8 10');
for (0, 1, 2) {
my @list = do { given ($_) {
- when ($_ == 0) { "moo" =~ /(.)/g }
+ whereso ($_ == 0) { "moo" =~ /(.)/g }
8, scalar(@things);
} };
is("@list", shift(@exp), "rvalue given - default list [$_]");
@@ -881,9 +881,9 @@ GIVEN5:
my @exp = ('6 7', '', '6 7');
F: for (0, 1, 2, 3) {
my @list = do { given ($_) {
- continue when $_ <= 1;
- next when $_ == 1;
- next F when $_ == 2;
+ continue whereso $_ <= 1;
+ next whereso $_ == 1;
+ next F whereso $_ == 2;
6, 7;
} };
is("@list", shift(@exp), "rvalue given - default list [$_]");
@@ -893,9 +893,9 @@ GIVEN5:
# Context propagation
my $smart_hash = sub {
do { given ($_[0]) {
- 'undef' when !defined;
- when ($_ >= 1 && $_ <= 3) { 1 .. 3 }
- when ($_ == 4) { my $fake; do { 4, 5 } }
+ 'undef' whereso !defined;
+ whereso ($_ >= 1 && $_ <= 3) { 1 .. 3 }
+ whereso ($_ == 4) { my $fake; do { 4, 5 } }
} };
};
@@ -954,19 +954,19 @@ GIVEN5:
our $given_glob = 5;
local $given_loc = 6;
- when ($_ == 0) { 0 }
+ whereso ($_ == 0) { 0 }
- when ($_ == 1) { my $when_lex = 1 }
- when ($_ == 2) { our $when_glob = 2 }
- when ($_ == 3) { local $when_loc = 3 }
+ whereso ($_ == 1) { my $when_lex = 1 }
+ whereso ($_ == 2) { our $when_glob = 2 }
+ whereso ($_ == 3) { local $when_loc = 3 }
- when ($_ == 4) { $given_lex }
- when ($_ == 5) { $given_glob }
- when ($_ == 6) { $given_loc }
+ whereso ($_ == 4) { $given_lex }
+ whereso ($_ == 5) { $given_glob }
+ whereso ($_ == 6) { $given_loc }
- when ($_ == 7) { $ext_lex }
- when ($_ == 8) { $ext_glob }
- when ($_ == 9) { $ext_loc }
+ whereso ($_ == 7) { $ext_lex }
+ whereso ($_ == 8) { $ext_glob }
+ whereso ($_ == 9) { $ext_loc }
'fallback';
}
@@ -975,9 +975,9 @@ GIVEN5:
my @descriptions = qw<
constant
- when-lexical
- when-global
- when-local
+ whereso-lexical
+ whereso-global
+ whereso-local
given-lexical
given-global
@@ -998,7 +998,7 @@ GIVEN5:
my $id_plus_1 = $id + 1;
given ($id_plus_1) {
do {
- when (/\d/) {
+ whereso (/\d/) {
--$id_plus_1;
continue;
456;
@@ -1011,7 +1011,7 @@ GIVEN5:
}
}
-# Check that values returned from given/when are destroyed at the right time.
+# Check that values returned from given/whereso are destroyed at the right time.
{
{
package Fmurrr;
@@ -1029,7 +1029,7 @@ GIVEN5:
}
my @descriptions = qw<
- when
+ whereso
next
continue
default
@@ -1045,10 +1045,10 @@ GIVEN5:
my $res = do {
given ($id) {
my $x;
- when ($_ == 0) { Fmurrr->new($destroyed, 0) }
- when ($_ == 1) { my $y = Fmurrr->new($destroyed, 1); next }
- when ($_ == 2) { $x = Fmurrr->new($destroyed, 2); continue }
- when ($_ == 2) { $x }
+ whereso ($_ == 0) { Fmurrr->new($destroyed, 0) }
+ whereso ($_ == 1) { my $y = Fmurrr->new($destroyed, 1); next }
+ whereso ($_ == 2) { $x = Fmurrr->new($destroyed, 2); continue }
+ whereso ($_ == 2) { $x }
Fmurrr->new($destroyed, 3);
}
};
@@ -1056,8 +1056,8 @@ GIVEN5:
}
$res_id = $id if $id == 1; # next doesn't return anything
- is $res_id, $id, "given/when returns the right object - $desc";
- is $destroyed, 1, "given/when does not leak - $desc";
+ is $res_id, $id, "given/whereso returns the right object - $desc";
+ is $destroyed, 1, "given/whereso does not leak - $desc";
};
}
@@ -1066,7 +1066,7 @@ GIVEN5:
my @res = (1, do {
given ("x") {
2, 3, do {
- when (/[a-z]/) {
+ whereso (/[a-z]/) {
4, 5, 6, next
}
}
@@ -1095,47 +1095,47 @@ GIVEN5:
f2();
}
-# check that 'when' handles all 'for' loop types
+# check that 'whereso' handles all 'for' loop types
{
my $i;
$i = 0;
for (1..3) {
- when ($_ == 1) {$i += 1 }
- when ($_ == 2) {$i += 10 }
- when ($_ == 3) {$i += 100 }
+ whereso ($_ == 1) {$i += 1 }
+ whereso ($_ == 2) {$i += 10 }
+ whereso ($_ == 3) {$i += 100 }
$i += 1000;
}
- is($i, 111, "when in for 1..3");
+ is($i, 111, "whereso in for 1..3");
$i = 0;
for ('a'..'c') {
- when ($_ eq 'a') {$i += 1 }
- when ($_ eq 'b') {$i += 10 }
- when ($_ eq 'c') {$i += 100 }
+ whereso ($_ eq 'a') {$i += 1 }
+ whereso ($_ eq 'b') {$i += 10 }
+ whereso ($_ eq 'c') {$i += 100 }
$i += 1000;
}
- is($i, 111, "when in for a..c");
+ is($i, 111, "whereso in for a..c");
$i = 0;
for (1,2,3) {
- when ($_ == 1) {$i += 1 }
- when ($_ == 2) {$i += 10 }
- when ($_ == 3) {$i += 100 }
+ whereso ($_ == 1) {$i += 1 }
+ whereso ($_ == 2) {$i += 10 }
+ whereso ($_ == 3) {$i += 100 }
$i += 1000;
}
- is($i, 111, "when in for 1,2,3");
+ is($i, 111, "whereso in for 1,2,3");
$i = 0;
my @a = (1,2,3);
for (@a) {
- when ($_ == 1) {$i += 1 }
- when ($_ == 2) {$i += 10 }
- when ($_ == 3) {$i += 100 }
+ whereso ($_ == 1) {$i += 1 }
+ whereso ($_ == 2) {$i += 10 }
+ whereso ($_ == 3) {$i += 100 }
$i += 1000;
}
- is($i, 111, 'when in for @a');
+ is($i, 111, 'whereso in for @a');
}
diff --git a/t/op/taint.t b/t/op/taint.t
index cdf07249c3..912be0e659 100644
--- a/t/op/taint.t
+++ b/t/op/taint.t
@@ -2400,7 +2400,7 @@ end
use feature 'switch';
no warnings 'experimental::smartmatch';
- my @descriptions = ('when', 'given end', 'default');
+ my @descriptions = ('whereso', 'given end', 'default');
for (qw<x y z>) {
my $letter = "$_$TAINT";
@@ -2409,8 +2409,8 @@ end
my $res = do {
given ($_) {
- when ('x') { $letter }
- when ('y') { goto leavegiven }
+ whereso ('x') { $letter }
+ whereso ('y') { goto leavegiven }
leavegiven: $letter
}
};
diff --git a/t/op/when.t b/t/op/whereso.t
index 2721b7623d..15d29a80e1 100644
--- a/t/op/when.t
+++ b/t/op/whereso.t
@@ -13,63 +13,63 @@ no warnings 'experimental::smartmatch';
plan tests => 42;
foreach(3) {
- CORE::when(3) {
- pass "CORE::when without feature flag";
+ CORE::whereso(3) {
+ pass "CORE::whereso without feature flag";
}
}
use feature 'switch';
foreach(3) {
- CORE::when(3) {
- pass "CORE::when with feature flag";
+ CORE::whereso(3) {
+ pass "CORE::whereso with feature flag";
}
}
foreach(3) {
- when(3) {
- pass "when with feature flag";
+ whereso(3) {
+ pass "whereso with feature flag";
}
}
foreach(0, 1) {
my $x = "foo";
- is($x, "foo", "when lexical scope not started yet");
- when(my $x = ($_ && "bar")) {
- is($x, "bar", "when lexical scope starts");
+ is($x, "foo", "whereso lexical scope not started yet");
+ whereso(my $x = ($_ && "bar")) {
+ is($x, "bar", "whereso lexical scope starts");
}
- is($x, "foo", "when lexical scope ends");
+ is($x, "foo", "whereso lexical scope ends");
}
foreach(3) {
- when($_ == 2) { fail; }
+ whereso($_ == 2) { fail; }
pass;
}
foreach(3) {
- when($_ == 3) { pass; }
+ whereso($_ == 3) { pass; }
fail;
}
foreach(3) {
- when($_ == 2) { fail; }
- when($_ == 3) { pass; }
- when($_ == 4) { fail; }
- when($_ == 3) { fail; }
+ whereso($_ == 2) { fail; }
+ whereso($_ == 3) { pass; }
+ whereso($_ == 4) { fail; }
+ whereso($_ == 3) { fail; }
}
foreach(undef, 3) {
- when(undef) { fail; }
+ whereso(undef) { fail; }
pass;
}
foreach(undef, 1, 3) {
- when(0) { fail; }
+ whereso(0) { fail; }
pass;
}
foreach(undef, 1, 3) {
- when(1) { pass; }
+ whereso(1) { pass; }
fail;
}
@@ -77,108 +77,108 @@ sub is_list_context { wantarray }
sub is_scalar_context { !wantarray && defined(wantarray) }
sub is_void_context { !defined(wantarray) }
foreach(3) {
- when(is_list_context()) { fail; }
+ whereso(is_list_context()) { fail; }
pass;
}
foreach(3) {
- when(is_scalar_context()) { pass; }
+ whereso(is_scalar_context()) { pass; }
fail;
}
foreach(3) {
- when(is_void_context()) { fail; }
+ whereso(is_void_context()) { fail; }
pass;
}
foreach(3) {
- when(is_list_context) { fail; }
+ whereso(is_list_context) { fail; }
pass;
}
foreach(3) {
- when(is_scalar_context) { pass; }
+ whereso(is_scalar_context) { pass; }
fail;
}
foreach(3) {
- when(is_void_context) { fail; }
+ whereso(is_void_context) { fail; }
pass;
}
my $ps = "foo";
foreach(3) {
- when($ps) { pass; }
+ whereso($ps) { pass; }
fail;
}
$ps = "";
foreach(3) {
- when($ps) { fail; }
+ whereso($ps) { fail; }
pass;
}
our $gs = "bar";
foreach(3) {
- when($gs) { pass; }
+ whereso($gs) { pass; }
fail;
}
$gs = "";
foreach(3) {
- when($gs) { fail; }
+ whereso($gs) { fail; }
pass;
}
my @pa = qw(a b c d e);
foreach(3) {
- when(@pa) { pass; }
+ whereso(@pa) { pass; }
fail;
}
@pa = ();
foreach(3) {
- when(@pa) { fail; }
+ whereso(@pa) { fail; }
pass;
}
our @ga = qw(a b c d e);
foreach(3) {
- when(@ga) { pass; }
+ whereso(@ga) { pass; }
fail;
}
@ga = ();
foreach(3) {
- when(@ga) { fail; }
+ whereso(@ga) { fail; }
pass;
}
my %ph = qw(a b c d e f g h i j);
foreach(3) {
- when(%ph) { pass; }
+ whereso(%ph) { pass; }
fail;
}
%ph = ();
foreach(3) {
- when(%ph) { fail; }
+ whereso(%ph) { fail; }
pass;
}
our %gh = qw(a b c d e f g h i j);
foreach(3) {
- when(%gh) { pass; }
+ whereso(%gh) { pass; }
fail;
}
%gh = ();
foreach(3) {
- when(%gh) { fail; }
+ whereso(%gh) { fail; }
pass;
}
my $one = 1;
foreach(3) {
- when($one + 3) { pass; }
+ whereso($one + 3) { pass; }
fail;
}
foreach(3) {
- when($one - 1) { fail; }
+ whereso($one - 1) { fail; }
pass;
}
foreach(3) {
- when(()) { fail; }
+ whereso(()) { fail; }
pass;
}
foreach my $z (3) {
- when(1) { pass; }
+ whereso(1) { pass; }
fail;
}
@@ -186,7 +186,7 @@ my @a = qw(x y z);
my $act = "";
while(@a) {
$act .= "[a@{[0+@a]}]";
- when(shift(@a) eq "y") {
+ whereso(shift(@a) eq "y") {
$act .= "[b]";
}
$act .= "[c]";
@@ -196,11 +196,11 @@ is $act, "[a3][c][a2][b][a1][c]";
$act = "";
{
$act .= "[a]";
- when(0) { $act .= "[b]"; }
+ whereso(0) { $act .= "[b]"; }
$act .= "[c]";
- when(1) { $act .= "[d]"; }
+ whereso(1) { $act .= "[d]"; }
$act .= "[e]";
- when(1) { $act .= "[f]"; }
+ whereso(1) { $act .= "[f]"; }
}
is $act, "[a][c][d]";
diff --git a/t/porting/customized.dat b/t/porting/customized.dat
index b18e7b8abb..40f3e31125 100644
--- a/t/porting/customized.dat
+++ b/t/porting/customized.dat
@@ -25,7 +25,7 @@ autodie cpan/autodie/lib/autodie/hints.pm e1998fec61fb4e82fe46585bd82c73200be6f2
autodie cpan/autodie/t/exceptions.t ad315a208f875e06b0964012ce8d65daa438c036
autodie cpan/autodie/t/lib/Hints_pod_examples.pm 6944c218e9754b3613c8d0c90a5ae8aceccb5c99
autodie cpan/autodie/t/mkdir.t 9e70d2282a3cc7d76a78bf8144fccba20fb37dac
-experimental cpan/experimental/t/basic.t 7029f7ca63251f277d741d155caea44f538d7e96
+experimental cpan/experimental/t/basic.t 4f0396c10b29eddb733f70f66c776fb10bd53a1d
perlfaq cpan/perlfaq/lib/perlfaq5.pod bcc1b6af3b6dff3973643acf8d5e741463374123
perlfaq cpan/perlfaq/lib/perlfaq8.pod bffbc0c8fa828aead24e0891a5e789369a8e0743
podlators pod/perlpodstyle.pod c6500c9950b46e8228d4adbc09a3ee2ef23de2d0
diff --git a/t/run/switches.t b/t/run/switches.t
index d831b8b8c9..7bd1a738e2 100644
--- a/t/run/switches.t
+++ b/t/run/switches.t
@@ -648,7 +648,7 @@ is( $r, "Hello, world!\n", "-E say" );
$r = runperl(
- switches => [ '-E', '"no warnings q{experimental::smartmatch}; given(undef) {when(!defined) { say q(Hello, world!)"}}']
+ switches => [ '-E', '"no warnings q{experimental::smartmatch}; given(undef) {whereso(!defined) { say q(Hello, world!)"}}']
);
is( $r, "Hello, world!\n", "-E given" );
diff --git a/toke.c b/toke.c
index 8b87058d75..fa729382ae 100644
--- a/toke.c
+++ b/toke.c
@@ -374,7 +374,7 @@ static struct debug_tokens {
{ UNLESS, TOKENTYPE_IVAL, "UNLESS" },
{ UNTIL, TOKENTYPE_IVAL, "UNTIL" },
{ USE, TOKENTYPE_IVAL, "USE" },
- { WHEN, TOKENTYPE_IVAL, "WHEN" },
+ { WHERESO, TOKENTYPE_IVAL, "WHERESO" },
{ WHILE, TOKENTYPE_IVAL, "WHILE" },
{ BAREWORD, TOKENTYPE_OPVAL, "BAREWORD" },
{ YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
@@ -8844,14 +8844,14 @@ Perl_yylex(pTHX)
case KEY_vec:
LOP(OP_VEC,XTERM);
- case KEY_when:
+ case KEY_whereso:
if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
return REPORT(0);
pl_yylval.ival = CopLINE(PL_curcop);
Perl_ck_warner_d(aTHX_
packWARN(WARN_EXPERIMENTAL__SMARTMATCH),
- "when is experimental");
- OPERATOR(WHEN);
+ "whereso is experimental");
+ OPERATOR(WHERESO);
case KEY_while:
if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)