Acme-ComeFrom
view release on metacpan or search on metacpan
comefrom label; print "Branch 2.1\n"; exit;
comefrom label; print "Branch 2.2\n";
EXPR0: print "To be\n"; exit;
comefrom "EXPR".int(rand(2)); print "Not to be\n";
DESCRIPTION
INTERCAL programmers have for a long time monopolized the enormously
powerful construct "COME FROM", both as a flow-control replacement to
"goto", and as a simple way to mark parallel execution branches in the
multi-thread variant.
But now, with Acme::ComeFrom, we Perl hackers can finally be on par with
them in terms of wackiness, if not in obfuscation.
Just like "goto", "comefrom" comes in three different flavors:
comefrom LABEL
The "comefrom-LABEL" form finds the statement labeled with "LABEL"
and jumps to the "comefrom" each time just *before* that statement's
execution. The "comefrom" may not be inside any construct that
inc/Test/Builder.pm view on Meta::CPAN
# $^C was only introduced in 5.005-ish. We do this to prevent
# use of uninitialized value warnings in older perls.
$^C ||= 0;
use strict;
use vars qw($VERSION);
$VERSION = '0.70';
$VERSION = eval $VERSION; # make the alpha version come out as a number
# Make Test::Builder thread-safe for ithreads.
BEGIN {
use Config;
# Load threads::shared when threads are turned on.
# 5.8.0's threads are so busted we no longer support them.
if( $] >= 5.008001 && $Config{useithreads} && $INC{'threads.pm'}) {
require threads::shared;
# Hack around YET ANOTHER threads::shared bug. It would
# occassionally forget the contents of the variable when sharing it.
# So we first copy the data, then share, then put our copy back.
*share = sub (\[$@%]) {
my $type = ref $_[0];
my $data;
if( $type eq 'HASH' ) {
%$data = %{$_[0]};
}
elsif( $type eq 'ARRAY' ) {
@$data = @{$_[0]};
}
elsif( $type eq 'SCALAR' ) {
$$data = ${$_[0]};
}
else {
die("Unknown type: ".$type);
}
$_[0] = &threads::shared::share($_[0]);
if( $type eq 'HASH' ) {
%{$_[0]} = %$data;
}
elsif( $type eq 'ARRAY' ) {
@{$_[0]} = @$data;
}
elsif( $type eq 'SCALAR' ) {
${$_[0]} = $$data;
}
else {
die("Unknown type: ".$type);
}
return $_[0];
};
}
# 5.8.0's threads::shared is busted when threads are off
# and earlier Perls just don't have that module at all.
else {
*share = sub { return $_[0] };
*lock = sub { 0 };
}
}
#line 128
inc/Test/Builder.pm view on Meta::CPAN
my $test_results = $self->{Test_Results};
if( @$test_results ) {
# The plan? We have no plan.
if( $self->{No_Plan} ) {
$self->_print("1..$self->{Curr_Test}\n") unless $self->no_header;
$self->{Expected_Tests} = $self->{Curr_Test};
}
# Auto-extended arrays and elements which aren't explicitly
# filled in with a shared reference will puke under 5.8.0
# ithreads. So we have to fill them in by hand. :(
my $empty_result = &share({});
for my $idx ( 0..$self->{Expected_Tests}-1 ) {
$test_results->[$idx] = $empty_result
unless defined $test_results->[$idx];
}
my $num_failed = grep !$_->{'ok'},
@{$test_results}[0..$self->{Curr_Test}-1];
my $num_extra = $self->{Curr_Test} - $self->{Expected_Tests};
inc/Test/More.pm view on Meta::CPAN
# There's faster ways to do this, but this is easiest.
local $^W = 0;
# It really doesn't matter how we sort them, as long as both arrays are
# sorted with the same algorithm.
#
# Ensure that references are not accidentally treated the same as a
# string containing the reference.
#
# Have to inline the sort routine due to a threading/sort bug.
# See [rt.cpan.org 6782]
#
# I don't know how references would be sorted so we just don't sort
# them. This means eq_set doesn't really work with refs.
return eq_array(
[grep(ref, @$a1), sort( grep(!ref, @$a1) )],
[grep(ref, @$a2), sort( grep(!ref, @$a2) )],
);
}
lib/Acme/ComeFrom.pm view on Meta::CPAN
comefrom label; print "Branch 2.2\n";
EXPR0: print "To be\n"; exit;
comefrom "EXPR".int(rand(2)); print "Not to be\n";
=head1 DESCRIPTION
B<INTERCAL> programmers have for a long time monopolized the enormously
powerful construct C<COME FROM>, both as a flow-control replacement to
C<goto>, and as a simple way to mark parallel execution branches in
the multi-thread variant.
But now, with B<Acme::ComeFrom>, we Perl hackers can finally be on par
with them in terms of wackiness, if not in obfuscation.
Just like C<goto>, C<comefrom> comes in three different flavors:
=over 4
=item comefrom LABEL
( run in 0.250 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )