Switch-Right
view release on metacpan or search on metacpan
lib/Switch/Right.pm view on Meta::CPAN
}xms;
# Unpack and enchant the "when" expression...
my ($JUNCTIVE, $MOD_EXPR) = (q{}, $pos->{mod});
if ($MOD_EXPR =~ $JUNCTIVE_EXPR) {
($JUNCTIVE, $MOD_EXPR) = ( $+{JUNC}, _apply_term_magic($+{EXPR}) );
}
# Convert postfix "when" to a postfix "if" (preserving Afterwhen info for continue())...
substr($BLOCK, $pos->{from}, $pos->{len})
= "BEGIN { \$^H{'Switch::Right/Afterwhenprev'} = \$^H{'Switch::Right/Afterwhen'};"
. " \$^H{'Switch::Right/Afterwhen'} = 'Afterpostfixwhen$ID'; }"
. "$pos->{expr}, break if smartmatch(\$_, $JUNCTIVE scalar($MOD_EXPR))"
. ";Afterpostfixwhen$ID:"
. "BEGIN { \$^H{'Switch::Right/Afterwhen'} = \$^H{'Switch::Right/Afterwhenprev'}; }"
. $pos->{end};
}
return $BLOCK;
}
# Change the target expression of a "when" to implement all the magic behaviours...
sub _apply_term_magic ($EXPR) {
# Apply compile-time expression folding...
( run in 0.617 second using v1.01-cache-2.11-cpan-49f99fa48dc )