Skip to content

Commit

Permalink
New feature: "perlbrew install --switch $perl"
Browse files Browse the repository at this point in the history
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
arc committed Jan 3, 2013
1 parent e4353a5 commit 6da850e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bin/perlbrew
Expand Up @@ -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>
Expand Down
10 changes: 10 additions & 0 deletions lib/App/perlbrew.pm
Expand Up @@ -144,6 +144,7 @@ sub new {
'help|h',
'version',
'root=s',
'switch',

# options passed directly to Configure
'D=s@',
Expand Down Expand Up @@ -868,6 +869,9 @@ sub run_command_install {
die $help_message;
}

$self->switch_to($installation_name)
if $self->{switch};

return;
}

Expand Down Expand Up @@ -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-/;

Expand Down
12 changes: 10 additions & 2 deletions t/installation3.t 100644 → 100755
Expand Up @@ -16,19 +16,27 @@ 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;
is 0+@installed, 1, "install perl-stable installs one perl";

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;

0 comments on commit 6da850e

Please sign in to comment.