lib/Module/Provision/TraitFor/CreatingDistributions.pm

filter: Statementstmt 23.4% 39 / 166 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 23.5% 8 / 34 Podpod 100% 13 / 13 totaltotal 18.1% 60 / 330 CC 47 SCAR 30.8
CC
47
Cov
15%
cover
56.0
create_directories
56.0
generate_metadata
56.0
CRAP 21.8
« lib/Module/Provision/TraitFor/CPANDistributions.pm ↑ Summary lib/Module/Provision/TraitFor/VCS.pm »
1 package Module::Provision::TraitFor::CreatingDistributions;
2  
3 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Class::Usul::Constants qw( FAILED FALSE OK SPC TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Class::Usul::Functions qw( emit emit_to io trim );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Class::Usul::Types qw( ArrayRef NonEmptySimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Class::Usul::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 requires qw( appbase appldir branch builder chdir config exec_perms
14 homedir incdir method output next_argv project_file
15 quiet render_templates run_cmd stash testdir vcs );
16  
17 # Object attributes (public)
18 option 'editor' => is => 'lazy', isa => NonEmptySimpleStr,
19 documentation => 'Which text editor to use',
20 0 ▶ default => sub { $_[ 0 ]->config->editor }, format => 's';
Subroutine __ANON__: not called CC=1 SCAR=1.2
21  
22 # Private functions
23 0 ▶my $_set_env_false = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
24 0 $ENV{ $_ } = FALSE for (@_); return;
25 1 };
26  
27 0 ▶my $_set_env_true = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
28 0 $ENV{ $_ } = TRUE for (@_); return;
29 1 };
30  
31 # Private methods
32 0 ▶my $_create_mask = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 return oct '0777' ^ $_[ 0 ]->exec_perms;
34 1 };
35  
36 0 ▶my $_get_cover_command = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
37 0 my $self = shift;
38  
39 0 ▶ ($self->builder eq 'DZ' or $self->builder eq 'MB')
Branch: 1 branch
BranchTrueFalseTotal
$self->builder eq "DZ" || $self->builder eq "MB" and return "perl Build.PL && ./Build testcover" 0 0 0
Condition0%0/3
$self->builder eq "DZ" or $self->builder eq "MB"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->builder eq "DZ" or $self->builder eq "MB"
$self->builder eq "DZ" $self->builder eq "MB"
Truth table0%0/3
A or B
A= $self->builder eq "DZ"B= $self->builder eq "MB"
ABresult
1X1
011
000
40 and return 'perl Build.PL && ./Build testcover';
41  
42 0 return;
43 1 };
44  
45 0 ▶my $_get_cover_build_command = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
46 0 my $self = shift;
47  
48 0 ▶ $self->builder eq 'DZ' and return 'dzil build';
Branch: 1 branch
BranchTrueFalseTotal
$self->builder eq "DZ" and return "dzil build" 0 0 0
49  
50 0 return;
51 1 };
52  
53 0 ▶my $_get_test_command = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
54 0 ▶ return $_[ 1 ] ? 'prove -lv '.$_[ 1 ]
Branch: 2 branches
BranchTrueFalseTotal
$_[1] ? : 0 0 0
$_[0]->builder eq 'DZ' ? : 0 0 0
55 : $_[ 0 ]->builder eq 'DZ' ? 'dzil test'
56 : 'prove t';
57 1 };
58  
59 0 ▶my $_project_file_path = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 return $_[ 0 ]->appldir->catfile( $_[ 0 ]->project_file );
61 1 };
62  
63 # Construction
64 0 ▶around '_build_appbase' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
65 0 my ($orig, $self, @args) = @_; my $appbase = $orig->( $self, @args );
66  
67 0 ▶ return $self->method eq 'dist'
Branch: 1 branch
BranchTrueFalseTotal
$self->method eq 'dist' ? : 0 0 0
68 ? $self->base->absolute( $self->initial_wd )->catdir( $self->distname )
69 : $appbase;
70 1 };
71  
72 0 ▶around '_build_appldir' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
73 0 my ($next, $self, @args) = @_; my $appldir = $self->$next( @args );
74  
75 0 ▶ return !$appldir && $self->method eq 'dist'
Branch: 1 branch
BranchTrueFalseTotal
!$appldir && $self->method eq 'dist' ? : 0 0 0
Condition0%0/3
not $appldir and $self->method eq "dist"
!ll&&!rl&&r
000
MC/DC0%0/2
not $appldir and $self->method eq "dist"
not $appldir $self->method eq "dist"
Truth table0%0/3
not(A) and B
A= not $appldirB= $self->method eq "dist"
ABresult
0X0
100
111
76 ? $self->appbase->catdir( $self->branch ) : $appldir ;
77 1 };
78  
79 0 ▶around '_build_builder' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 0 my ($next, $self, @args) = @_; my $builder = $self->$next( @args );
81  
82 0 ▶ return !$builder && $self->method eq 'dist'
Branch: 1 branch
BranchTrueFalseTotal
!$builder && $self->method eq 'dist' ? : 0 0 0
Condition0%0/3
not $builder and $self->method eq "dist"
!ll&&!rl&&r
000
MC/DC0%0/2
not $builder and $self->method eq "dist"
not $builder $self->method eq "dist"
Truth table0%0/3
not(A) and B
A= not $builderB= $self->method eq "dist"
ABresult
0X0
100
111
83 ? $self->config->builder : $builder;
84 1 };
85  
86 0 ▶around '_build_project' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
87 0 my ($next, $self, @args) = @_; my $project;
88  
89 0 ▶ $self->method eq 'dist' and $project = $self->next_argv and return $project;
Branch: 1 branch
BranchTrueFalseTotal
$self->method eq "dist" and $project = $self->next_argv and return $project 0 0 0
Condition0%0/3
$self->method eq "dist" and $project = $self->next_argv
!ll&&!rl&&r
000
MC/DC0%0/2
$self->method eq "dist" and $project = $self->next_argv
$self->method eq "dist" $project = $self->next_argv
Truth table0%0/3
A and B
A= $self->method eq "dist"B= $project = $self->next_argv
ABresult
0X0
100
111
90  
91 0 return $self->$next( @args );
92 1 };
93  
94 0 ▶around '_build_vcs' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
95 0 my ($next, $self, @args) = @_; my $vcs = $self->$next( @args );
96  
97 0 ▶ return $vcs eq 'none' && $self->method eq 'dist' ? $self->config->vcs : $vcs;
Branch: 1 branch
BranchTrueFalseTotal
$vcs eq 'none' && $self->method eq 'dist' ? : 0 0 0
Condition0%0/3
$vcs eq "none" and $self->method eq "dist"
!ll&&!rl&&r
000
MC/DC0%0/2
$vcs eq "none" and $self->method eq "dist"
$vcs eq "none" $self->method eq "dist"
Truth table0%0/3
A and B
A= $vcs eq "none"B= $self->method eq "dist"
ABresult
0X0
100
111
98 1 };
99  
100 # Public Methods
101 0 ▶sub build_distribution : method {
Subroutine build_distribution: not called CC=5 SCAR=34.0
Pod documented
102 0 my ($self, $verbose) = @_;
103  
104 0 ▶ if ($self->builder eq 'DZ') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->builder eq 'DZ') { } 0 0 0
elsif ($self->builder eq 'MB') { } 0 0 0
105 0 ▶ $self->run_cmd( 'dzil build', $verbose ? { out => 'stdout' } : {} );
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 0 0 0
106 }
107 elsif ($self->builder eq 'MB') {
108 0 $self->run_cmd( 'perl Build.PL' );
109 0 ▶ $self->run_cmd( './Build dist', $verbose ? { out => 'stdout' } : {} );
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 0 0 0
110 }
111  
112 0 return OK;
113 }
114  
115 0 ▶sub clean_distribution : method {
Subroutine clean_distribution: not called CC=3 SCAR=24.8
Pod documented
116 0 my ($self, $verbose) = @_;
117  
118 0 ▶ if ($self->builder eq 'DZ') { $self->run_cmd( 'dzil clean' ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->builder eq 'DZ') { } 0 0 0
elsif ($self->builder eq 'MB') { } 0 0 0
119 0 elsif ($self->builder eq 'MB') { $self->run_cmd( './Build distclean' ) }
120  
121 0 return OK;
122 }
123  
124 0 ▶sub cover : method {
Subroutine cover: not called CC=7 SCAR=40.3
Pod documented
125 0 my $self = shift; $self->chdir( $self->appldir );
126  
127 0 ▶ $self->quiet or
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet or $self->output("Testing coverage [_1]", {"args", [$self->appldir]}) 0 0 0
128 $self->output( 'Testing coverage [_1]', { args => [ $self->appldir ] } );
129  
130 0 my $cmd = $self->$_get_cover_build_command;
131  
132 0 ▶ $cmd and $self->run_cmd( $cmd, $self->quiet ? {} : { out => 'stdout' } );
Branch: 2 branches
BranchTrueFalseTotal
$cmd and $self->run_cmd($cmd, $self->quiet ? {} : {"out", "stdout"}) 0 0 0
$self->quiet ? : 0 0 0
133 0 $_set_env_true->( @{ $self->config->test_env_vars } );
134 0 $ENV{DEVEL_COVER_OPTIONS} = '-ignore,MyModuleBuilder.pm,/home';
135 0 ▶ $self->builder eq 'DZ'
Branch: 1 branch
BranchTrueFalseTotal
$self->builder eq "DZ" and $self->chdir($self->distname . '-' . $self->dist_version) 0 0 0
136 and $self->chdir( $self->distname.'-'.$self->dist_version );
137 0 $cmd = $self->$_get_cover_command;
138 0 ▶ $cmd and $self->run_cmd( $cmd, $self->quiet ? {} : { out => 'stdout' } );
Branch: 2 branches
BranchTrueFalseTotal
$cmd and $self->run_cmd($cmd, $self->quiet ? {} : {"out", "stdout"}) 0 0 0
$self->quiet ? : 0 0 0
139 0 $self->chdir( $self->appldir );
140 0 $_set_env_false->( @{ $self->config->test_env_vars } );
141 0 delete $ENV{DEVEL_COVER_OPTIONS};
142 0 return OK;
143 }
144  
145 0 ▶sub create_directories {
Subroutine create_directories: not called CC=7 SCAR=40.3
Pod documented
146 0 my $self = shift; my $perms = $self->exec_perms;
147  
148 0 ▶ $self->quiet or $self->output( 'Creating directories' );
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet or $self->output("Creating directories") 0 0 0
149 0 ▶ $self->appldir->exists or $self->appldir->mkpath( $perms );
Branch: 1 branch
BranchTrueFalseTotal
$self->appldir->exists or $self->appldir->mkpath($perms) 0 0 0
150 0 ▶ $self->builder eq 'MB'
Branch: 1 branch
BranchTrueFalseTotal
$self->builder eq "MB" and $self->incdir->exists || $self->incdir->mkpath($perms) 0 0 0
Condition0%0/6
$self->builder eq 'MB' && ($self->incdir->exists || $self->incdir->mkpath($perms))
!ll&&!rl&&r
000
$self->incdir->exists or $self->incdir->mkpath($perms)
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->builder eq 'MB' && ($self->incdir->exists || $self->incdir->mkpath($perms))
$self->builder eq 'MB' $self->incdir->exists $self->incdir->mkpath($perms)
Truth table0%0/4
A && B or C
A= $self->builder eq 'MB'B= $self->incdir->existsC= $self->incdir->mkpath($perms)
ABCresult
0XX0
1000
11X1
1011
151 and ($self->incdir->exists or $self->incdir->mkpath( $perms ));
152 0 ▶ $self->testdir->exists or $self->testdir->mkpath( $perms );
Branch: 1 branch
BranchTrueFalseTotal
$self->testdir->exists or $self->testdir->mkpath($perms) 0 0 0
153 0 ▶ $self->homedir->parent->exists or $self->homedir->parent->mkpath( $perms );
Branch: 1 branch
BranchTrueFalseTotal
$self->homedir->parent->exists or $self->homedir->parent->mkpath($perms) 0 0 0
154 0 return;
155 }
156  
157 0 ▶sub dist : method {
Subroutine dist: not called CC=1 SCAR=6.9
Pod documented
158 0 my $self = shift;
159  
160 0 $self->dist_pre_hook;
161 0 $self->create_directories;
162 0 $self->render_templates;
163 0 $self->dist_post_hook;
164 0 return OK;
165 }
166  
167 0 ▶sub dist_post_hook {
Subroutine dist_post_hook: not called CC=1 SCAR=6.9
Pod documented
168 0 my $self = shift;
169  
170 0 $self->generate_metadata( TRUE ); $self->prove;
171  
172 0 return;
173 }
174  
175 0 ▶sub dist_pre_hook {
Subroutine dist_pre_hook: not called CC=3 SCAR=24.8
Pod documented
176 0 my $self = shift; umask $self->$_create_mask;
177  
178 0 ▶ $self->appbase->exists or $self->appbase->mkpath( $self->exec_perms );
Branch: 1 branch
BranchTrueFalseTotal
$self->appbase->exists or $self->appbase->mkpath($self->exec_perms) 0 0 0
179 0 ▶ $self->stash->{abstract} = $self->next_argv || $self->stash->{abstract};
Condition0%0/3
$self->next_argv || $self->stash->{'abstract'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->next_argv || $self->stash->{'abstract'}
$self->next_argv $self->stash->{'abstract'}
Truth table0%0/3
A || B
A= $self->next_argvB= $self->stash->{'abstract'}
ABresult
1X1
011
000
180 0 $self->chdir( $self->appbase );
181 0 return;
182 }
183  
184 0 ▶sub edit_project : method {
Subroutine edit_project: not called CC=1 SCAR=6.9
Pod documented
185 0 my $self = shift; my $path = $self->$_project_file_path;
186  
187 0 $self->run_cmd( $self->editor.SPC.$path, { async => TRUE } );
188 0 return OK;
189 }
190  
191 0 ▶sub generate_metadata {
Subroutine generate_metadata: not called CC=7 SCAR=40.3
Pod documented
192 0 my ($self, $create) = @_; $self->chdir( $self->appldir );
193  
194 0 ▶ my $verbose = $create ? FALSE : TRUE; my $mdf = 'README.md';
Branch: 1 branch
BranchTrueFalseTotal
$create ? : 0 0 0
195  
196 0 ▶ if ($self->builder eq 'DZ') { $self->build_distribution( $verbose ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->builder eq 'DZ') { } 0 0 0
elsif ($self->builder eq 'MB') { } 0 0 0
197 elsif ($self->builder eq 'MB') {
198 0 $self->run_cmd( 'perl '.$self->project_file );
199 0 ▶ $self->run_cmd( './Build manifest', $verbose ? { out => 'stdout' } : {} );
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 0 0 0
200 0 ▶ $self->run_cmd( './Build distmeta', $verbose ? { out => 'stdout' } : {} );
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 0 0 0
201 }
202  
203 0 $self->clean_distribution( $verbose );
204 0 ▶ return $create ? $mdf : undef;
Branch: 1 branch
BranchTrueFalseTotal
$create ? : 0 0 0
205 }
206  
207 0 ▶sub metadata : method {
Subroutine metadata: not called CC=1 SCAR=6.9
Pod documented
208 0 my $self = shift; $self->generate_metadata( FALSE ); return OK;
209 }
210  
211 0 ▶sub prove : method {
Subroutine prove: not called CC=2 SCAR=17.9
Pod documented
212 0 my $self = shift; $self->chdir( $self->appldir );
213  
214 0 my $cmd = $self->$_get_test_command( $self->next_argv );
215  
216 0 $_set_env_true->( @{ $self->config->test_env_vars } );
217  
218 0 $self->output ( 'Testing [_1]', { args => [ $self->appldir ] } );
219 0 ▶ $self->run_cmd( $cmd, $self->quiet ? {} : { out => 'stdout' } );
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet ? : 0 0 0
220  
221 0 $_set_env_false->( @{ $self->config->test_env_vars } );
222 0 return OK;
223 }
224  
225 0 ▶sub select_project : method {
Subroutine select_project: not called CC=2 SCAR=17.9
Pod documented
226 0 my $self = shift;
227 0 my @projects = $self->base->all_dirs;
228 0 my @options = map { $_->basename } @projects;
229 0 my $prompt = 'Select a project from the following list';
230 0 my $index = $self->get_option( $prompt, undef, TRUE, undef, \@options );
231  
232 0 ▶ $index < 0 and return FAILED;
Branch: 1 branch
BranchTrueFalseTotal
$index < 0 and return 1 0 0 0
233  
234 0 my $name = $projects[ $index ]->basename;
235 0 my $project = Module::Provision->new
236 ( noask => TRUE, project => $name, quiet => TRUE );
237  
238 0 $self->chdir( my $dir = $project->appldir );
239  
240 0 io()->fdopen( 3, 'w' )->print( $dir )->close;
241  
242 0 return Module::Provision->new
243 ( method => 'edit_project', noask => TRUE, quiet => TRUE )->run;
244 }
245  
246 0 ▶sub show_tab_title : method {
Subroutine show_tab_title: not called CC=3 SCAR=24.8
Pod documented
247 0 my $self = shift;
248 0 ▶ my $file = $self->next_argv || $self->$_project_file_path;
Condition0%0/3
$self->next_argv || $self->$_project_file_path
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->next_argv || $self->$_project_file_path
$self->next_argv $self->$_project_file_path
Truth table0%0/3
A || B
A= $self->next_argvB= $self->$_project_file_path
ABresult
1X1
011
000
249 0 ▶ my $text = (grep { m{ tab-title: }msx } io( $file )->getlines)[ -1 ]
Condition0%0/2
(grep {/ tab-title: /msx;} &io($file)->getlines)[-1] || ':' . $self->distname
l!l
00
MC/DC0%0/1
(grep {/ tab-title: /msx;} &io($file)->getlines)[-1] || ':' . $self->distname
(grep {/ tab-title: /msx;} &io($file)->getlines)[-1]
Truth table0%0/2
A
A= (grep {/ tab-title: /msx;} &io($file)->getlines)[-1]
Aresult
11
00
250 || ':'.$self->distname;
251  
252 0 emit trim( (split m{ : }msx, $text, 2)[ 1 ] ).SPC.$self->appbase;
253 0 return OK;
254 }
255  
256 1 1;
257  
258 __END__
« lib/Module/Provision/TraitFor/CPANDistributions.pm ↑ Summary lib/Module/Provision/TraitFor/VCS.pm »