CPAN/Maker/Bootstrapper/Role/Init.pm

filter: Statementstmt 37.3% 31 / 83 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 1 totaltotal 24.1% 41 / 170 CC 30 SCAR 52.9
CC
30
Cov
22%
init
306.0
_init_config
210.0
BEGIN
1.0
CRAP 198.8
« CPAN/Maker/Bootstrapper/Role/Installer.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Importer.pm »
1 package CPAN::Maker::Bootstrapper::Role::Init;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CPAN::Maker::Bootstrapper::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Cwd qw(abs_path getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 0 ▶sub init {
Subroutine init: not called CC=17 SCAR=57.2
Pod undocumented
18 ########################################################################
19 0 my ($self) = @_;
20  
21 0 my ($dist) = split /[.]/xsm, 'CPAN::Maker::Bootstrapper';
22 0 $dist =~ s/::/-/xmsg;
23  
24 0 $self->set_dist_dir( dist_dir($dist) );
25  
26 0 my $reader = $self->_init_config;
27 0 my $config = $reader->get_config;
28  
29 0 ▶ foreach my $section ( keys %{ $config // {} } ) {
Condition0%0/2
$config // {}
l!l
00
MC/DC0%0/1
$config // {}
$config
Truth table0%0/2
A
A= $config
Aresult
11
00
30 0 ▶ next if $section eq 'cpan-maker';
Branch: 1 branch
BranchTrueFalseTotal
if $section eq "cpan-maker" 0 0 0
31  
32 0 foreach my $option ( keys %{ $config->{$section} } ) {
33 0 my $name = sprintf '%s_%s', $section, $option;
34 0 $name =~ s/-/_/gxsm;
35  
36 0 my $setter = 'set_' . $name;
37 0 my $getter = 'get_' . $name;
38  
39 0 ▶ next if !$self->can($setter) || exists $self->options->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->can($setter) or exists $self->options->{$name} 0 0 0
Condition0%0/3
not $self->can($setter) or exists $self->options->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->can($setter) or exists $self->options->{$name}
not $self->can($setter) exists $self->options->{$name}
Truth table0%0/3
not(A) or B
A= not $self->can($setter)B= exists $self->options->{$name}
ABresult
1X1
011
000
40  
41 0 my $value = $config->{$section}{$option};
42  
43 0 ▶ if ( $value !~ /^"/xsm && looks_like_number $value ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $value =~ /^"/msx and &looks_like_number($value)) { } 0 0 0
elsif ($value =~ /^true$/i) { } 0 0 0
elsif ($value =~ /^false$/i) { } 0 0 0
Condition0%0/3
not $value =~ /^"/msx and &looks_like_number($value)
!ll&&!rl&&r
000
MC/DC0%0/2
not $value =~ /^"/msx and &looks_like_number($value)
not $value =~ /^"/msx &looks_like_number($value)
Truth table0%0/3
not(A) and B
A= not $value =~ /^"/msxB= &looks_like_number($value)
ABresult
0X0
100
111
44 0 $value += 0;
45 }
46 elsif ( $value =~ /^true$/i ) {
47 0 $value = 1;
48 }
49 elsif ( $value =~ /^false$/i ) {
50 0 $value = 0;
51 }
52  
53 0 $value =~ s/^"(.*)"$/$1/xsm;
54  
55 0 $self->$setter($value);
56 }
57 }
58  
59 0 my $basedir = $self->get_basedir;
60  
61 0 ▶ die sprintf "ERROR: basedir [%s] is not a directory\n", $basedir
Branch: 1 branch
BranchTrueFalseTotal
if $basedir and not -d $basedir 0 0 0
Condition0%0/3
$basedir and not -d $basedir
!ll&&!rl&&r
000
MC/DC0%0/2
$basedir and not -d $basedir
$basedir not -d $basedir
Truth table0%0/3
A and not(B)
A= $basedirB= not -d $basedir
ABresult
0X0
100
111
62 if $basedir && !-d $basedir;
63  
64 0 ▶ $basedir //= abs_path(getcwd);
Condition0%0/3
$basedir //= abs_path(getcwd())
l!l&&r!l&&!r
000
MC/DC0%0/2
$basedir //= abs_path(getcwd())
$basedir abs_path(getcwd())
Truth table0%0/3
A //= B
A= $basedirB= abs_path(getcwd())
ABresult
1X1
011
000
65 0 $self->set_basedir( abs_path($basedir) );
66  
67 0 ▶ my $importdir = $self->get_import // [];
Condition0%0/2
$self->get_import // []
l!l
00
MC/DC0%0/1
$self->get_import // []
$self->get_import
Truth table0%0/2
A
A= $self->get_import
Aresult
11
00
68 0 $self->set_import($importdir);
69  
70 0 ▶ $self->set_max_diff_files( $self->get_max_diff_files // $MAX_DIFF_FILES );
Condition0%0/3
$self->get_max_diff_files // $CPAN::Maker::Bootstrapper::Role::Init::MAX_DIFF_FILES
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_max_diff_files // $CPAN::Maker::Bootstrapper::Role::Init::MAX_DIFF_FILES
$self->get_max_diff_files $CPAN::Maker::Bootstrapper::Role::Init::MAX_DIFF_FILES
Truth table0%0/3
A // B
A= $self->get_max_diff_filesB= $CPAN::Maker::Bootstrapper::Role::Init::MAX_DIFF_FILES
ABresult
1X1
011
000
71  
72 0 ▶ if ( $self->get_color ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_color) 0 0 0
73 0 my $color = eval {
74 0 require Term::ANSIColor;
75 0 Term::ANSIColor->import('colored');
76 0 return $TRUE;
77 };
78  
79 0 $self->set_color($color);
80 }
81  
82 0 return;
83 }
84  
85 ########################################################################
86 0 ▶sub _init_config {
Subroutine _init_config: not called CC=14 SCAR=53.5
87 ########################################################################
88 0 my ($self) = @_;
89  
90 0 require CPAN::Maker::Bootstrapper::ConfigReader;
91  
92 0 my $reader = eval { CPAN::Maker::Bootstrapper::ConfigReader->new( $self->get_config ); };
93  
94 0 $self->set_reader($reader);
95  
96 0 ▶ $self->set_config( $reader ? $reader->get_config_file : undef );
Branch: 1 branch
BranchTrueFalseTotal
$reader ? : 0 0 0
97  
98 0 ▶ if ( $EVAL_ERROR && $self->get_config ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Maker::Bootstrapper::Role::Init::EVAL_ERROR and $self->get_config) 0 0 0
Condition0%0/3
$CPAN::Maker::Bootstrapper::Role::Init::EVAL_ERROR and $self->get_config
!ll&&!rl&&r
000
MC/DC0%0/2
$CPAN::Maker::Bootstrapper::Role::Init::EVAL_ERROR and $self->get_config
$CPAN::Maker::Bootstrapper::Role::Init::EVAL_ERROR $self->get_config
Truth table0%0/3
A and B
A= $CPAN::Maker::Bootstrapper::Role::Init::EVAL_ERRORB= $self->get_config
ABresult
0X0
100
111
99 0 warn "WARNING: could not load config file: $EVAL_ERROR Using defaults.\n";
100 }
101  
102 { # the one legit and allowable use of postfix if!
103 ## no critic (ProhibitPostfixControls)
104 0 ▶ $self->set_username( $reader ? $reader->user_name : q{} )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->get_username 0 0 0
$reader ? : 0 0 0
105 if !$self->get_username;
106  
107 0 ▶ $self->set_email( $reader ? $reader->user_email : q{} )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->get_email 0 0 0
$reader ? : 0 0 0
108 if !$self->get_email;
109  
110 0 ▶ $self->set_github_user( $reader ? $reader->user_github : q{} )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->get_github_user 0 0 0
$reader ? : 0 0 0
111 if !$self->get_github_user;
112  
113 0 ▶ $self->set_resources( $reader ? $reader->cpan_maker_resources : undef )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->get_resources 0 0 0
$reader ? : 0 0 0
114 if !$self->get_resources;
115  
116 0 ▶ $self->set_basedir( $reader ? $reader->cpan_maker_basedir : undef )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->get_basedir 0 0 0
$reader ? : 0 0 0
117 if !$self->get_basedir;
118 }
119  
120 0 return $reader;
121 }
122  
123 1 1;
124  
125 __END__
« CPAN/Maker/Bootstrapper/Role/Installer.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Importer.pm »