text
stringlengths
0
834k
}
$o->{SHELL}{mode} = $newmode;
return $oldmode;
}
# Older versions of PPM3 had one ""Active"" repository. This code reads
# $o->conf('repository') if it exists, and moves it into
# $o->conf('active_reps'), which is a list. The old one is deleted -- old PPMs
# will reset it if needed, but it will be ignored if 'active_reps' exists.
sub init_active_reps {
my $o = shift;
if ($o->conf('repository') and not $o->conf('active_reps')) {
my @active = $o->conf('repository');
delete $o->{SHELL}{conf}{DATA}{repository};
$o->conf('active_reps', \@active);
}
elsif (not defined $o->conf('active_reps')) {
my @active = $o->reps_all; # enable all repositories
$o->conf('active_reps', \@active);
}
}
sub init {
my $o = shift;
$o->cache_clear('query');
$o->cache_clear('search');
$o->{API}{case_ignore} = 1;
# Load the configuration;
$o->{SHELL}{conf} = PPM::Config::load_config_file('cmdline');
$o->init_active_reps;
# check whether there's a target in the parent's perl that hasn't been
# installed in the ""targets"" file:
my $ppmsitelib = $ENV{PPM3_PERL_SITELIB};
if ($ppmsitelib and opendir(PPMDIR, ""$ppmsitelib/ppm-conf"")) {
my @files = map { ""$ppmsitelib/ppm-conf/$_"" }
grep { /^ppminst/i && !/(~|\.bak)\z/ } readdir PPMDIR;
closedir PPMDIR;
my $found = 0;
if (@files == 1) {
my @targets = PPM::UI::target_list()->result_l;
for my $target (@targets) {
my $info = PPM::UI::target_raw_info($target);
next unless $info and $info->is_success;
++$found and last
if path_under($info->result->{path}, $files[0]);
}
unless ($found) {
# We're going to add a new target:
# 1. if we can find ppm3-bin.cfg, use that
# 2. if not, guess lots of stuff
my $ppm3_bin_cfg = ""$ENV{PPM3_PERL_PREFIX}/bin/ppm3-bin.cfg"";
my $r = PPM::UI::target_add(undef, From => $ppm3_bin_cfg)
if -f $ppm3_bin_cfg;
unless ($r and $r->is_success) {
PPM::UI::target_add(
'TEMP',
type => 'Local',
path => $files[0],
);
}
}
}
}
# set the initial target:
if (defined $o->{API}{args}{target}) {
my $t = $o->{API}{args}{target};
my $prefix = $ENV{PPM3_PERL_PREFIX};
if ($t ne 'auto') {
# A full name or number given:
$o->run('target', 'select', $o->{API}{args}{target});
}
elsif ($prefix) {
# Auto-select target, based on where we came from:
my @l = $o->conf('target');
push @l, PPM::UI::target_list()->result_l;
for my $target (@l) {
next unless $target;
my $info = PPM::UI::target_raw_info($target);
next unless $info and $info->is_success;
next unless path_under($info->result->{path}, ""$prefix/"");
my $mode = $o->setmode('SILENT');
$o->run('target', 'select', $target);
$o->setmode($mode);
last;
}
}
}
}
sub preloop {
my $o = shift;
if ($o->conf('verbose-startup') and $o->mode eq 'SHELL') {
my $profile_track = $o->conf('profile-track');
chomp (my $startup = <<END);
$NAME version $VERSION.