blib/lib/Dist/Zilla/Dist/Builder.pm

filter: Statementstmt 78.5% 286 / 364 Branchbran 42.0% 58 / 138 Conditioncond 37.1% 23 / 62 MC/DCmcdc 22.8% 8 / 35 Subroutinesub 89.1% 41 / 46 Podpod 100% 16 / 16 totaltotal 65.3% 432 / 661 CC 115 SCAR 36.6
CC
115
Cov
65%
run_in_build
272.0
install
90.0
_ensure_blib
30.0
CRAP 39.0
« blib/lib/Dist/Zilla/App/Command/setup.pm ↑ Summary blib/lib/Dist/Zilla/Role/BuildPL.pm »
1 package Dist::Zilla::Dist::Builder 6.040;
2 # ABSTRACT: dist zilla subclass for building dists
3  
4 51 ▶use Moose 0.92; # role composition fixes
Subroutine BEGIN: called CC=1 SCAR=0.0
5 51 extends 'Dist::Zilla';
6  
7 51 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 51 ▶use MooseX::Types::Moose qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 51 ▶use Dist::Zilla::Types qw(Path);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 51 ▶use File::pushd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 51 ▶use Dist::Zilla::Path; # because more Path::* is better, eh?
Subroutine BEGIN: called CC=1 SCAR=0.0
14 51 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 51 ▶use List::Util 1.45 'uniq';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 51 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 51 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #pod =method from_config
21 #pod
22 #pod my $zilla = Dist::Zilla->from_config(\%arg);
23 #pod
24 #pod This routine returns a new Zilla from the configuration in the current working
25 #pod directory.
26 #pod
27 #pod This method should not be relied upon, yet. Its semantics are B<certain> to
28 #pod change.
29 #pod
30 #pod Valid arguments are:
31 #pod
32 #pod config_class - the class to use to read the config
33 #pod default: Dist::Zilla::MVP::Reader::Finder
34 #pod
35 #pod =cut
36  
37 197 ▶sub from_config {
Subroutine from_config: called CC=3 SCAR=11.0
Pod documented
38 197 my ($class, $arg) = @_;
39 197 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
1970
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
40  
41 197 ▶ my $root = path($arg->{dist_root} || '.');
Condition100%2/2
$arg->{'dist_root'} || '.'
l!l
17720
MC/DC100%1/1
$arg->{'dist_root'} || '.'
$arg->{'dist_root'}
Truth table100%2/2
A
A= $arg->{'dist_root'}
Aresult
11
00
42  
43 my $sequence = $class->_load_config({
44 root => $root,
45 chrome => $arg->{chrome},
46 config_class => $arg->{config_class},
47 _global_stashes => $arg->{_global_stashes},
48 197 });
49  
50 187 my $self = $sequence->section_named('_')->zilla;
51  
52 187 $self->_setup_default_plugins;
53  
54 187 return $self;
55 }
56  
57 187 ▶sub _setup_default_plugins {
Subroutine _setup_default_plugins: called CC=11 SCAR=24.6
58 187 my ($self) = @_;
59 187 ▶ unless ($self->plugin_named(':InstallModules')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":InstallModules")) 187 0 187
60 187 require Dist::Zilla::Plugin::FinderCode;
61 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
62 plugin_name => ':InstallModules',
63 zilla => $self,
64 style => 'grep',
65 419 ▶ code => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
66 419 my ($file, $self) = @_;
67 419 local $_ = $file->name;
68 419 ▶ return 1 if m{\Alib/} and m{\.(pm|pod)$};
Branch: 1 branch
BranchTrueFalseTotal
if m[\Alib/]u and /\.(pm|pod)$/u 124 295 419
Condition66%2/3
m[\Alib/]u and /\.(pm|pod)$/u
!ll&&!rl&&r
2950124
MC/DC50%1/2
m[\Alib/]u and /\.(pm|pod)$/u
m[\Alib/]u /\.(pm|pod)$/u
Truth table66%2/3
A and B
A= m[\Alib/]uB= /\.(pm|pod)$/u
ABresult
0X0
100
111
69 295 return;
70 },
71 187 });
72  
73 187 push @{ $self->plugins }, $plugin;
74 }
75  
76 187 ▶ unless ($self->plugin_named(':IncModules')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":IncModules")) 187 0 187
77 187 require Dist::Zilla::Plugin::FinderCode;
78 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
79 plugin_name => ':IncModules',
80 zilla => $self,
81 style => 'grep',
82 38 ▶ code => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
83 38 my ($file, $self) = @_;
84 38 local $_ = $file->name;
85 38 ▶ return 1 if m{\Ainc/} and m{\.pm$};
Branch: 1 branch
BranchTrueFalseTotal
if m[\Ainc/]u and /\.pm$/u 5 33 38
Condition66%2/3
m[\Ainc/]u and /\.pm$/u
!ll&&!rl&&r
3305
MC/DC50%1/2
m[\Ainc/]u and /\.pm$/u
m[\Ainc/]u /\.pm$/u
Truth table66%2/3
A and B
A= m[\Ainc/]uB= /\.pm$/u
ABresult
0X0
100
111
86 33 return;
87 },
88 187 });
89  
90 187 push @{ $self->plugins }, $plugin;
91 }
92  
93 187 ▶ unless ($self->plugin_named(':TestFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":TestFiles")) 187 0 187
94 187 require Dist::Zilla::Plugin::FinderCode;
95 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
96 plugin_name => ':TestFiles',
97 zilla => $self,
98 style => 'grep',
99 169 ▶ code => sub { local $_ = $_->name; m{\At/} },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 187 });
101  
102 187 push @{ $self->plugins }, $plugin;
103 }
104  
105 187 ▶ unless ($self->plugin_named(':ExtraTestFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":ExtraTestFiles")) 187 0 187
106 187 require Dist::Zilla::Plugin::FinderCode;
107 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
108 plugin_name => ':ExtraTestFiles',
109 zilla => $self,
110 style => 'grep',
111 169 ▶ code => sub { local $_ = $_->name; m{\Axt/} },
Subroutine __ANON__: called CC=1 SCAR=0.0
112 187 });
113  
114 187 push @{ $self->plugins }, $plugin;
115 }
116  
117 187 ▶ unless ($self->plugin_named(':ExecFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":ExecFiles")) 187 0 187
118 187 require Dist::Zilla::Plugin::FinderCode;
119 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
120 plugin_name => ':ExecFiles',
121 zilla => $self,
122 style => 'list',
123 100 ▶ code => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
124 100 my $plugins = $_[0]->zilla->plugins_with(-ExecFiles);
125 100 my @files = uniq map {; @{ $_->find_files } } @$plugins;
126  
127 100 return \@files;
128 },
129 187 });
130  
131 187 push @{ $self->plugins }, $plugin;
132 }
133  
134 187 ▶ unless ($self->plugin_named(':PerlExecFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":PerlExecFiles")) 187 0 187
135 187 require Dist::Zilla::Plugin::FinderCode;
136 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
137 plugin_name => ':PerlExecFiles',
138 zilla => $self,
139 style => 'list',
140 1 ▶ code => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
141 1 my $parent_plugin = $self->plugin_named(':ExecFiles');
142 my @files = grep {
143 3 ▶ $_->name =~ m{\.pl$}
Condition100%3/3
$_->name =~ /\.pl$/u || $_->content =~ /^\s*\#\!.*perl\b/u
l!l&&r!l&&!r
111
MC/DC100%2/2
$_->name =~ /\.pl$/u || $_->content =~ /^\s*\#\!.*perl\b/u
$_->name =~ /\.pl$/u $_->content =~ /^\s*\#\!.*perl\b/u
Truth table100%3/3
A || B
A= $_->name =~ /\.pl$/uB= $_->content =~ /^\s*\#\!.*perl\b/u
ABresult
1X1
011
000
144 or $_->content =~ m{^\s*\#\!.*perl\b};
145 1 } @{ $parent_plugin->find_files };
146 1 return \@files;
147 },
148 187 });
149  
150 187 push @{ $self->plugins }, $plugin;
151 }
152  
153 187 ▶ unless ($self->plugin_named(':ShareFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":ShareFiles")) 187 0 187
154 187 require Dist::Zilla::Plugin::FinderCode;
155 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
156 plugin_name => ':ShareFiles',
157 zilla => $self,
158 style => 'list',
159 1 ▶ code => sub {
Subroutine __ANON__: called CC=4 SCAR=15.5
160 1 my $self = shift;
161 1 my $map = $self->zilla->_share_dir_map;
162 1 my @files;
163 1 ▶ if ( $map->{dist} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map->{"dist"}) 1 0 1
164 14 push @files, grep {; $_->name =~ m{\A\Q$map->{dist}\E/} }
165 1 @{ $self->zilla->files };
166 }
167 1 ▶ if ( my $mod_map = $map->{module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod_map = $map->{"module"}) 0 1 1
168 0 for my $mod ( keys %$mod_map ) {
169 0 push @files, grep { $_->name =~ m{\A\Q$mod_map->{$mod}\E/} }
170 0 @{ $self->zilla->files };
171 }
172 }
173 1 return \@files;
174 },
175 187 });
176  
177 187 push @{ $self->plugins }, $plugin;
178 }
179  
180 187 ▶ unless ($self->plugin_named(':MainModule')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":MainModule")) 187 0 187
181 187 require Dist::Zilla::Plugin::FinderCode;
182 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
183 plugin_name => ':MainModule',
184 zilla => $self,
185 style => 'grep',
186 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
187 0 my ($file, $self) = @_;
188 0 local $_ = $file->name;
189 0 ▶ return 1 if $_ eq $self->zilla->main_module->name;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $self->zilla->main_module->name 0 0 0
190 0 return;
191 },
192 187 });
193  
194 187 push @{ $self->plugins }, $plugin;
195 }
196  
197 187 ▶ unless ($self->plugin_named(':AllFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":AllFiles")) 187 0 187
198 187 require Dist::Zilla::Plugin::FinderCode;
199 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
200 plugin_name => ':AllFiles',
201 zilla => $self,
202 style => 'grep',
203 18 ▶ code => sub { return 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
204 187 });
205  
206 187 push @{ $self->plugins }, $plugin;
207 }
208  
209 187 ▶ unless ($self->plugin_named(':NoFiles')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->plugin_named(":NoFiles")) 187 0 187
210 187 require Dist::Zilla::Plugin::FinderCode;
211 my $plugin = Dist::Zilla::Plugin::FinderCode->new({
212 plugin_name => ':NoFiles',
213 zilla => $self,
214 style => 'list',
215 1 ▶ code => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
216 187 });
217  
218 187 push @{ $self->plugins }, $plugin;
219 }
220 }
221  
222 51 has _share_dir_map => (
223 is => 'ro',
224 isa => HashRef,
225 init_arg => undef,
226 lazy => 1,
227 builder => '_build_share_dir_map',
228 );
229  
230 37 ▶sub _build_share_dir_map {
Subroutine _build_share_dir_map: called CC=8 SCAR=20.8
231 37 my ($self) = @_;
232  
233 37 my $share_dir_map = {};
234  
235 37 for my $plugin (@{ $self->plugins_with(-ShareDir) }) {
236 21 ▶ next unless my $sub_map = $plugin->share_dir_map;
Branch: 1 branch
BranchTrueFalseTotal
unless my $sub_map = $plugin->share_dir_map 11 10 21
237  
238 10 ▶ if ( $sub_map->{dist} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_map->{"dist"}) 5 5 10
239 $self->log_fatal("can't install more than one distribution ShareDir")
240 5 ▶ if $share_dir_map->{dist};
Branch: 1 branch
BranchTrueFalseTotal
if $share_dir_map->{"dist"} 0 5 5
241 5 $share_dir_map->{dist} = $sub_map->{dist};
242 }
243  
244 10 ▶ if ( my $mod_map = $sub_map->{module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod_map = $sub_map->{"module"}) 5 5 10
245 5 for my $mod ( keys %$mod_map ) {
246 $self->log_fatal("can't install more than one ShareDir for $mod")
247 8 ▶ if $share_dir_map->{module}{$mod};
Branch: 1 branch
BranchTrueFalseTotal
if $share_dir_map->{"module"}{$mod} 0 8 8
248 8 $share_dir_map->{module}{$mod} = $mod_map->{$mod};
249 }
250 }
251 }
252  
253 37 return $share_dir_map;
254 }
255  
256  
257 197 ▶sub _load_config {
Subroutine _load_config: called CC=5 SCAR=16.1
258 197 my ($class, $arg) = @_;
259 197 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
1970
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
260  
261 my $config_class =
262 197 ▶ $arg->{config_class} ||= 'Dist::Zilla::MVP::Reader::Finder';
Condition50%1/2
$arg->{"config_class"} ||= "Dist::Zilla::MVP::Reader::Finder"
l!l
0197
MC/DC0%0/1
$arg->{"config_class"} ||= "Dist::Zilla::MVP::Reader::Finder"
$arg->{"config_class"}
Truth table50%1/2
A
A= $arg->{"config_class"}
Aresult
11
00
263  
264 197 require_module($config_class);
265  
266 $arg->{chrome}->logger->log_debug(
267 197 { prefix => '[DZ] ' },
268 "reading configuration using $config_class"
269 );
270  
271 197 my $root = $arg->{root};
272  
273 197 require Dist::Zilla::MVP::Assembler::Zilla;
274 197 require Dist::Zilla::MVP::Section;
275 my $assembler = Dist::Zilla::MVP::Assembler::Zilla->new({
276 chrome => $arg->{chrome},
277 197 zilla_class => $class,
278 section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
279 });
280  
281 197 for ($assembler->sequence->section_named('_')) {
282 197 $_->add_value(chrome => $arg->{chrome});
283 197 $_->add_value(root => $arg->{root});
284 $_->add_value(_global_stashes => $arg->{_global_stashes})
285 197 ▶ if $arg->{_global_stashes};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"_global_stashes"} 20 177 197
286 }
287  
288 197 my $seq;
289 197 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
290 197 $seq = $config_class->read_config(
291 $root->child('dist'),
292 {
293 assembler => $assembler
294 },
295 );
296 10 ▶ } catch {
Subroutine __ANON__: called CC=3 SCAR=11.0
297 10 ▶ die $_ unless try {
Subroutine __ANON__: called CC=2 SCAR=6.9
298 10 ▶ $_->isa('Config::MVP::Error')
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("Config::MVP::Error") and $_->ident eq "package not installed" 4 6 10
299 and $_->ident eq 'package not installed'
300 10 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
unless &try(sub { $_->isa("Config::MVP::Error") and $_->ident eq "package not installed"; } ) 6 4 10
301  
302 4 my $package = $_->package;
303 4 ▶ my $bundle = $_->section_name =~ m{^@(?!.*/)} ? ' bundle' : '';
Branch: 1 branch
BranchTrueFalseTotal
$_->section_name =~ m[^@(?!.*/)]u ? : 1 3 4
304  
305 4 die <<"END_DIE";
306 Required plugin$bundle $package isn't installed.
307  
308 Run 'dzil authordeps' to see a list of all required plugins.
309 You can pipe the list to your CPAN client to install or update them:
310  
311 dzil authordeps --missing | cpanm
312  
313 END_DIE
314  
315 197 };
316  
317 187 return $seq;
318 }
319  
320 #pod =method build_in
321 #pod
322 #pod $zilla->build_in($root);
323 #pod
324 #pod This method builds the distribution in the given directory. If no directory
325 #pod name is given, it defaults to DistName-Version. If the distribution has
326 #pod already been built, an exception will be thrown.
327 #pod
328 #pod =method build
329 #pod
330 #pod This method just calls C<build_in> with no arguments. It gets you the default
331 #pod behavior without the weird-looking formulation of C<build_in> with no object
332 #pod for the preposition!
333 #pod
334 #pod =cut
335  
336 134 ▶sub build { $_[0]->build_in }
Subroutine build: called CC=1 SCAR=0.0
Pod documented
337  
338 155 ▶sub build_in {
Subroutine build_in: called CC=12 SCAR=24.9
Pod documented
339 155 my ($self, $root) = @_;
340  
341 155 ▶ $self->log_fatal("tried to build with a minter")
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("Dist::Zilla::Dist::Minter") 0 155 155
342 if $self->isa('Dist::Zilla::Dist::Minter');
343  
344 155 ▶ $self->log_fatal("attempted to build " . $self->name . " a second time")
Branch: 1 branch
BranchTrueFalseTotal
if $self->built_in 0 155 155
345 if $self->built_in;
346  
347 155 $_->before_build for @{ $self->plugins_with(-BeforeBuild) };
348  
349 155 $self->log("beginning to build " . $self->name);
350  
351 155 $_->gather_files for @{ $self->plugins_with(-FileGatherer) };
352 154 $_->set_file_encodings for @{ $self->plugins_with(-EncodingProvider) };
353 154 $_->prune_files for @{ $self->plugins_with(-FilePruner) };
354  
355 154 $self->version; # instantiate this lazy attribute now that files are gathered
356  
357 154 $_->munge_files for @{ $self->plugins_with(-FileMunger) };
358  
359 152 $_->register_prereqs for @{ $self->plugins_with(-PrereqSource) };
360  
361 152 $self->prereqs->finalize;
362  
363 # Barf if someone has already set up a prereqs entry? -- rjbs, 2010-04-13
364 152 $self->distmeta->{prereqs} = $self->prereqs->as_string_hash;
365  
366 151 $_->setup_installer for @{ $self->plugins_with(-InstallTool) };
367  
368 150 $self->_check_dupe_files;
369  
370 150 my $build_root = $self->_prep_build_root($root);
371  
372 150 $self->log("writing " . $self->name . " in $build_root");
373  
374 150 for my $file (@{ $self->files }) {
375 657 $self->_write_out_file($file, $build_root);
376 }
377  
378 $_->after_build({ build_root => $build_root })
379 150 for @{ $self->plugins_with(-AfterBuild) };
380  
381 150 $self->built_in($build_root);
382 }
383  
384 #pod =attr built_in
385 #pod
386 #pod This is the L<Path::Tiny>, if any, in which the dist has been built.
387 #pod
388 #pod =cut
389  
390 51 has built_in => (
391 is => 'rw',
392 isa => Path,
393 init_arg => undef,
394 coerce => 1,
395 );
396  
397 #pod =method ensure_built_in
398 #pod
399 #pod $zilla->ensure_built_in($root);
400 #pod
401 #pod This method behaves like C<L</build_in>>, but if the dist is already built in
402 #pod C<$root> (or the default root, if no root is given), no exception is raised.
403 #pod
404 #pod =method ensure_built
405 #pod
406 #pod This method just calls C<ensure_built_in> with no arguments. It gets you the
407 #pod default behavior without the weird-looking formulation of C<ensure_built_in>
408 #pod with no object for the preposition!
409 #pod
410 #pod =cut
411  
412 23 ▶sub ensure_built {
Subroutine ensure_built: called CC=1 SCAR=0.0
Pod documented
413 23 $_[0]->ensure_built_in;
414 }
415  
416 24 ▶sub ensure_built_in {
Subroutine ensure_built_in: called CC=5 SCAR=17.2
Pod documented
417 24 my ($self, $root) = @_;
418  
419 # $root ||= $self->name . q{-} . $self->version;
420 24 ▶ return $self->built_in if $self->built_in and
Branch: 1 branch
BranchTrueFalseTotal
if $self->built_in and !$root || $self->built_in eq $root 3 21 24
Condition50%3/6
$self->built_in and !$root || $self->built_in eq $root
!ll&&!rl&&r
2103
not $root or $self->built_in eq $root
l!l&&r!l&&!r
300
MC/DC33%1/3
$self->built_in and !$root || $self->built_in eq $root
$self->built_in not $root $self->built_in eq $root
Truth table50%2/4
A and not(B) or C
A= $self->built_inB= not $rootC= $self->built_in eq $root
ABCresult
0XX0
1000
11X1
1011
421 (!$root or ($self->built_in eq $root));
422  
423 21 ▶ Carp::croak("dist is already built, but not in $root") if $self->built_in;
Branch: 1 branch
BranchTrueFalseTotal
if $self->built_in 0 21 21
424 21 $self->build_in($root);
425 }
426  
427 #pod =method dist_basename
428 #pod
429 #pod my $basename = $zilla->dist_basename;
430 #pod
431 #pod This method will return the dist's basename (e.g. C<Dist-Name-1.01>.
432 #pod The basename is used as the top-level directory in the tarball. It
433 #pod does not include C<-TRIAL>, even if building a trial dist.
434 #pod
435 #pod =cut
436  
437 57 ▶sub dist_basename {
Subroutine dist_basename: called CC=1 SCAR=0.0
Pod documented
438 57 my ($self) = @_;
439 57 return join(q{},
440 $self->name,
441 '-',
442 $self->version,
443 );
444 }
445  
446 #pod =method archive_basename
447 #pod
448 #pod my $basename = $zilla->archive_basename;
449 #pod
450 #pod This method will return the filename, without the format extension
451 #pod (e.g. C<Dist-Name-1.01> or C<Dist-Name-1.01-TRIAL>).
452 #pod
453 #pod =cut
454  
455 31 ▶sub archive_basename {
Subroutine archive_basename: called CC=3 SCAR=11.0
Pod documented
456 31 my ($self) = @_;
457 31 ▶ return join q{},
Branch: 1 branch
BranchTrueFalseTotal
$self->is_trial && !($self->version =~ /_/u) ? : 4 27 31
Condition100%3/3
$self->is_trial and not $self->version =~ /_/u
!ll&&!rl&&r
2614
MC/DC100%2/2
$self->is_trial and not $self->version =~ /_/u
$self->is_trial not $self->version =~ /_/u
Truth table100%3/3
A and not(B)
A= $self->is_trialB= not $self->version =~ /_/u
ABresult
0X0
100
111
458 $self->dist_basename,
459 ( $self->is_trial && $self->version !~ /_/ ? '-TRIAL' : '' ),
460 ;
461 }
462  
463 #pod =method archive_filename
464 #pod
465 #pod my $tarball = $zilla->archive_filename;
466 #pod
467 #pod This method will return the filename (e.g. C<Dist-Name-1.01.tar.gz>)
468 #pod of the tarball of this distribution. It will include C<-TRIAL> if building a
469 #pod trial distribution, unless the version contains an underscore. The tarball
470 #pod might not exist.
471 #pod
472 #pod =cut
473  
474 30 ▶sub archive_filename {
Subroutine archive_filename: called CC=1 SCAR=0.0
Pod documented
475 30 my ($self) = @_;
476 30 return join q{}, $self->archive_basename, '.tar.gz';
477 }
478  
479 #pod =method build_archive
480 #pod
481 #pod $zilla->build_archive;
482 #pod
483 #pod This method will ensure that the dist has been built, and will then build a
484 #pod tarball of the build directory in the current directory.
485 #pod
486 #pod =cut
487  
488 23 ▶sub build_archive {
Subroutine build_archive: called CC=4 SCAR=13.9
Pod documented
489 23 my ($self) = @_;
490  
491 23 my $built_in = $self->ensure_built;
492  
493 23 my $basedir = path($self->dist_basename);
494  
495 23 $_->before_archive for $self->plugins_with(-BeforeArchive)->@*;
496  
497 23 for my $builder ($self->plugins_with(-ArchiveBuilder)->@*) {
498 1 my $file = $builder->build_archive($self->archive_basename, $built_in, $basedir);
499 1 ▶ return $file if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 1 0 1
500 }
501  
502 22 my $archive = $self->_build_archive($built_in, $basedir);
503  
504 22 my $file = path($self->archive_filename);
505  
506 22 $self->log("writing archive to $file");
507 22 $archive->write("$file", 9);
508  
509 22 return $file;
510 }
511  
512 22 ▶sub _build_archive {
Subroutine _build_archive: called CC=3 SCAR=11.0
513 22 my ($self, $built_in, $basedir) = @_;
514  
515 22 require Archive::Tar;
516 22 my $archive = Archive::Tar->new;
517 22 my %seen_dir;
518 22 for my $distfile (
519 106 sort { length($a->name) <=> length($b->name) } @{ $self->files }
520 ) {
521 82 my $in = path($distfile->name)->parent;
522  
523 82 ▶ unless ($seen_dir{ $in }++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen_dir{$in}++) 64 18 82
524 64 $archive->add_data(
525 $basedir->child($in),
526 '',
527 { type => Archive::Tar::Constant::DIR(), mode => 0755 },
528 )
529 }
530  
531 82 my $filename = $built_in->child( $distfile->name );
532 82 $archive->add_data(
533 $basedir->child( $distfile->name ),
534 path($filename)->slurp_raw,
535 { mode => (stat $filename)[2] & ~022 },
536 );
537 }
538  
539 22 return $archive;
540 }
541  
542 150 ▶sub _prep_build_root {
Subroutine _prep_build_root: called CC=10 SCAR=30.2
543 150 my ($self, $build_root) = @_;
544  
545 150 ▶ $build_root = path($build_root || $self->dist_basename);
Condition66%2/3
$build_root || $self->dist_basename
l!l&&r!l&&!r
14910
MC/DC0%0/2
$build_root || $self->dist_basename
$build_root $self->dist_basename
Truth table66%2/3
A || B
A= $build_rootB= $self->dist_basename
ABresult
1X1
011
000
546  
547 150 ▶ $build_root->mkpath unless -d $build_root;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $build_root 1 149 150
548  
549 150 my $dist_root = $self->root;
550  
551 150 ▶ return $build_root if !-d $build_root;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $build_root 0 150 150
552  
553 150 my $ok = eval { $build_root->remove_tree({ safe => 0 }); 1 };
554 150 ▶ die "unable to delete '$build_root' in preparation of build: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 150 150
555  
556 # the following is done only on windows, and only if the deletion failed,
557 # yet rmtree reported success, because currently rmdir is non-blocking as per:
558 # https://rt.perl.org/Ticket/Display.html?id=123958
559 150 ▶ if ( $^O eq 'MSWin32' and -d $build_root ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32" and -d $build_root) 0 150 150
Condition33%1/3
$^O eq "MSWin32" and -d $build_root
!ll&&!rl&&r
15000
MC/DC0%0/2
$^O eq "MSWin32" and -d $build_root
$^O eq "MSWin32" -d $build_root
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= -d $build_root
ABresult
0X0
100
111
560 0 $self->log("spinning for at least one second to allow other processes to release locks on $build_root");
561 0 my $timeout = time + 2;
562 0 ▶ while(time != $timeout and -d $build_root) { }
Branch: 1 branch
BranchTrueFalseTotal
if (time != $timeout and -d $build_root) 0 0 0
Condition0%0/3
time != $timeout and -d $build_root
!ll&&!rl&&r
000
MC/DC0%0/2
time != $timeout and -d $build_root
time != $timeout -d $build_root
Truth table0%0/3
A and B
A= time != $timeoutB= -d $build_root
ABresult
0X0
100
111
563 0 ▶ die "unable to delete '$build_root' in preparation of build because some process has a lock on it"
Branch: 1 branch
BranchTrueFalseTotal
if -d $build_root 0 0 0
564 if -d $build_root;
565 }
566  
567 150 return $build_root;
568 }
569  
570 #pod =method release
571 #pod
572 #pod $zilla->release;
573 #pod
574 #pod This method releases the distribution, probably by uploading it to the CPAN.
575 #pod The actual effects of this method (as with most of the methods) is determined
576 #pod by the loaded plugins.
577 #pod
578 #pod =cut
579  
580 21 ▶sub release {
Subroutine release: called CC=5 SCAR=16.1
Pod documented
581 21 my $self = shift;
582  
583 Carp::croak("you can't release without any Releaser plugins")
584 21 ▶ unless my @releasers = @{ $self->plugins_with(-Releaser) };
Branch: 1 branch
BranchTrueFalseTotal
unless my(@releasers) = @{$self->plugins_with("-Releaser");} 0 21 21
585  
586 21 $ENV{DZIL_RELEASING} = 1;
587  
588 21 my $tgz = $self->build_archive;
589  
590 # call all plugins implementing BeforeRelease role
591 21 $_->before_release($tgz) for @{ $self->plugins_with(-BeforeRelease) };
592  
593 # do the actual release
594 13 $_->release($tgz) for @releasers;
595  
596 # call all plugins implementing AfterRelease role
597 11 $_->after_release($tgz) for @{ $self->plugins_with(-AfterRelease) };
598 }
599  
600 #pod =method clean
601 #pod
602 #pod This method removes temporary files and directories suspected to have been
603 #pod produced by the Dist::Zilla build process. Specifically, it deletes the
604 #pod F<.build> directory and any entity that starts with the dist name and a hyphen,
605 #pod like matching the glob C<Your-Dist-*>.
606 #pod
607 #pod =cut
608  
609 0 ▶sub clean {
Subroutine clean: not called CC=3 SCAR=19.6
Pod documented
610 0 my ($self, $dry_run) = @_;
611  
612 0 require File::Path;
613 0 ▶ for my $x (grep { -e } '.build', glob($self->name . '-*')) {
Subroutine BEGIN: called CC=1 SCAR=0.6
614 0 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 0 0 0
615 0 $self->log("clean: would remove $x");
616 } else {
617 0 $self->log("clean: removing $x");
618 0 File::Path::rmtree($x);
619 }
620 };
621 }
622  
623 #pod =method ensure_built_in_tmpdir
624 #pod
625 #pod $zilla->ensure_built_in_tmpdir;
626 #pod
627 #pod This method will consistently build the distribution in a temporary
628 #pod subdirectory. It will return the path for the temporary build location.
629 #pod
630 #pod =cut
631  
632 1 ▶sub ensure_built_in_tmpdir {
Subroutine ensure_built_in_tmpdir: called CC=8 SCAR=23.2
Pod documented
633 1 my $self = shift;
634  
635 1 require File::Temp;
636  
637 1 my $build_root = path('.build');
638 1 ▶ $build_root->mkpath unless -d $build_root;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $build_root 1 0 1
639  
640 1 my $target = path( File::Temp::tempdir(DIR => $build_root) );
641 1 $self->log("building distribution under $target for installation");
642  
643 1 my $os_has_symlinks = eval { symlink("",""); 1 };
644 1 my $previous;
645 my $latest;
646  
647 1 ▶ if( $os_has_symlinks ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os_has_symlinks) 1 0 1
648 1 $previous = path( $build_root, 'previous' );
649 1 $latest = path( $build_root, 'latest' );
650 1 ▶ if( -l $previous ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $previous) 0 1 1
651 0 ▶ $previous->remove
Branch: 1 branch
BranchTrueFalseTotal
$previous->remove or $self->log("cannot remove old .build/previous link") 0 0 0
652 or $self->log("cannot remove old .build/previous link");
653 }
654 1 ▶ if( -l $latest ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $latest) 0 1 1
655 0 ▶ rename $latest, $previous
Branch: 1 branch
BranchTrueFalseTotal
rename $latest, $previous or $self->log("cannot move .build/latest link to .build/previous") 0 0 0
656 or $self->log("cannot move .build/latest link to .build/previous");
657 }
658 1 ▶ symlink $target->basename, $latest
Branch: 1 branch
BranchTrueFalseTotal
symlink $target->basename, $latest or $self->log("cannot create link .build/latest") 1 0 1
659 or $self->log('cannot create link .build/latest');
660 }
661  
662 1 $self->ensure_built_in($target);
663  
664 1 return ($target, $latest, $previous);
665 }
666  
667 #pod =method install
668 #pod
669 #pod $zilla->install( \%arg );
670 #pod
671 #pod This method installs the distribution locally. The distribution will be built
672 #pod in a temporary subdirectory, then the process will change directory to that
673 #pod subdir and an installer will be run.
674 #pod
675 #pod Valid arguments are:
676 #pod
677 #pod keep_build_dir - if true, don't rmtree the build dir, even if everything
678 #pod seemed to work
679 #pod install_command - the command to run in the subdir to install the dist
680 #pod default (roughly): $^X -MCPAN -einstall .
681 #pod
682 #pod this argument should be an arrayref
683 #pod
684 #pod =cut
685  
686 0 ▶sub install {
Subroutine install: not called CC=9 SCAR=45.0
Pod documented
687 0 my ($self, $arg) = @_;
688 0 ▶ $arg ||= {};
Condition0%0/2
$arg ||= {}
l!l
00
MC/DC0%0/1
$arg ||= {}
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
689  
690 0 my ($target, $latest) = $self->ensure_built_in_tmpdir;
691  
692 0 my $ok = eval {
693 ## no critic Punctuation
694 0 my $wd = File::pushd::pushd($target);
695 my @cmd = $arg->{install_command}
696 0 ▶ ? @{ $arg->{install_command} }
Branch: 1 branch
BranchTrueFalseTotal
$arg->{'install_command'} ? : 0 0 0
697 : (cpanm => ".");
698  
699 0 $self->log_debug([ 'installing via %s', \@cmd ]);
700 0 ▶ system(@cmd) && $self->log_fatal([ "error running %s", \@cmd ]);
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and $self->log_fatal(["error running %s", \@cmd]) 0 0 0
701 0 1;
702 };
703  
704 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
705 0 ▶ my $error = $@ || '(exception clobered)';
Condition0%0/2
$@ || '(exception clobered)'
l!l
00
MC/DC0%0/1
$@ || '(exception clobered)'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
706 0 $self->log("install failed, left failed dist in place at $target");
707 0 die $error;
708 }
709  
710 0 ▶ if ($arg->{keep_build_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'keep_build_dir'}) { } 0 0 0
711 0 $self->log("all's well; left dist in place at $target");
712 } else {
713 0 $self->log("all's well; removing $target");
714 0 $target->remove_tree({ safe => 0 });
715 0 ▶ $latest->remove_tree({ safe => 0 }) if -d $latest; # error cannot unlink, is a directory
Branch: 1 branch
BranchTrueFalseTotal
if -d $latest 0 0 0
716 0 ▶ $latest->remove if $latest;
Branch: 1 branch
BranchTrueFalseTotal
if $latest 0 0 0
717 }
718  
719 0 return;
720 }
721  
722 #pod =method test
723 #pod
724 #pod $zilla->test(\%arg);
725 #pod
726 #pod This method builds a new copy of the distribution and tests it using
727 #pod C<L</run_tests_in>>.
728 #pod
729 #pod C<\%arg> may be omitted. Otherwise, valid arguments are:
730 #pod
731 #pod keep_build_dir - if true, don't rmtree the build dir, even if everything
732 #pod seemed to work
733 #pod
734 #pod =cut
735  
736 1 ▶sub test {
Subroutine test: called CC=7 SCAR=22.8
Pod documented
737 1 my ($self, $arg) = @_;
738  
739 Carp::croak("you can't test without any TestRunner plugins")
740 1 ▶ unless my @testers = @{ $self->plugins_with(-TestRunner) };
Branch: 1 branch
BranchTrueFalseTotal
unless my(@testers) = @{$self->plugins_with("-TestRunner");} 0 1 1
741  
742 1 my ($target, $latest) = $self->ensure_built_in_tmpdir;
743 1 my $error = $self->run_tests_in($target, $arg);
744  
745 1 ▶ if ($arg and $arg->{keep_build_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg and $arg->{"keep_build_dir"}) 0 1 1
Condition33%1/3
$arg and $arg->{"keep_build_dir"}
!ll&&!rl&&r
100
MC/DC0%0/2
$arg and $arg->{"keep_build_dir"}
$arg $arg->{"keep_build_dir"}
Truth table33%1/3
A and B
A= $argB= $arg->{"keep_build_dir"}
ABresult
0X0
100
111
746 0 $self->log("all's well; left dist in place at $target");
747 0 return;
748 }
749  
750 1 $self->log("all's well; removing $target");
751 1 $target->remove_tree({ safe => 0 });
752 1 ▶ $latest->remove_tree({ safe => 0 }) if $latest && -d $latest; # error cannot unlink, is a directory
Branch: 1 branch
BranchTrueFalseTotal
if $latest and -d $latest 0 1 1
Condition33%1/3
$latest and -d $latest
!ll&&!rl&&r
010
MC/DC0%0/2
$latest and -d $latest
$latest -d $latest
Truth table33%1/3
A and B
A= $latestB= -d $latest
ABresult
0X0
100
111
753 1 ▶ $latest->remove if $latest;
Branch: 1 branch
BranchTrueFalseTotal
if $latest 1 0 1
754 }
755  
756 #pod =method run_tests_in
757 #pod
758 #pod my $error = $zilla->run_tests_in($directory, $arg);
759 #pod
760 #pod This method runs the tests in $directory (a Path::Tiny), which must contain an
761 #pod already-built copy of the distribution. It will throw an exception if there
762 #pod are test failures.
763 #pod
764 #pod It does I<not> set any of the C<*_TESTING> environment variables, nor
765 #pod does it clean up C<$directory> afterwards.
766 #pod
767 #pod =cut
768  
769 2 ▶sub run_tests_in {
Subroutine run_tests_in: called CC=3 SCAR=11.0
Pod documented
770 2 my ($self, $target, $arg) = @_;
771  
772 Carp::croak("you can't test without any TestRunner plugins")
773 2 ▶ unless my @testers = @{ $self->plugins_with(-TestRunner) };
Branch: 1 branch
BranchTrueFalseTotal
unless my(@testers) = @{$self->plugins_with("-TestRunner");} 0 2 2
774  
775 2 for my $tester (@testers) {
776 2 my $wd = File::pushd::pushd($target);
777 2 $tester->test( $target, $arg );
778 }
779 }
780  
781 #pod =method run_in_build
782 #pod
783 #pod $zilla->run_in_build( \@cmd );
784 #pod
785 #pod This method makes a temporary directory, builds the distribution there,
786 #pod executes all the dist's L<BuildRunner|Dist::Zilla::Role::BuildRunner>s
787 #pod (unless directed not to, via C<< $arg->{build} = 0 >>), and
788 #pod then runs the given command in the build directory. If the command exits
789 #pod non-zero, the directory will be left in place.
790 #pod
791 #pod =cut
792  
793 0 ▶sub run_in_build {
Subroutine run_in_build: not called CC=16 SCAR=56.1
Pod documented
794 0 my ($self, $cmd, $arg) = @_;
795  
796 $self->log_fatal("you can't build without any BuildRunner plugins")
797 unless ($arg and exists $arg->{build} and ! $arg->{build})
798 0 ▶ or @{ $self->plugins_with(-BuildRunner) };
Branch: 1 branch
BranchTrueFalseTotal
unless $arg and exists $arg->{"build"} and not $arg->{"build"} or @{$self->plugins_with("-BuildRunner");} 0 0 0
Condition0%0/9
$arg and exists $arg->{"build"} and not $arg->{"build"} or @{$self->plugins_with("-BuildRunner");}
l!l&&r!l&&!r
000
$arg and exists $arg->{"build"} and not $arg->{"build"}
!ll&&!rl&&r
000
$arg and exists $arg->{"build"}
!ll&&!rl&&r
000
MC/DC0%0/4
$arg and exists $arg->{"build"} and not $arg->{"build"} or @{$self->plugins_with("-BuildRunner");}
$arg exists $arg->{"build"} not $arg->{"build"} @{$self->plugins_with("-BuildRunner");}
Truth table0%0/7
A and B and not(C) or D
A= $argB= exists $arg->{"build"}C= not $arg->{"build"}D= @{$self->plugins_with("-BuildRunner");}
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
799  
800 0 require "Config.pm"; # skip autoprereq
801  
802 0 my ($target, $latest) = $self->ensure_built_in_tmpdir;
803 0 my $abstarget = $target->absolute;
804  
805 # building the dist for real
806 0 my $ok = eval {
807 0 my $wd = File::pushd::pushd($target);
808  
809 0 ▶ if ($arg and exists $arg->{build} and ! $arg->{build}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg and exists $arg->{"build"} and not $arg->{"build"}) 0 0 0
Condition0%0/6
$arg and exists $arg->{"build"} and not $arg->{"build"}
!ll&&!rl&&r
000
$arg and exists $arg->{"build"}
!ll&&!rl&&r
000
MC/DC0%0/3
$arg and exists $arg->{"build"} and not $arg->{"build"}
$arg exists $arg->{"build"} not $arg->{"build"}
Truth table0%0/4
A and B and not(C)
A= $argB= exists $arg->{"build"}C= not $arg->{"build"}
ABCresult
0XX0
10X0
1100
1111
810 0 ▶ system(@$cmd) and die "error while running: @$cmd";
Branch: 1 branch
BranchTrueFalseTotal
system @$cmd and die "error while running: @$cmd" 0 0 0
811 0 return 1;
812 }
813  
814 0 $self->_ensure_blib;
815  
816 local $ENV{PERL5LIB} = join $Config::Config{path_sep},
817 0 ▶ (map { $abstarget->child('blib', $_) } qw(arch lib)),
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL5LIB'} ? : 0 0 0
818 0 (defined $ENV{PERL5LIB} ? $ENV{PERL5LIB} : ());
819  
820 local $ENV{PATH} = join $Config::Config{path_sep},
821 0 ▶ (map { $abstarget->child('blib', $_) } qw(bin script)),
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PATH'} ? : 0 0 0
822 0 (defined $ENV{PATH} ? $ENV{PATH} : ());
823  
824 0 ▶ system(@$cmd) and die "error while running: @$cmd";
Branch: 1 branch
BranchTrueFalseTotal
system @$cmd and die "error while running: @$cmd" 0 0 0
825 0 1;
826 };
827  
828 0 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 0 0 0
829 0 $self->log("all's well; removing $target");
830 0 $target->remove_tree({ safe => 0 });
831 0 ▶ $latest->remove_tree({ safe => 0 }) if -d $latest; # error cannot unlink, is a directory
Branch: 1 branch
BranchTrueFalseTotal
if -d $latest 0 0 0
832 0 ▶ $latest->remove if $latest;
Branch: 1 branch
BranchTrueFalseTotal
if $latest 0 0 0
833 } else {
834 0 ▶ my $error = $@ || '(unknown error)';
Condition0%0/2
$@ || '(unknown error)'
l!l
00
MC/DC0%0/1
$@ || '(unknown error)'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
835 0 $self->log($error);
836 0 $self->log_fatal("left failed dist in place at $target");
837 }
838 }
839  
840 # Ensures that a F<blib> directory exists in the build, by invoking all
841 # C<-BuildRunner> plugins to generate it. Useful for commands that operate on
842 # F<blib>, such as C<test> or C<run>.
843  
844 0 ▶sub _ensure_blib {
Subroutine _ensure_blib: not called CC=5 SCAR=34.0
845 0 my ($self) = @_;
846  
847 0 ▶ unless ( -d 'blib' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "blib") 0 0 0
848 0 my @builders = @{ $self->plugins_with( -BuildRunner ) };
849 0 ▶ $self->log_fatal("no BuildRunner plugins specified") unless @builders;
Branch: 1 branch
BranchTrueFalseTotal
unless @builders 0 0 0
850 0 $_->build for @builders;
851 0 ▶ $self->log_fatal("no blib; failed to build properly?") unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
852 }
853 }
854  
855 51 __PACKAGE__->meta->make_immutable;
856 51 1;
857  
858 __END__
« blib/lib/Dist/Zilla/App/Command/setup.pm ↑ Summary blib/lib/Dist/Zilla/Role/BuildPL.pm »