handleconfig.pm

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PM 代码 · 共 720 行 · 第 1/2 页

PM
720
字号
    my($self) = @_;    if ($CPAN::RUN_DEGRADED) {                             $CPAN::Frontend->mydie(                                                    "'o conf defaults' disabled in ".                                                    "degraded mode. Maybe try\n".                                                    " !undef \$CPAN::RUN_DEGRADED\n"                                                   );    }    my $done;    for my $config (qw(CPAN/MyConfig.pm CPAN/Config.pm)) {        if ($INC{$config}) {            CPAN->debug("INC{'$config'}[$INC{$config}]") if $CPAN::DEBUG;            CPAN::Shell->_reload_this($config,{reloforce => 1});            $CPAN::Frontend->myprint("'$INC{$config}' reread\n");            last;        }    }    $CPAN::CONFIG_DIRTY = 0;    1;}=head2 C<< CLASS->safe_quote ITEM >>Quotes an item to become safe against spacesin shell interpolation. An item is enclosedin double quotes if:  - the item contains spaces in the middle  - the item does not start with a quoteThis happens to avoid shell interpolationproblems when whitespace is present indirectory names.This method uses C<commands_quote> to determinethe correct quote. If C<commands_quote> isa space, no quoting will take place.if it starts and ends with the same quote character: leave it as it isif it contains no whitespace: leave it as it isif it contains whitespace, thenif it contains quotes: better leave it as it iselse: quote it with the correct quote type for the box we're on=cut{    # Instead of patching the guess, set commands_quote    # to the right value    my ($quotes,$use_quote)        = $^O eq 'MSWin32'            ? ('"', '"')                : (q{"'}, "'")                    ;    sub safe_quote {        my ($self, $command) = @_;        # Set up quote/default quote        my $quote = $CPAN::Config->{commands_quote} || $quotes;        if ($quote ne ' '            and defined($command )            and $command =~ /\s/            and $command !~ /[$quote]/) {            return qq<$use_quote$command$use_quote>        }        return $command;    }}sub init {    my($self,@args) = @_;    CPAN->debug("self[$self]args[".join(",",@args)."]");    $self->load(doit => 1, @args);    1;}# This is a piece of repeated code that is abstracted here for# maintainability.  RMB#sub _configpmtest {    my($configpmdir, $configpmtest) = @_;    if (-w $configpmtest) {        return $configpmtest;    } elsif (-w $configpmdir) {        #_#_# following code dumped core on me with 5.003_11, a.k.        my $configpm_bak = "$configpmtest.bak";        unlink $configpm_bak if -f $configpm_bak;        if( -f $configpmtest ) {            if( rename $configpmtest, $configpm_bak ) {                $CPAN::Frontend->mywarn(<<END);Old configuration file $configpmtest    moved to $configpm_bakEND            }        }        my $fh = FileHandle->new;        if ($fh->open(">$configpmtest")) {            $fh->print("1;\n");            return $configpmtest;        } else {            # Should never happen            Carp::confess("Cannot open >$configpmtest");        }    } else { return }}sub require_myconfig_or_config () {    return if $INC{"CPAN/MyConfig.pm"};    local @INC = @INC;    my $home = home();    unshift @INC, File::Spec->catdir($home,'.cpan');    eval { require CPAN::MyConfig };    my $err_myconfig = $@;    if ($err_myconfig and $err_myconfig !~ m#locate CPAN/MyConfig\.pm#) {        die "Error while requiring CPAN::MyConfig:\n$err_myconfig";    }    unless ($INC{"CPAN/MyConfig.pm"}) { # this guy has settled his needs already      eval {require CPAN::Config;}; # not everybody has one      my $err_config = $@;      if ($err_config and $err_config !~ m#locate CPAN/Config\.pm#) {          die "Error while requiring CPAN::Config:\n$err_config";      }    }}sub home () {    my $home;    if ($CPAN::META->has_usable("File::HomeDir")) {        $home = File::HomeDir->my_data;        unless (defined $home) {            $home = File::HomeDir->my_home        }    }    unless (defined $home) {        $home = $ENV{HOME};    }    $home;}sub load {    my($self, %args) = @_;    $CPAN::Be_Silent++ if $args{be_silent};    my $doit;    $doit = delete $args{doit};    use Carp;    require_myconfig_or_config;    my @miss = $self->missing_config_data;    return unless $doit || @miss;    return if $loading;    $loading++;    require CPAN::FirstTime;    my($configpm,$fh,$redo);    $redo ||= "";    if (defined $INC{"CPAN/Config.pm"} && -w $INC{"CPAN/Config.pm"}) {        $configpm = $INC{"CPAN/Config.pm"};        $redo++;    } elsif (defined $INC{"CPAN/MyConfig.pm"} && -w $INC{"CPAN/MyConfig.pm"}) {        $configpm = $INC{"CPAN/MyConfig.pm"};        $redo++;    } else {        my($path_to_cpan) = File::Basename::dirname($INC{"CPAN.pm"});        my($configpmdir) = File::Spec->catdir($path_to_cpan,"CPAN");        my($configpmtest) = File::Spec->catfile($configpmdir,"Config.pm");        my $inc_key;        if (-d $configpmdir or File::Path::mkpath($configpmdir)) {            $configpm = _configpmtest($configpmdir,$configpmtest);            $inc_key = "CPAN/Config.pm";        }        unless ($configpm) {            $configpmdir = File::Spec->catdir(home,".cpan","CPAN");            File::Path::mkpath($configpmdir);            $configpmtest = File::Spec->catfile($configpmdir,"MyConfig.pm");            $configpm = _configpmtest($configpmdir,$configpmtest);            $inc_key = "CPAN/MyConfig.pm";        }        if ($configpm) {          $INC{$inc_key} = $configpm;        } else {          my $text = qq{WARNING: CPAN.pm is unable to } .              qq{create a configuration file.};          output($text, 'confess');        }    }    local($") = ", ";    if ($redo && !$doit) {        $CPAN::Frontend->myprint(<<END);Sorry, we have to rerun the configuration dialog for CPAN.pm due tosome missing parameters...END        $args{args} = \@miss;    }    CPAN::FirstTime::init($configpm, %args);    $loading--;    return;}# returns mandatory but missing entries in the Configsub missing_config_data {    my(@miss);    for (         "auto_commit",         "build_cache",         "build_dir",         "cache_metadata",         "cpan_home",         "ftp_proxy",         #"gzip",         "http_proxy",         "index_expire",         #"inhibit_startup_message",         "keep_source_where",         #"make",         "make_arg",         "make_install_arg",         "makepl_arg",         "mbuild_arg",         "mbuild_install_arg",         "mbuild_install_build_command",         "mbuildpl_arg",         "no_proxy",         #"pager",         "prerequisites_policy",         "scan_cache",         #"tar",         #"unzip",         "urllist",        ) {        next unless exists $keys{$_};        push @miss, $_ unless defined $CPAN::Config->{$_};    }    return @miss;}sub help {    $CPAN::Frontend->myprint(q[Known options:  commit    commit session changes to disk  defaults  reload default config values from disk  help      this help  init      enter a dialog to set all or a set of parametersEdit key values as in the following (the "o" is a literal letter o):  o conf build_cache 15  o conf build_dir "/foo/bar"  o conf urllist shift  o conf urllist unshift ftp://ftp.foo.bar/  o conf inhibit_startup_message 1]);    undef; #don't reprint CPAN::Config}sub cpl {    my($word,$line,$pos) = @_;    $word ||= "";    CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;    my(@words) = split " ", substr($line,0,$pos+1);    if (        defined($words[2])        and        $words[2] =~ /list$/        and        (        @words == 3        ||        @words == 4 && length($word)        )       ) {        return grep /^\Q$word\E/, qw(splice shift unshift pop push);    } elsif (defined($words[2])             and             $words[2] eq "init"             and            (             @words == 3             ||             @words >= 4 && length($word)            )) {        return sort grep /^\Q$word\E/, keys %keys;    } elsif (@words >= 4) {        return ();    }    my %seen;    my(@o_conf) =  sort grep { !$seen{$_}++ }        keys %can,            keys %$CPAN::Config,                keys %keys;    return grep /^\Q$word\E/, @o_conf;}sub prefs_lookup {    my($self,$distro,$what) = @_;    if ($prefssupport{$what}) {        return $CPAN::Config->{$what} unless            $distro                and $distro->prefs                    and $distro->prefs->{cpanconfig}                        and defined $distro->prefs->{cpanconfig}{$what};        return $distro->prefs->{cpanconfig}{$what};    } else {        $CPAN::Frontend->mywarn("Warning: $what not yet officially ".                                "supported for distroprefs, doing a normal lookup");        return $CPAN::Config->{$what};    }}{    package        CPAN::Config; ####::###### #hide from indexer    # note: J. Nick Koston wrote me that they are using    # CPAN::Config->commit although undocumented. I suggested    # CPAN::Shell->o("conf","commit") even when ugly it is at least    # documented    # that's why I added the CPAN::Config class with autoload and    # deprecated warning    use strict;    use vars qw($AUTOLOAD $VERSION);    $VERSION = sprintf "%.2f", substr(q$Rev: 2212 $,4)/100;    # formerly CPAN::HandleConfig was known as CPAN::Config    sub AUTOLOAD {        my $class = shift; # e.g. in dh-make-perl: CPAN::Config        my($l) = $AUTOLOAD;        $CPAN::Frontend->mywarn("Dispatching deprecated method '$l' to CPAN::HandleConfig\n");        $l =~ s/.*:://;        CPAN::HandleConfig->$l(@_);    }}1;__END__=head1 LICENSEThis program is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=cut# Local Variables:# mode: cperl# cperl-indent-level: 4# End:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?