Skip to content

support finding perl via plenv #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions bin/plx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ sub resolve_perl_via_perlbrew {
my ($self, $perl) = @_;
stderr "Resolving perl '${perl}' via perlbrew";
local %ENV = our %orig_env;
barf "Couldn't find perlbrew in \$PATH"
stderr "Couldn't find perlbrew in \$PATH", return
unless my $perlbrew = File::Which::which('perlbrew');
my @list = $self->slurp_command($perlbrew, 'list');
barf join(
Expand All @@ -485,6 +485,23 @@ sub resolve_perl_via_perlbrew {
return $perl_path;
}

sub resolve_perl_via_plenv {
my ($self, $perl) = @_;
stderr "Resolving perl '${perl}' via plenv";
local %ENV = our %orig_env;
stderr "Couldn't find plenv in \$PATH", return
unless my $plenv = File::Which::which('plenv');
my @list = $self->slurp_command($plenv, 'versions');
barf join(
"\n", "No such plenv perl '${perl}', choose from:\n", @list, ''
) unless grep $_ eq $perl, map /(\S+)/, @list;
my ($perl_path) = do { local $ENV{PLENV_VERSION} = $perl;
$self->slurp_command( $plenv, qw(which perl) );
};
return $perl_path;
}


sub run_config_perl_set {
my ($self, $new_perl) = @_;
barf "plx --config perl set <perl>" unless $new_perl;
Expand All @@ -497,8 +514,13 @@ sub run_config_perl_set {
if (my $resolved = File::Which::which($new_perl)) {
$new_perl = $resolved;
} else {
$new_perl =~ s/^perl5/perl-5/; # perl binary to perlbrew name
$new_perl = $self->resolve_perl_via_perlbrew($new_perl);
$new_perl =
do {
# convert perl binary to perlbrew name
$self->resolve_perl_via_perlbrew( do { ( my $new_perl = $new_perl ) =~ s/^perl5/perl-5/ ; $new_perl } )
# try plenv, but use the actual spec the user passed.
// $self->resolve_perl_via_plenv($perl_spec);
} or barf "Couldn't find perl '${new_perl}'";
}
}
barf "Not executable: $new_perl" unless -x $new_perl;
Expand Down Expand Up @@ -748,7 +770,7 @@ next run:
plx --init

If we want a different perl - say, we have a C<perl5.30.1> in our path, or
a C<perl-5.30.1> built in perlbrew, we'd instead run:
a C<perl-5.30.1> built in perlbrew or plenv, we'd instead run:

plx --init 5.30.1

Expand Down Expand Up @@ -846,7 +868,7 @@ L</--cmd>, L</--exec> and L</--perl> commands by providing them in

plx --config perl # Show perl binary
plx --config perl set /path/to/perl # Select exact perl binary
plx --config perl set perl-5.xx.y # Select perl via $PATH or perlbrew
plx --config perl set perl-5.xx.y # Select perl via $PATH, perlbrew, or plenv

plx --config libspec # Show lib specifications
plx --config libspec add <name> <path> # Add lib specification
Expand Down Expand Up @@ -895,12 +917,12 @@ Prints out the usage information (i.e. the L</SYNOPSIS>) for plx.
plx --init # resolve 'perl' in $PATH
plx --init perl # (ditto)
plx --init 5.28.0 # looks for perl5.28.0 in $PATH
# or perl-5.28.0 in perlbrew
# or perl-5.28.0 in perlbrew or plenv
plx --init /path/to/some/perl # uses the absolute path directly

Initializes the layout.

If a perl name is passed, attempts to resolve it via C<$PATH> and C<perlbrew>
If a perl name is passed, attempts to resolve it via C<$PATH>, C<perlbrew>, or C<plenv>
and sets the result as the layout perl; if not looks for just C<perl>.

Creates the following libspec config:
Expand Down Expand Up @@ -1045,7 +1067,10 @@ Third, if the (current) spec begins C<perl5>, we replace it with C<perl-5>.
Fourth, we search C<$PATH> for a C<perlbrew> binary, and ask it if it has a
perl named after the spec, and record that if so.

Fifth, we shrug and hope the user can come up with an absolute path next time.
Fifth, we search C<$PATH> for a C<plenv> binary, and ask it if it has a
perl named after the spec, and record that if so.

Sixth, we shrug and hope the user can come up with an absolute path next time.

B<Note:> The original spec passed to C<set> is recorded in C<.plx/perl.spec>,
so if you intend to share the C<.plx> directory across multiple machines via
Expand Down