blib/lib/Dist/Zilla/App/Command/setup.pm

filter: Statementstmt 20.6% 13 / 63 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 28.5% 4 / 14 Podpod 100% 4 / 4 totaltotal 17.2% 21 / 122 CC 17 SCAR 39.3
CC
17
Cov
13%
execute
132.0
validate_args
6.0
__ANON__
6.0
CRAP 51.1
« blib/lib/Dist/Zilla/App/Command/test.pm ↑ Summary blib/lib/Dist/Zilla/Dist/Builder.pm »
1 package Dist::Zilla::App::Command::setup 6.040;
2 # ABSTRACT: set up a basic global config file
3  
4 4 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Dist::Zilla::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #pod =head1 SYNOPSIS
11 #pod
12 #pod $ dzil setup
13 #pod Enter your name> Ricardo Signes
14 #pod ...
15 #pod
16 #pod Dist::Zilla looks for per-user configuration in F<~/.dzil/config.ini>. This
17 #pod command prompts the user for some basic information that can be used to produce
18 #pod the most commonly needed F<config.ini> sections.
19 #pod
20 #pod B<WARNING>: PAUSE account details are stored within config.ini in plain text.
21 #pod
22 #pod =cut
23  
24 4 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶sub abstract { 'set up a basic global config file' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
27  
28 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
29 0 "This command will run through a short interactive process to set up\n" .
30 "a basic Dist::Zilla configuration in ~/.dzil/config.ini"
31 }
32  
33 0 ▶sub validate_args {
Subroutine validate_args: not called CC=2 SCAR=17.9
Pod documented
34 0 my ($self, $opt, $args) = @_;
35  
36 0 ▶ $self->usage_error('too many arguments') if @$args != 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$args != 0 0 0 0
37 }
38  
39 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod documented
40 0 my ($self, $opt, $arg) = @_;
41  
42 0 my $chrome = $self->app->chrome;
43  
44 0 require Dist::Zilla::Util;
45 0 my $config_root = Dist::Zilla::Util->_global_config_root;
46  
47 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (-d $config_root and my(@files) = grep({-f $_ and $_->basename =~ /\Aconfig\.[^.]+\z/u;} $config_root->children)) 0 0 0
Condition0%0/3
-d $config_root and my(@files) = grep({-f $_ and $_->basename =~ /\Aconfig\.[^.]+\z/u;} $config_root->children)
!ll&&!rl&&r
000
MC/DC0%0/2
-d $config_root and my(@files) = grep({-f $_ and $_->basename =~ /\Aconfig\.[^.]+\z/u;} $config_root->children)
-d $config_root my(@files) = grep({-f $_ and $_->basename =~ /\Aconfig\.[^.]+\z/u;} $config_root->children)
Truth table0%0/3
A and B
A= -d $config_rootB= my(@files) = grep({-f $_ and $_->basename =~ /\Aconfig\.[^.]+\z/u;} $config_root->children)
ABresult
0X0
100
111
48 -d $config_root
49 and
50 0 ▶ my @files = grep { -f and $_->basename =~ /\Aconfig\.[^.]+\z/ }
Condition0%0/3
-f $_ && $_->basename =~ /\Aconfig\.[^.]+\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ && $_->basename =~ /\Aconfig\.[^.]+\z/u
-f $_ $_->basename =~ /\Aconfig\.[^.]+\z/u
Truth table0%0/3
A && B
A= -f $_B= $_->basename =~ /\Aconfig\.[^.]+\z/u
ABresult
0X0
100
111
51 $config_root->children
52 ) {
53 0 $chrome->logger->log_fatal([
54 "per-user configuration files already exist in %s: %s",
55 "$config_root",
56 join(q{, }, @files),
57 ]);
58  
59 0 ▶ return unless $chrome->prompt_yn("Continue anyway?", { default => 0 });
Branch: 1 branch
BranchTrueFalseTotal
unless $chrome->prompt_yn("Continue anyway?", {"default", 0}) 0 0 0
60 }
61  
62 my $realname = $chrome->prompt_str(
63 "What's your name? ",
64 0 ▶ { check => sub { defined $_[0] and $_[0] =~ /\S/ } },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /\S/u 0 0 0
65 0 );
66  
67 my $email = $chrome->prompt_str(
68 "What's your email address? ",
69 0 ▶ { check => sub { defined $_[0] and $_[0] =~ /\A\S+\@\S+\z/ } },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /\A\S+\@\S+\z/u 0 0 0
70 0 );
71  
72 my $c_holder = $chrome->prompt_str(
73 "Who, by default, holds the copyright on your code? ",
74 {
75 0 ▶ check => sub { defined $_[0] and $_[0] =~ /\S/ },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /\S/u 0 0 0
76 0 default => $realname,
77 },
78 );
79  
80 my $license = $chrome->prompt_str(
81 "What license will you use by default (Perl_5, BSD, etc.)? ",
82 {
83 default => 'Perl_5',
84 0 ▶ check => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
85 0 my $str = String::RewritePrefix->rewrite(
86 { '' => 'Software::License::', '=' => '' },
87 $_[0],
88 );
89  
90 0 ▶ return Params::SomeUtil::_CLASS($str) && eval "require $str; 1";
Condition0%0/3
&Params::SomeUtil::_CLASS($str) && eval "require $str; 1"
!ll&&!rl&&r
000
MC/DC0%0/2
&Params::SomeUtil::_CLASS($str) && eval "require $str; 1"
&Params::SomeUtil::_CLASS($str) eval "require $str; 1"
Truth table0%0/3
A && B
A= &Params::SomeUtil::_CLASS($str)B= eval "require $str; 1"
ABresult
0X0
100
111
91 },
92 },
93 0 );
94  
95 0 my %pause;
96  
97 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($chrome->prompt_yn("\n * WARNING - Your account details will be stored in plain text *\nDo you want to enter your PAUSE account details? ", {"default", 0})) 0 0 0
98 $chrome->prompt_yn(
99 '
100 * WARNING - Your account details will be stored in plain text *
101 Do you want to enter your PAUSE account details? ',
102 { default => 0 },
103 )
104 ) {
105 0 my $default_pause;
106 0 ▶ if ($email =~ /\A(.+?)\@cpan\.org\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($email =~ /\A(.+?)\@cpan\.org\z/iu) 0 0 0
107 0 $default_pause = uc $1;
108 }
109  
110 $pause{username} = $chrome->prompt_str(
111 "What is your PAUSE id? ",
112 {
113 0 ▶ check => sub { defined $_[0] and $_[0] =~ /\A\w+\z/ },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /\A\w+\z/u 0 0 0
114 0 default => $default_pause,
115 },
116 );
117  
118 $pause{password} = $chrome->prompt_str(
119 "What is your PAUSE password (you can leave this blank to be prompted)? ",
120 {
121 0 ▶ check => sub { length $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 noecho => 1,
123 },
124 );
125 }
126  
127 0 ▶ $config_root->mkpath unless -d $config_root;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $config_root 0 0 0
128 0 ▶ $config_root->child('profiles')->mkpath
Branch: 1 branch
BranchTrueFalseTotal
unless -d $config_root->child("profiles") 0 0 0
129 unless -d $config_root->child('profiles');
130  
131 0 my $umask = umask;
132 0 umask( $umask | 077 ); # this file might contain PAUSE pw; make it go-r
133 0 open my $fh, '>:encoding(UTF-8)', $config_root->child('config.ini');
134  
135 0 $fh->print("[%User]\n");
136 0 $fh->print("name = $realname\n");
137 0 $fh->print("email = $email\n\n");
138  
139 0 $fh->print("[%Rights]\n");
140 0 $fh->print("license_class = $license\n");
141 0 $fh->print("copyright_holder = $c_holder\n\n");
142  
143 0 ▶ if (keys %pause) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %pause) 0 0 0
144 0 $fh->print("[%PAUSE]\n");
145 0 $fh->print("username = $pause{username}\n");
146 0 ▶ if (length $pause{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $pause{"password"}) 0 0 0
147 0 $fh->print("password = $pause{password}\n");
148 }
149 0 $fh->print("\n");
150 }
151  
152 0 close $fh;
153  
154 0 umask $umask;
155  
156 0 $self->log("config.ini file created!");
157 }
158  
159 4 1;
160  
161 __END__
« blib/lib/Dist/Zilla/App/Command/test.pm ↑ Summary blib/lib/Dist/Zilla/Dist/Builder.pm »