Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New feature: "perlbrew install --switch $perl"

Automatically switches to the newly-installed Perl once installation
completes successfully.

This means that a good recommendation for newcomers to Perl who've installed
Perlbrew can be simply

    perlbrew install --switch stable

rather than

    perlbrew install 5.16.2
    perlbrew switch 5.16.2

The latter approach has the additional disadvantage that the appropriate
"latest stable Perl" version changes over time.
  • Loading branch information...
commit 6da850ee4e9f58f16514659195767fc09de57331 1 parent e4353a5
@arc arc authored
Showing with 23 additions and 2 deletions.
  1. +3 −0  bin/perlbrew
  2. +10 −0 lib/App/perlbrew.pm
  3. +10 −2 t/installation3.t
View
3  bin/perlbrew
@@ -203,6 +203,9 @@ Options for C<install> command:
-j $n Parallel building and testing. ex. C<perlbrew install -j 5 perl-5.14.2>
-n --notest Skip testing
+ --switch Automatically switch to this Perl once successfully
+ installed, as if with `perlbrew switch <version>`
+
--as Install the given version of perl by a name.
ex. C<perlbrew install perl-5.6.2 --as legacy-perl>
View
10 lib/App/perlbrew.pm
@@ -144,6 +144,7 @@ sub new {
'help|h',
'version',
'root=s',
+ 'switch',
# options passed directly to Configure
'D=s@',
@@ -868,6 +869,9 @@ sub run_command_install {
die $help_message;
}
+ $self->switch_to($installation_name)
+ if $self->{switch};
+
return;
}
@@ -1382,6 +1386,12 @@ sub run_command_switch {
return;
}
+ $self->switch_to($dist, $alias);
+}
+
+sub switch_to {
+ my ( $self, $dist, $alias ) = @_;
+
die "Cannot use for alias something that starts with 'perl-'\n"
if $alias && $alias =~ /^perl-/;
View
12 t/installation3.t 100644 → 100755
@@ -16,12 +16,16 @@ use Test::More;
return map { "perl-$_" }
qw<5.8.9 5.17.7 5.16.2 5.14.3 5.12.5 5.10.1>;
}
+
+ sub App::perlbrew::switch_to {
+ shift->current_perl(shift);
+ }
}
-plan tests => 2;
+plan tests => 3;
{
- my $app = App::perlbrew->new("install", "perl-stable");
+ my $app = App::perlbrew->new("install", "--switch", "perl-stable");
$app->run;
my @installed = $app->installed_perls;
@@ -29,6 +33,10 @@ plan tests => 2;
is $installed[0]{name}, "perl-5.16.2",
"install perl-stable installs correct perl";
+
+ ok $installed[0]{is_current},
+ "install --switch automatically switches to the installed perl"
+ or diag explain $installed[0];
}
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.