Starter/App.pm

filter: Statementstmt 41.8% 36 / 86 Branchbran 32.3% 11 / 34 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 47.0% 8 / 17 Podpod 100% 1 / 1 totaltotal 37.5% 56 / 149 CC 22 SCAR 28.9
CC
22
Cov
37%
_config_read
42.0
_process_command_line
42.0
_config_file
20.0
CRAP 18.0
↑ Summary Starter/Simple.pm »
1 package Module::Starter::App;
2  
3 =head1 NAME
4  
5 Module::Starter::App - the code behind the command line program
6  
7 =head1 VERSION
8  
9 version 1.82
10  
11 =cut
12  
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = '1.82';
17  
18 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Module::Runtime qw( require_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 0 ▶sub _config_file {
Subroutine _config_file: not called CC=4 SCAR=30.0
25 0 my $self = shift;
26 0 ▶ my $configdir = $ENV{'MODULE_STARTER_DIR'} || '';
Condition0%0/2
$ENV{'MODULE_STARTER_DIR'} || ''
l!l
00
MC/DC0%0/1
$ENV{'MODULE_STARTER_DIR'} || ''
$ENV{'MODULE_STARTER_DIR'}
Truth table0%0/2
A
A= $ENV{'MODULE_STARTER_DIR'}
Aresult
11
00
27  
28 0 ▶ if ( !$configdir && $ENV{'HOME'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $configdir and $ENV{"HOME"}) 0 0 0
Condition0%0/3
not $configdir and $ENV{"HOME"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $configdir and $ENV{"HOME"}
not $configdir $ENV{"HOME"}
Truth table0%0/3
not(A) and B
A= not $configdirB= $ENV{"HOME"}
ABresult
0X0
100
111
29 0 $configdir = File::Spec->catdir( $ENV{'HOME'}, '.module-starter' );
30 }
31  
32 0 return File::Spec->catfile( $configdir, 'config' );
33 }
34  
35  
36 0 ▶sub _config_read {
Subroutine _config_read: not called CC=6 SCAR=37.4
37 0 my $self = shift;
38  
39 0 my $filename = $self->_config_file;
40 0 ▶ return () unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 0 0
41
42 0 ▶ open( my $config_file, '<', $filename )
Branch: 1 branch
BranchTrueFalseTotal
open my $config_file, "<", $filename or die "couldn't open config file ${filename}: $!\n" 0 0 0
43 or die "couldn't open config file $filename: $!\n";
44  
45 0 my %config;
46 0 ▶ while (my $line = <$config_file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $config_file)) 0 0 0
47 0 chomp $line;
48 0 ▶ next if $line =~ /\A\s*\Z/sm;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*\Z/ms 0 0 0
49 0 ▶ if ($line =~ /\A(\w+):\s*(.+)\Z/sm) { $config{$1} = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A(\w+):\s*(.+)\Z/ms) 0 0 0
50 }
51
52 0 return $self->_config_multi_process(%config);
53 }
54  
55 22 ▶sub _config_multi_process {
Subroutine _config_multi_process: called CC=9 SCAR=22.1
56 22 my ( $self, %config ) = @_;
57  
58 # The options that accept multiple arguments must be set to an arrayref
59 22 foreach my $key (qw( author builder ignores_type modules plugins )) {
60 110 ▶ $config{$key} = [] unless exists $config{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config{$key} 88 22 110
61  
62 110 ▶ if ( $key eq 'author' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'author') { } 22 88 110
63 22 ▶ next if ref $config{$key};
Branch: 1 branch
BranchTrueFalseTotal
if ref $config{$key} 0 22 22
64  
65 # Split author strings on whitespace or comma.
66 # Spec: 'Author Name <author-email@domain.tld>'
67 22 my @authors;
68 22 ▶ while ($config{$key} =~ s/
Branch: 1 branch
BranchTrueFalseTotal
if ($config{$key} =~ s/ ^\s* ((?> (?: # Author [^\s<>]+ \s+ )+ ) <[^<>]+>) # Email (?: # Separators (or end of string) \s*,\s* | \s+ | \z ) //x) 20 22 42
69 ^\s*
70 ((?>
71 (?: # Author
72 [^\s<>]+
73 \s+
74 )+
75 )
76 <[^<>]+>) # Email
77 (?: # Separators (or end of string)
78 \s*,\s*
79 | \s+
80 | \z
81 )
82 //x) {
83 20 push @authors, $1;
84 }
85 22 ▶ push @authors, $config{$key} if length $config{$key};
Branch: 1 branch
BranchTrueFalseTotal
if length $config{$key} 15 7 22
86 22 $config{$key} = \@authors;
87 }
88 else {
89 88 ▶ $config{$key} = [ split /(?:\s*,\s*|\s+)/, (ref $config{$key} ? join(',', @{$config{$key}}) : $config{$key}) ] if $config{$key};
Branch: 2 branches
BranchTrueFalseTotal
if $config{$key} 88 0 88
ref $config{$key} ? : 88 0 88
90 }
91 }
92  
93 22 return %config;
94 }
95  
96 0 ▶sub _process_command_line {
Subroutine _process_command_line: not called CC=6 SCAR=37.4
97 0 my ( $self, %config ) = @_;
98  
99 0 $config{'argv'} = [ @ARGV ];
100  
101 0 ▶ pod2usage(2) unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 0 0
102  
103 GetOptions(
104 'class=s' => \$config{class},
105 'plugin=s@' => \$config{plugins},
106 'dir=s' => \$config{dir},
107 'distro=s' => \$config{distro},
108 'module=s@' => \$config{modules},
109 'builder=s@' => \$config{builder},
110 'ignores=s@' => \$config{ignores_type},
111 0 ▶ eumm => sub { push @{$config{builder}}, 'ExtUtils::MakeMaker' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 ▶ mb => sub { push @{$config{builder}}, 'Module::Build' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 0 ▶ mi => sub { push @{$config{builder}}, 'Module::Install' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
114  
115 0 'author=s@' => \@{ $config{author} },
116 'email=s' => \$config{email},
117 'github=s' => \$config{github},
118 'license=s' => \$config{license},
119 genlicense => \$config{genlicense},
120 'minperl=s' => \$config{minperl},
121 'fatalize' => \$config{fatalize},
122  
123 force => \$config{force},
124 verbose => \$config{verbose},
125 0 ▶ version => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 require Module::Starter;
127 0 print "module-starter v$Module::Starter::VERSION\n";
128 0 exit 1;
129 },
130 0 ▶ help => sub { pod2usage(1); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
131 0 ▶ ) or pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("class=s", \$config{"class"}, "plugin=s\@", \$config{"plugins"}, "dir=s", \$config{"dir"}, "distro=s", \$config{"distro"}, "module=s\@", \$config{"modules"}, "builder=s\@", \$config{"builder"}, "ignores=s\@", \$config{"ignores_type"}, "eumm", sub { push @{$config{"builder"};}, "ExtUtils::MakeMaker"; } , "mb", sub { push @{$config{"builder"};}, "Module::Build"; } , "mi", sub { push @{$config{"builder"};}, "Module::Install"; } , "author=s\@", \@{$config{"author"};}, "email=s", \$config{"email"}, "github=s", \$config{"github"}, "license=s", \$config{"license"}, "genlicense", \$config{"genlicense"}, "minperl=s", \$config{"minperl"}, "fatalize", \$config{"fatalize"}, "force", \$config{"force"}, "verbose", \$config{"verbose"}, "version", sub { require Module::Starter; print "module-starter v$Module::Starter::VERSION\n"; exit 1; } , "help", sub { pod2usage(1); } ) or pod2usage(2) 0 0 0
132  
133 0 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 0 0 0
134 0 pod2usage(
135 -msg => "Unparseable arguments received: " . join(',', @ARGV),
136 -exitval => 2,
137 );
138 }
139  
140 0 ▶ $config{class} ||= 'Module::Starter';
Condition0%0/2
$config{"class"} ||= "Module::Starter"
l!l
00
MC/DC0%0/1
$config{"class"} ||= "Module::Starter"
$config{"class"}
Truth table0%0/2
A
A= $config{"class"}
Aresult
11
00
141  
142 0 ▶ $config{builder} = ['ExtUtils::MakeMaker'] unless $config{builder};
Branch: 1 branch
BranchTrueFalseTotal
unless $config{"builder"} 0 0 0
143  
144 0 return %config;
145 }
146  
147 =head2 run
148  
149 Module::Starter::App->run;
150  
151 This is equivalent to running F<module-starter>. Its behavior is still subject
152 to change.
153  
154 =cut
155  
156 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
157 0 my $self = shift;
158 0 my %config = $self->_config_read;
159  
160 0 %config = $self->_process_command_line(%config);
161 0 %config = $self->_config_multi_process(%config);
162  
163 0 require_module $config{class};
164 0 $config{class}->import( @{ $config{'plugins'} } );
165  
166 0 my $starter = $config{class}->new( %config );
167 0 $starter->postprocess_config;
168 0 $starter->pre_create_distro;
169 0 $starter->create_distro;
170 0 $starter->post_create_distro;
171 0 $starter->pre_exit;
172  
173 0 return 1;
174 }
175  
176 1 1;
↑ Summary Starter/Simple.pm »