From b656f11fe184dd7107e87d38fad61cd7466f8a54 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Wed, 3 Nov 2021 18:17:00 -0400 Subject: [PATCH 1/2] support finding perl via plenv --- bin/plx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/plx b/bin/plx index b4a5437..a07d92b 100644 --- a/bin/plx +++ b/bin/plx @@ -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( @@ -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 " unless $new_perl; @@ -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; From 7e3eb2641c5fb0101f323d2b0102439c5204d566 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Sun, 22 Jan 2023 09:30:22 -0500 Subject: [PATCH 2/2] update docs to mention plenv --- bin/plx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) mode change 100644 => 100755 bin/plx diff --git a/bin/plx b/bin/plx old mode 100644 new mode 100755 index a07d92b..22f35e1 --- a/bin/plx +++ b/bin/plx @@ -770,7 +770,7 @@ next run: plx --init If we want a different perl - say, we have a C in our path, or -a C built in perlbrew, we'd instead run: +a C built in perlbrew or plenv, we'd instead run: plx --init 5.30.1 @@ -868,7 +868,7 @@ L, L and L 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 # Add lib specification @@ -917,12 +917,12 @@ Prints out the usage information (i.e. the L) 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 +If a perl name is passed, attempts to resolve it via C<$PATH>, C, or C and sets the result as the layout perl; if not looks for just C. Creates the following libspec config: @@ -1067,7 +1067,10 @@ Third, if the (current) spec begins C, we replace it with C. Fourth, we search C<$PATH> for a C 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 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 The original spec passed to C is recorded in C<.plx/perl.spec>, so if you intend to share the C<.plx> directory across multiple machines via