my $consider = 'foo';
${{
bar => sub { print "Barred!\n" },
foo => sub { print "Fooed for thought...\n" }
}}{$consider}();
####
{
my $continue = 1;
$_->[1]() for grep {
my ($cond, $then, $break)=@$_;
local $_='boz'; # This is your given
$continue and
$cond->() and do { $continue = !defined $break; 1}
}
[sub {/z/}, sub { print "Hi!\n" }],
[sub {/o/}, sub { print "Oh!\n" }, 'break'],
[sub {1}, sub { print "This is the default\n" }]
;
}
####
{
my $continue = 1;
sub given ($$) {
local $_ = shift;
my $next = shift;
my ($cond, $then);
while ($next) {
($cond, $then, $next) = @$next;
$then->() if $cond->() and $then;
$continue or last;
}
}
sub when (&$) { [$_[0], @{$_[1]}] }
sub then (&;$) { [@_] }
sub default(&) { [@_] }
sub done() { $continue = 0 }
sub isit ($$) { my @args=@_; [sub { $_ eq $args[0] }, @{$args[1]}] }
}
given 'baz',
isit 'baz', then { print "String match!\n" }
when {/z/} then { print "Hi!\n" }
when {/o/} then { print "Oh!\n"; done }
default { print "This is the default\n" }
;