| 1 | package Switch::Perlish; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | @ISA = 'Exporter'; | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | @EXPORT = qw/ switch case default fallthrough stop /; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | $VERSION = '1.0.5'; | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Switch::Perlish::Smatch; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use vars qw/ $MATCH $TOPIC $SWITCH $CASE $FALLING $CSTYLE /; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | package Switch::Perlish::Control::_success; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | package Switch::Perlish::Control::_fallthrough; | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | package Switch::Perlish::Control::_stop; | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use constant SUCCESS => 'Switch::Perlish::Control::_success'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use constant FALLTHROUGH => 'Switch::Perlish::Control::_fallthrough'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | ▶ | use constant STOP => 'Switch::Perlish::Control::_stop'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 11 | $CSTYLE = pop(@_) eq 'C'; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | Switch::Perlish->export_to_level(1, @_); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | use Scalar::Util qw/ reftype blessed /; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 98 | ▶ | sub switch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
switch: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 98 | local($TOPIC, $SWITCH) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 98 | ▶ | croak "Invalid code block provided: '$SWITCH'" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | unless reftype($SWITCH) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ## Restore this if we exit successfully so as not to make debugging trickier. | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 98 | my $olderr = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ## Topicalize the topic for the switch block. | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 98 | local *_ = \$TOPIC; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ## We're not falling through until a successful match. | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 98 | local $FALLING = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ## How the switch statement is evaluted: | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ## A successful case (that doesn't fallthrough) will leave the block by | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ## throwing an error object blessed into SUCCESS control exception. However, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ## the user might want to return early for whatever reason, so keep that | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ## result too. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 98 | my @result = eval { $SWITCH->() }; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 98 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ## If something was returned from the block explicitly or a case | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ## succeeded then try to return what seems most appropriate. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 98 | ▶ | if( ( @result and !$err ) or _left_ok($err) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@result and not $err or _left_ok($err)
@result and not $err
MC/DC66%2/3
@result and not $err or _left_ok($err)
@result
not $err
_left_ok($err)
Truth table60%3/5
A and not(B) or C
A= @resultB= not $errC= _left_ok($err)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 85 | $@ = $olderr; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 85 | ▶ | my @r = @result ? @result : @$err; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 85 | ▶ | return defined wantarray ? wantarray ? @r : $r[-1] : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | die $err | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 180 | ▶ | sub _called_by { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_called_by: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 180 | my $name = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 180 | ▶ | my $depth = defined( $_[1] ) ? $_[1] : 4; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 180 | return +(caller $depth)[3] =~ /::\Q$name\E$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ## Did we leave the switch() from a control exception? | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 86 | ▶ | sub _left_ok { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_left_ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 86 | return blessed($_[0]) and $_[0]->isa(SUCCESS) | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | or $_[0]->isa(STOP); | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ## Exit the switch block and set $@ to a S::P::_success control exception. | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ## NB: This blessing trickery is for people who want the result propagated. | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 69 | ▶ | sub _end_case { die bless \@_, SUCCESS } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_end_case: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub fallthrough { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fallthrough: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ## make sure we're not called out of context | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | croak "Not called within a case statement" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | if !_called_by(case => 5); | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | die bless( \do{ | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $msg = "The fallthrough control exception from Switch::Perlish" | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | }, FALLTHROUGH ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ## Make sure this isn't called out of context. | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | croak "Not called within a case statement" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | if !_called_by(case => 5); | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ## Was, "The stop control exception from Switch::Perlish", but that could be | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ## assigned to which isn't expected behaviour in the case of stop;. | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | die bless([], STOP ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 88 | ▶ | sub _exec_block { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_block: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 88 | my @ret = eval { $CASE->() }; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ## Check for fallthrough control exception. | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 88 | ▶ | if blessed($@) and $@->isa(FALLTHROUGH); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($@) and $@->isa("Switch::Perlish::Control::_fallthrough")
MC/DC100%2/2
builtin::blessed($@) and $@->isa("Switch::Perlish::Control::_fallthrough")
builtin::blessed($@)
$@->isa("Switch::Perlish::Control::_fallthrough")
Truth table100%3/3
A and B
A= builtin::blessed($@)B= $@->isa("Switch::Perlish::Control::_fallthrough")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ## Check for stop control exception. | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 87 | ▶ | die $@ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($@) and $@->isa("Switch::Perlish::Control::_stop")
MC/DC50%1/2
builtin::blessed($@) and $@->isa("Switch::Perlish::Control::_stop")
builtin::blessed($@)
$@->isa("Switch::Perlish::Control::_stop")
Truth table66%2/3
A and B
A= builtin::blessed($@)B= $@->isa("Switch::Perlish::Control::_stop")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | if blessed($@) and $@->isa(STOP); | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ## Propagate non-control exception. | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 83 | ▶ | die $@ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 79 | ▶ | _end_case @ret | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and not _called_by("default", 2)
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING
MC/DC100%3/3
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and not _called_by("default", 2)
$Switch::Perlish::CSTYLE
$Switch::Perlish::FALLING
not _called_by("default", 2)
Truth table100%4/4
A and B and not(C)
A= $Switch::Perlish::CSTYLEB= $Switch::Perlish::FALLINGC= not _called_by("default", 2)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | unless $CSTYLE and $FALLING and !_called_by(default => 2); | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 156 | ▶ | sub case { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
case: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ## If you want smatching, use S::P::Smatch::match not S::P::case. | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 156 | ▶ | croak "Not called within a switch statement\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | if !_called_by('switch'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 155 | local($MATCH, $CASE) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 155 | ▶ | croak "No case block provided" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $Switch::Perlish::CASE or $Switch::Perlish::CSTYLE
MC/DC100%2/2
defined $Switch::Perlish::CASE or $Switch::Perlish::CSTYLE
defined $Switch::Perlish::CASE
$Switch::Perlish::CSTYLE
Truth table100%3/3
A or B
A= defined $Switch::Perlish::CASEB= $Switch::Perlish::CSTYLE
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | if !defined($CASE) and !$CSTYLE; | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ## Single arg case and using CSTYLE and we're falling. | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 154 | ▶ | if $CSTYLE and $FALLING and @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and @_ == 1
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING
MC/DC100%3/3
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and @_ == 1
$Switch::Perlish::CSTYLE
$Switch::Perlish::FALLING
@_ == 1
Truth table100%4/4
A and B and C
A= $Switch::Perlish::CSTYLEB= $Switch::Perlish::FALLINGC= @_ == 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ## keep going if we're falling, otherwise smatch | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 152 | ▶ | unless $CSTYLE and $FALLING | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING or "Switch::Perlish::Smatch"->match($Switch::Perlish::TOPIC, $Switch::Perlish::MATCH)
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING
MC/DC100%3/3
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING or "Switch::Perlish::Smatch"->match($Switch::Perlish::TOPIC, $Switch::Perlish::MATCH)
$Switch::Perlish::CSTYLE
$Switch::Perlish::FALLING
"Switch::Perlish::Smatch"->match($Switch::Perlish::TOPIC, $Switch::Perlish::MATCH)
Truth table100%5/5
A and B or C
A= $Switch::Perlish::CSTYLEB= $Switch::Perlish::FALLINGC= "Switch::Perlish::Smatch"->match($Switch::Perlish::TOPIC, $Switch::Perlish::MATCH)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | or Switch::Perlish::Smatch->match($TOPIC, $MATCH); | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ## There's been a match, so keep on falling. | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 86 | ▶ | $FALLING = 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | if $CSTYLE; | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ## Single arg case and using CSTYLE and we matched. | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 86 | ▶ | if $CSTYLE and $FALLING and @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and @_ == 1
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING
MC/DC66%2/3
$Switch::Perlish::CSTYLE and $Switch::Perlish::FALLING and @_ == 1
$Switch::Perlish::CSTYLE
$Switch::Perlish::FALLING
@_ == 1
Truth table75%3/4
A and B and C
A= $Switch::Perlish::CSTYLEB= $Switch::Perlish::FALLINGC= @_ == 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 83 | _exec_block; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | ▶ | sub default { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ## Make sure we're in a switch block. | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | ▶ | croak "Not called within a switch statement\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | if !_called_by('switch'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | local $CASE = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | _exec_block; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | Switch::Perlish - A Perlish implementation of the C<switch> statement. | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1.0.5 - Mostly cosmetic changes for this release. | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | use Switch::Perlish; | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | switch $var, sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | case 'foo', | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub { print "$var is equal to 'foo'\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | case 42, | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | sub { print "$var is equal to 42\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | fallthrough }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | case [qw/ foo bar baz /], | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | sub { print "$var found in list\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | case { foo => 'bar' }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub { print "$var key found in hash\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | case \&func, | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub { print "$var as arg to func() returned true\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | case $obj, | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | sub { print "$var is method in $obj and returned true\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | case qr/\bfoo\b/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub { print "$var matched against foo\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | default | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub { print "$var did not find a match\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | =head1 BACKGROUND | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | If you're unfamiliar with C<switch> then this is the best place to start. A | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | C<switch> statement is essentially syntactic sugar for an C<if>/C<elsif>/C<else> | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | chain where the same C<$variable> is tested in every conditional e.g: | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | my $foo = 'a string'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | if($foo eq 'something') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | print '$foo matched "something"'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } elsif($foo eq 'a string') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | print '$foo matched "a string"'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | print '$foo matched nothing'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | This simply matches C<$foo> against a series of strings, then defaulting to the | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | last C<else> block if nothing matched. An equivalent C<switch> statement (using | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | this module) would be: | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | use Switch::Perlish; | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | my $foo = 'a string'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | switch $foo, sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | case 'something', | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub { print '$foo matched "something"' }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | case 'a string', | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | sub { print '$foo matched "a string"' }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | default | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | sub { print '$foo matched nothing' }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | So the first argument to C<switch> is the thing to be tested (in the code above, | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | C<$foo>), and the second argument is the block of tests. Each C<case> statement | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | matches its first argument against C<$foo>, and if the match is successful, | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | the associated block is executed, so running the above code outputs: C<$foo | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | matched "a string">. Note the use of semi-colon at the end of the C<switch>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | C<case> and C<default> calls - they're just simple subroutine calls. | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | This is a Perl-oriented implementation of the C<switch> statement. It uses | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | smart-matching in C<case>s which can be configured and extended by the user. | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | There is no magical syntax so C<switch>/C<case>/C<default> expect coderefs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | which are most simply provided by anonymous subroutines. By default successful | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | C<case> statements do not fall through[1]. To fall through a C<case> block | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | call the C<fallthrough> subroutine explicitly. For C<C> style C<switch> | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | behaviour[2] simply call the module with an upper-case I<C> i.e | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | use Switch::Perlish 'C'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | I<< [1] To 'fall through' in a C<case> block means that the C<switch> block | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | isn't exited upon success. >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | I<< [2] upon a C<case> succesfully matching all subsequent C<case>s succeed; to | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | break out from the current C<switch> completely use C<stop>. >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | =head2 Smart Matching | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | The idea behind I<smart matching> is that the given values are matched | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | in an intelligent manner, so as to get a meaningful result I<regardless> | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | of the values' types. This allows for flexible code and a certain amount of | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | "just do it" when using I<smart matching>. Below is a basic example using | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | I<smart matching> (which is done implictly in C<case>) where a simple value | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | is being matched against an array e.g | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | use Switch::Perlish; | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | my $num = $ARGV[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | switch $num, sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | case undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | sub { die "Usage: $0 NUM\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | case [0 .. 10], | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub { print "Your number was between 0 and 10" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | case [11 .. 100], | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | sub { print "Your number was between 11 and 100" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | case [101 .. 1000], | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | sub { print "Your number was between 101 and 1000" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | default | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | sub { print "Your number was less than 0 or greater than 1000" }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | So here the I<smart matching> is checking for the existence of C<$num> in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | provided arrays. In the above code I<ranges> happen to be used, but any array | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | would suffice. To see how different value types compare with each other see. | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | L<Switch::Perlish::Smatch::Comparators>, which provides descriptions for all | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | the default comparators. | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | The code behind this I<smart matching> can be found in | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | L<Switch::Perlish::Smatch> which itself delegates to the appropriate comparator | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | subroutine depending on the value types. See L<Switch::Perlish::Smatch> for more | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | details on the I<smart matching> implementation and how it can be extended. | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | =head1 COMPARISON | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | Because there is an existing module which implements C<switch> this section | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | intends to provide clarification of the differences that module, L<Switch>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | and this one. | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =head2 Native vs. New | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | To create a more natural C<switch> syntax, L<Switch> uses source filters[3], | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | which facilitate the creation of this natural syntax. C<Switch::Perlish> | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | however uses the native syntax of perl, so what you code is what you see. | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | The big advantage of source filtering is the ability to create new syntax, | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | but it has several disadvantages - the new syntax can conflict with, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | break, existing code, the filtered code can be difficult to debug and because | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | you can't easily see the post-filtered code it can be difficult to integrate | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | into production code. The I<raison d'E<ecirc>tre> for this module is to have | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | the syntax of C<switch> without the baggage that goes with filtered code. | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | =head2 Extensibility | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | The L<Switch> module deals with the Perl's types superbly, however, that is all, | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | so there is no extensibility as such. This module was designed from the outset | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | to allow an extensibilty of how types are dealt with, i.e how they are compared, | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | and this is done through the companion module L<Switch::Perlish::Smatch>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | =head2 The C<sub> keyword | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | Unlike L<Switch>, C<Switch::Perlish> requires the use of the the C<sub> keyword | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | when creating blocks. This is because there is no standard way of magically | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | coercing bare blocks into closures, unless one uses the C<(E<amp>)> prototype, | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | and that is only applicable where it is the first argument. Also, prototypes are | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | too restrictive for what is intended as a very I<perlish> module e.g | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | $ perl -e 'sub f(&) { print $_[0]->() } sub g{'foo'} my $r = \&g; f $r' | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | Type of arg 1 to main::f must be block or sub {} (not private variable) | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | at -e line 1, at EOF | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | Execution of -e aborted due to compilation errors. | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | So, for now, 3 extra keystrokes are necessary when using blocks with | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | C<Switch::Perlish>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | I<< [3] see. L<Filter::Simple> for more info on source filters >>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head1 SUBROUTINES | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =item C<< switch( $topic, $block ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | Execute the given C<$block> allowing C<case> statements to access the C<$topic>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | This, along with C<case> and C<default>, will also attempt to return in the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | manner as normal subroutines e.g you can assign to the result of them. | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | =item C<< case( $match, $block ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | If the current C<$topic> successfully I<smart matches> against C<$match> then | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | execute C<$block> and exit from current C<switch>, but if using C<C> style | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | C<switch> behaviour, then continue executing the block and all subsequent | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | C<case> C<$block>s until the end of the current C<switch> or a call to C<stop>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | Also, if using C<C> style C<switch> behaviour then C<$block> is optional. I<NB>: | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | this subroutine cannot be called outside of C<switch>, if you want to use | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | I<smart matching> functionality, see. L<Switch::Perlish::Smatch>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | =item C<< default( $block ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | Execute C<$block> and exit from C<switch>. I<NB>: this subroutine cannot be | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | called outside of C<switch>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =item C<< fallthrough() >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | Fall through the the current C<case> block i.e continue to evaluate the rest of | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | the C<switch> block. I<NB>: this subroutine cannot be called outside of C<case>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | =item C<< stop() >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | Use in C<case> blocks to exit the current C<switch> block, ideally when used | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | with the C<C> style behaviour as it mimics C<C>'s C<break>. I<NB>: this | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | subroutine cannot be called outside of C<case>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | =head2 Globals | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =item C<$SWITCH> | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | The current C<switch> block. | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | =item C<$CASE> | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | The current C<case> block. | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | =item C<$TOPIC> | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | The current topic block, also aliased to C<$_>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | =item C<$MATCH> | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | The current thing being matched against. | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | =item C<$CSTYLE> | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | If C<Switch::Perlish> is called with the I<C> argument, this is set to | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | true and C<C> style C<switch> behaviour is enabled. | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | =item C<$FALLING> | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | Set to true when falling through the current C<switch> block i.e set to true | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | when C<fallthrough> has been called. | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | =head1 SEE. ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | L<Switch> | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | L<How do I create a switch or case statement?|perlfaq7/"How_do_I_create_a_switch_or_case_statement?"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | L<Basic_BLOCKs_and_Switch_Statements|Switch Statements|perlsyn/"Basic_BLOCKs_and_Switch_Statements"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | L<Switch::Perlish::Smatch> | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | L<Switch::Perlish::Smatch::Comparators> | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | Implement localizing comparators | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | Test with earlier versions of C<perl> | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | Drop C<warnings> for compatibility with older perls? | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | Allow lists as the topic and/or cases to match against | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | Dan Brook C<< <mr.daniel.brook@gmail.com> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | Copyright (c) 2006, Dan Brook. All Rights Reserved. This module is free | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | software. It may be used, redistributed and/or modified under the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||