Skip to content

Commit 96d966f

Browse files
committed
reduce FirstTime init complexity
Perl::Critic found these violations in "lib/CPAN/FirstTime.pm": lib/CPAN/FirstTime.pm: Subroutine "init" with high complexity score (154) at line 774, column 1. Consider refactoring. (Severity: 3)
1 parent cc7e9dc commit 96d966f

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

lib/CPAN/FirstTime.pm

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,39 @@ then restart your command line shell and CPAN before installing modules:
771771

772772
}
773773

774+
#
775+
# YAML::Syck, YAML::XS (cperl only), YAML, YAML::Tiny. CPAN::Meta::YAML not yet
776+
# YAML::XS is broken upstream, CPAN::Meta::YAML cannot read spec v2.
777+
#
778+
779+
sub _yaml_init {
780+
my ($matcher) = @_;
781+
my $CPERL = $Config::Config{usecperl};
782+
my $dflt = $CPERL ? 'YAML::XS' : 'YAML';
783+
while(1) {
784+
my_dflt_prompt(yaml_module => $dflt, $matcher);
785+
my $given = $CPAN::Config->{yaml_module};
786+
my $forbidden = $CPERL ? qr/^(CPAN::Meta::YAML)$/ : qr/^(CPAN::Meta::YAML|YAML::XS)$/;
787+
if ($given =~ $forbidden) {
788+
$CPAN::Frontend->mywarn
789+
("Error: $given cannot be used yet. Try YAML"
790+
. $CPERL ? ", YAML::Syck or YAML::XS\n" : " or YAML::Syck\n");
791+
$CPAN::Frontend->mysleep(3);
792+
} else {
793+
last;
794+
}
795+
}
796+
my $old_v = $CPAN::Config->{load_module_verbosity};
797+
$CPAN::Config->{load_module_verbosity} = q[none];
798+
if (!$auto_config && !$CPAN::META->has_inst($CPAN::Config->{yaml_module})) {
799+
$CPAN::Frontend->mywarn
800+
("Warning (maybe harmless): '$CPAN::Config->{yaml_module}' not installed. Try $dflt\n");
801+
$CPAN::Frontend->mysleep(3);
802+
}
803+
$CPAN::Config->{load_module_verbosity} = $old_v;
804+
}
805+
806+
774807
sub init {
775808
my($configpm, %args) = @_;
776809
use Config;
@@ -940,38 +973,13 @@ sub init {
940973

941974
my_yn_prompt(trust_test_report_history => 0, $matcher);
942975

943-
#
944-
#= YAML::Syck, YAML::XS (cperl only), YAML, YAML::Tiny. CPAN::Meta::YAML not yet
945-
# YAML::XS is broken upstream, CPAN::Meta::YAML cannot read spec v2.
946-
#
976+
#= YAML module
947977
if (!$matcher or "yaml_module" =~ /$matcher/) {
948-
my $CPERL = $Config::Config{usecperl};
949-
my $dflt = $CPERL ? 'YAML::XS' : 'YAML';
950-
while(1) {
951-
my_dflt_prompt(yaml_module => $dflt, $matcher);
952-
my $given = $CPAN::Config->{yaml_module};
953-
my $forbidden = $CPERL ? qr/^(CPAN::Meta::YAML)$/ : qr/^(CPAN::Meta::YAML|YAML::XS)$/;
954-
if ($given =~ $forbidden) {
955-
$CPAN::Frontend->mywarn
956-
("Error: $given cannot be used yet. Try YAML"
957-
. $CPERL ? ", YAML::Syck or YAML::XS\n" : " or YAML::Syck\n");
958-
$CPAN::Frontend->mysleep(3);
959-
} else {
960-
last;
961-
}
962-
}
963-
my $old_v = $CPAN::Config->{load_module_verbosity};
964-
$CPAN::Config->{load_module_verbosity} = q[none];
965-
if (!$auto_config && !$CPAN::META->has_inst($CPAN::Config->{yaml_module})) {
966-
$CPAN::Frontend->mywarn
967-
("Warning (maybe harmless): '$CPAN::Config->{yaml_module}' not installed. Try $dflt\n");
968-
$CPAN::Frontend->mysleep(3);
969-
}
970-
$CPAN::Config->{load_module_verbosity} = $old_v;
978+
_yaml_init($matcher);
971979
}
972980

973981
#
974-
#= YAML code deserialisation
982+
#= YAML code deserialisation (security problem)
975983
#
976984
my_yn_prompt(yaml_load_code => 0, $matcher);
977985

0 commit comments

Comments
 (0)