in reply to Can ActiveState be managed under PerlBrew on Mac

;) Sure, if you extend perlbrew to have that, start with switch_to

sub switch_to { my ( $self, $dist, $alias ) = @_; die "Cannot use for alias something that starts with 'perl-'\n" if $alias && $alias =~ /^perl-/; die "${dist} is not installed\n" unless -d joinpath($self->root, " +perls", $dist); if ($self->env("PERLBREW_BASHRC_VERSION")) { local $ENV{PERLBREW_PERL} = $dist; my $HOME = $self->env('HOME'); my $pb_home = $self->env("PERLBREW_HOME") || $PERLBREW_HOME; mkpath($pb_home); system("$0 env $dist > " . joinpath($pb_home, "init")); print "Switched to $dist.\n\n"; } else { $self->launch_sub_shell($dist); } }

Then later in launch_sub_shell you have

# The user does not source bashrc/csh in their shell initializ +ation. $env{PATH} = $env{PERLBREW_PATH} . ":" . join ":", grep +{ !/$root\/bin/ } split ":", $ENV{PATH}; $env{MANPATH} = $env{PERLBREW_MANPATH} . ":" . join ":", grep +{ !/$root\/man/ } ( defined($ENV{MANPATH}) ? split(":", $ENV{MANPATH}) : () +);

Then the other thing to improve is installed_perls

sub installed_perls { my $self = shift; my @result; my $root = $self->root; for (<$root/perls/*>) { my ($name) = $_ =~ m/\/([^\/]+$)/; my $executable = joinpath($_, 'bin', 'perl'); my $version_file = joinpath($_,'.version'); my $orig_version; if ( -e $version_file ){ open my $fh, '<', $version_file; local $/; $orig_version = <$fh>; chomp $orig_version; } else { $orig_version = `$executable -e 'print \$]'`; if ( defined $orig_version and length $orig_version ){ if (open my $fh, '>', $version_file ){ print {$fh} $orig_version; } } } push @result, { name => $name, orig_version=> $orig_version, version => $self->format_perl_version($orig_version), is_current => ($self->current_perl eq $name) && !($self-> +current_lib), libs => [ $self->local_libs($name) ], executable => $executable }; } return sort { $a->{orig_version} <=> $b->{orig_version} or $a->{na +me} cmp $b->{name} } @result; }

Basically all these need abstracting

for (<$root/perls/*>) { my @libs = map { substr($_, length($PERLBREW_HOME) + 6) } <$PERLBR +EW_HOME/libs/*>; @perls = map { m{/([^/]+)$} } grep { -d $_ && ! -l $_ } <$root +/perls/*>; for my $executable (<$root/perls/$perl/bin/*>) { my @build_dirs = <$root/build/*>; my @tarballs = <$root/dists/*>; my $executable = joinpath($self->root, "perls", $name, "bin", "per +l"); mkpath($_) for (grep { ! -d $_ } map { joinpath($self->root, $_) } + qw(perls dists build etc bin)); my $etc_dir = joinpath($self->root, "etc"); my $root_dir = $self->path_with_tilde($self->root); my $target = joinpath($self->root, "bin", "perlbrew"); mkpath( joinpath($self->root, "bin" )); my $dist_tarball_path = joinpath($self->root, "dists", $dist_tarba +ll); my $extracted_dir = "@{[ $self->root ]}/build/$dist_tarball_basena +me"; my $extract_command = "cd @{[ $self->root ]}/build; $tarx $dist_ta +rball"; my $dist_tarball_path = joinpath($self->root, "dists", $dist_tarba +ll); my $build_dir = joinpath($self->root, "build"); my $dist_extracted_dir = joinpath($self->root, "build", $candidate +s[0]); # take the newest one my $dist_tarball_path = joinpath($self->root, "dists", $dist_tarba +ll); my $dist_tarball_path = joinpath($self->root, "dists", $dist_tarba +ll); my @paths = grep { index($_, $PERLBREW_HOME) < 0 && index($_, $sel +f->root) < 0 } split /:/, $self->env($envname); $self->{log_file} = joinpath($self->root, "build.${installation_na +me}${variation}${append}.log"); my $perlpath = $self->root . "/perls/$installation_name"; my $patchperl = $self->root . "/bin/patchperl"; print "Installing $dist_extracted_dir into " . $self->path_with_ti +lde("@{[ $self->root ]}/perls/$installation_name") . "\n\n"; my $newperl = joinpath($self->root, "perls", $installation_nam +e, "bin", "perl"); joinpath( $self->root, 'perls', $installation_name, '.versio +n' ); my $out = $self->root . "/bin/" . $program_name; mkpath("@{[ $self->root ]}/bin") unless -d "@{[ $self->root ]}/bin +"; my $root = $self->root; PERLBREW_PATH => joinpath($self->root, "bin"), PERLBREW_ROOT => $self->root if(-d "@{[ $self->root ]}/perls/$perl_name/bin") { $env{PERLBREW_PATH} .= ":" . joinpath($self->root, "perl +s", $perl_name, "bin"); $env{PERLBREW_MANPATH} = joinpath($self->root, "perls", $p +erl_name, "man") my $root_dir = $self->root; my $root = $self->root; die "${dist} is not installed\n" unless -d joinpath($self->root, " +perls", $dist); my $root = $self->root; my $dir = "@{[ $self->root ]}/perls/$target"; next if -l $self->root . '/perls/' . $i->{name}; # Skip Aliase +s my $root = $self->root; my $path_name = joinpath($self->root, "perls", $name); my $path_alias = joinpath($self->root, "perls", $alias) if $alias; joinpath( $self->root, 'Config.pm' );

They should all make use of is_installed or an abstraction like that to generate all paths that need checking

So that you can add reading paths from a config file in addition to globbing $root

Basically readdir/glob should only happen in one sub, maybe two, not in 5