forked from gknocke/Crypt-PKCS10
-
Notifications
You must be signed in to change notification settings - Fork 5
/
runbrew
executable file
·61 lines (45 loc) · 1.12 KB
/
runbrew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/perl
#
# This software is Copyright (c) 2016 Timothe Litt
#
# See LICENSE for details.
#
# If perlbrew is detected, run the current (or if none, highest) version on a command.
# Otherwise, use the system perl
use warnings;
use strict;
use Cwd qw/getcwd/;
use Sort::Versions;
my $wd;
END {
if( $wd ) {
chdir( $wd ) or die( "Can't chdir to $wd: $!\n" );
}
}
if( @ARGV && $ARGV[0] eq '-in' && $ARGV[1] ) {
shift;
my $in = shift;
$wd = getcwd;
chdir( $in ) or die( "Can't chdir to $in: $!\n" );
}
#my $cmd = join( ' ', @ARGV );
unless( system( 'which perlbrew >/dev/null 2>&1' ) == 0 ) {
exit( system( @ARGV ) );
}
my $perl;
my @avail = split( /\n/, `perlbrew list` );
foreach my $p (@avail) {
if( $p =~ s/^(\*| ) perl-(\S+)\s*$/$2/ ) {
if( $1 eq '*' ) {
$perl = $p;
last;
}
}
}
if( !defined $perl ) {
@avail = sort { -1 * versioncmp( $a, $b ) } @avail;
$perl = $avail[0];
}
die "No perl found" unless( defined $perl );
#print( "Using perl $perl for $cmd\n" );
exit( system( qw(perlbrew exec --quiet --with), "perl-$perl", @ARGV ) );