Skip to content

@lucasbuchala /p6
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
p6
This is little Perl 5 wrapper script that calls Perl 6 implementation executables.
You'll need Capture::Tiny installed.
Usage:
p6 ... # Runs all four implementations
p6 -- ... # Use "--" if you need to pass options directly to the implementations
p6 -m ... # Runs only perl6-m
p6 -p ... # Runs only perl6-p
p6 -j ... # Runs only perl6-j
p6 -n ... # Runs only niecza
p6 -M ... # Runs all, except perl6-m
p6 -P ... # Runs all, except perl6-p
p6 -J ... # Runs all, except perl6-j
p6 -N ... # Runs all, except niecza
p6 -m -p ... # Runs only perl6-m and perl6-p
p6 -J -N ... # Runs all, except perl6-j and niecza
Example output:
$ cat hello.pl
use v6;
say 'Hello world';
$ p6 hello.pl
Running perl6-m ... ok
Running perl6-p ... ok
Running perl6-j ... ok
Running niecza ... ok
perl6-m, perl6-p, perl6-j, niecza: Hello world
$ p6 -e 'say "Hello world"'
Running perl6-m ... ok
Running perl6-p ... ok
Running perl6-j ... ok
Running niecza ... ok
perl6-m, perl6-p, perl6-j, niecza: Hello world
$ p6 -v
Running perl6-m ... ok
Running perl6-p ... ok
Running perl6-j ... ok
Running niecza ... ok
niecza: This is Niecza Perl 6 v24-109-g48a8de3
perl6-m: This is perl6 version 2014.06 built on MoarVM version 2014.06
perl6-p: This is perl6 version 2014.06 built on parrot 6.5.0 revision 0
perl6-j: This is perl6 version 2014.06-12-ga7b4cba built on JVM
$ p6 -e 'exit 42'
Running perl6-m ... not ok (exit status: 42)
Running perl6-p ... not ok (exit status: 42)
Running perl6-j ... not ok (exit status: 42)
Running niecza ... not ok (exit status: 42)
perl6-m, perl6-p, perl6-j, niecza: (no output)
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case no_auto_abbrev);
use Capture::Tiny qw(capture);
(my $PROGNAME = $0) =~ s|.*/||;
my @KEYS = qw(m p j n);
my %PROGRAMS = (
'm' => 'perl6-m',
'p' => 'perl6-p',
'j' => 'perl6-j',
'n' => 'niecza',
);
my $v;
my $e;
my %Run;
my $Verbose = 1;
my $Show_stdout = 1;
my $Show_stderr = 1;
GetOptions(
'v' => \$v,
'e=s' => \$e,
'stdout|out!' => \$Show_stdout,
'stderr|err!' => \$Show_stderr,
'quiet|silent' => sub { $Verbose = 0 },
'm|moarvm' => sub { $Run{m} = 1 },
'p|parrot' => sub { $Run{p} = 1 },
'j|jvm' => sub { $Run{j} = 1 },
'n|niecza' => sub { $Run{n} = 1 },
'M|no-moarvm' => sub { $Run{m} = 0 },
'P|no-parrot' => sub { $Run{p} = 0 },
'J|no-jvm' => sub { $Run{j} = 0 },
'N|no-niecza' => sub { $Run{n} = 0 },
) or die "$PROGNAME: Error parsing options\n";
my @Args = @ARGV;
unshift @Args, '-v' if $v;
unshift @Args, '-e', $e if defined $e;
die "Usage: $PROGNAME [options] arguments\n" unless @Args;
my @Programs = grep { $Run{$_} } @KEYS;
@Programs = grep { exists $Run{$_} ? $Run{$_} : 1 } @KEYS if not @Programs;
my (%Stdout, %Stderr);
foreach my $letter (@Programs) {
my $program = $PROGRAMS{$letter};
print "Running $program ... " if $Verbose;
my ($out, $err, $exit) = capture { system($program, @Args) };
(my $n = $exit) >>= 8;
print $exit == 0 ? 'ok' : "not ok (exit status: $n)", "\n" if $Verbose;
if (not $Verbose) {
warn "$program returned non-zero exit status\n" if $exit != 0;
}
push @{ $Stdout{ length $out ? $out : '(no output)' } }, $program;
push @{ $Stderr{$err} }, $program if length $err;
}
if ($Show_stdout) {
foreach my $out (sort keys %Stdout) {
my $x = join ', ', @{ $Stdout{$out} };
chomp $out;
my $s = $out =~ /\n/ ? "\n" : ' ';
print "$x:$s$out\n";
}
}
if ($Show_stderr) {
foreach my $err (sort keys %Stderr) {
my $x = join ', ', @{ $Stderr{$err} };
chomp $err;
my $s = $err =~ /\n/ ? "\n" : ' ';
print STDERR "$x:$s$err\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.