diff --git a/bin/perlbrew b/bin/perlbrew index 8a4ea336..8fde490b 100755 --- a/bin/perlbrew +++ b/bin/perlbrew @@ -203,6 +203,9 @@ Options for C command: -j $n Parallel building and testing. ex. C -n --notest Skip testing + --switch Automatically switch to this Perl once successfully + installed, as if with `perlbrew switch ` + --as Install the given version of perl by a name. ex. C diff --git a/lib/App/perlbrew.pm b/lib/App/perlbrew.pm index e51b04e4..93f0f3b8 100644 --- a/lib/App/perlbrew.pm +++ b/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-/; diff --git a/t/installation3.t b/t/installation3.t old mode 100644 new mode 100755 index 080c5d2e..9d0a2c06 --- a/t/installation3.t +++ b/t/installation3.t @@ -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;