blib/lib/Dist/Zilla.pm

filter: Statementstmt 90.7% 254 / 280 Branchbran 68.4% 63 / 92 Conditioncond 81.2% 13 / 16 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 98.0% 50 / 51 Podpod 80.0% 4 / 5 totaltotal 85.9% 390 / 454 CC 61 SCAR 15.4
CC
61
Cov
85%
_check_dupe_files
12.5
_build_license
10.2
__ANON__
9.0
CRAP 4.7
« blib/lib/Dist/Zilla/Plugin/MetaResources.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/GatherDir/Template.pm »
1 package Dist::Zilla 6.040;
2 # ABSTRACT: distribution builder; installer not included!
3  
4 53 ▶use Moose 0.92; # role composition fixes
Subroutine BEGIN: called CC=1 SCAR=0.0
5 53 with 'Dist::Zilla::Role::ConfigDumper';
6  
7 53 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # This comment has fün̈n̈ÿ characters.
10  
11 53 ▶use MooseX::Types::Moose qw(ArrayRef Bool HashRef Object Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 53 ▶use MooseX::Types::Perl qw(DistName LaxVersionStr);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 53 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 53 ▶use Dist::Zilla::Types qw(Path License ReleaseStatus);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 53 ▶use Log::Dispatchouli 1.100712; # proxy_loggers, quiet_fatal
Subroutine BEGIN: called CC=1 SCAR=0.0
18 53 ▶use Dist::Zilla::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 53 ▶use List::Util 1.33 qw(first none);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 53 ▶use Software::License 0.104001; # ->program
Subroutine BEGIN: called CC=1 SCAR=0.0
21 53 ▶use String::RewritePrefix;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 53 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 53 ▶use Dist::Zilla::Prereqs;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 53 ▶use Dist::Zilla::File::OnDisk;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 53 ▶use Dist::Zilla::Role::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 53 ▶use Dist::Zilla::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 53 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 53 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 #pod =head1 DESCRIPTION
33 #pod
34 #pod Dist::Zilla builds distributions of code to be uploaded to the CPAN. In this
35 #pod respect, it is like L<ExtUtils::MakeMaker>, L<Module::Build>, or
36 #pod L<Module::Install>. Unlike those tools, however, it is not also a system for
37 #pod installing code that has been downloaded from the CPAN. Since it's only run by
38 #pod authors, and is meant to be run on a repository checkout rather than on
39 #pod published, released code, it can do much more than those tools, and is free to
40 #pod make much more ludicrous demands in terms of prerequisites.
41 #pod
42 #pod If you have access to the web, you can learn more and find an interactive
43 #pod tutorial at B<L<dzil.org|https://dzil.org/>>. If not, try
44 #pod L<Dist::Zilla::Tutorial>.
45 #pod
46 #pod =cut
47  
48 53 has chrome => (
49 is => 'rw',
50 isa => role_type('Dist::Zilla::Role::Chrome'),
51 required => 1,
52 );
53  
54 #pod =attr name
55 #pod
56 #pod The name attribute (which is required) gives the name of the distribution to be
57 #pod built. This is usually the name of the distribution's main module, with the
58 #pod double colons (C<::>) replaced with dashes. For example: C<Dist-Zilla>.
59 #pod
60 #pod =cut
61  
62 53 has name => (
63 is => 'ro',
64 isa => DistName,
65 lazy => 1,
66 builder => '_build_name',
67 );
68  
69 #pod =attr version
70 #pod
71 #pod This is the version of the distribution to be created.
72 #pod
73 #pod =cut
74  
75 53 has _version_override => (
76 isa => LaxVersionStr,
77 is => 'ro' ,
78 init_arg => 'version',
79 );
80  
81 # XXX: *clearly* this needs to be really much smarter -- rjbs, 2008-06-01
82 53 has version => (
83 is => 'rw',
84 isa => LaxVersionStr,
85 lazy => 1,
86 init_arg => undef,
87 builder => '_build_version',
88 );
89  
90 1 ▶sub _build_name {
Subroutine _build_name: called CC=5 SCAR=16.5
91 1 my ($self) = @_;
92  
93 1 my $name;
94 1 for my $plugin (@{ $self->plugins_with(-NameProvider) }) {
95 1 ▶ next unless defined(my $this_name = $plugin->provide_name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $this_name = $plugin->provide_name) 0 1 1
96  
97 1 ▶ $self->log_fatal('attempted to set name twice') if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 1 1
98  
99 1 $name = $this_name;
100 }
101  
102 1 ▶ $self->log_fatal('no name was ever set') unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
103  
104 1 $name;
105 }
106  
107 155 ▶sub _build_version {
Subroutine _build_version: called CC=5 SCAR=16.5
108 155 my ($self) = @_;
109  
110 155 my $version = $self->_version_override;
111  
112 155 for my $plugin (@{ $self->plugins_with(-VersionProvider) }) {
113 3 ▶ next unless defined(my $this_version = $plugin->provide_version);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $this_version = $plugin->provide_version) 0 3 3
114  
115 3 ▶ $self->log_fatal('attempted to set version twice') if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 3 3
116  
117 3 $version = $this_version;
118 }
119  
120 155 ▶ $self->log_fatal('no version was ever set') unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 155 155
121  
122 155 $version;
123 }
124  
125 #pod =attr release_status
126 #pod
127 #pod This attribute sets the release status to one of the
128 #pod L<CPAN::META::Spec|https://metacpan.org/pod/CPAN::Meta::Spec#release_status>
129 #pod values: 'stable', 'testing' or 'unstable'.
130 #pod
131 #pod If the C<$ENV{RELEASE_STATUS}> environment variable exists, its value will
132 #pod be used as the release status.
133 #pod
134 #pod For backwards compatibility, if C<$ENV{RELEASE_STATUS}> does not exist and
135 #pod the C<$ENV{TRIAL}> variable is true, the release status will be 'testing'.
136 #pod
137 #pod Otherwise, the release status will be set from a
138 #pod L<ReleaseStatusProvider|Dist::Zilla::Role::ReleaseStatusProvider>, if one
139 #pod has been configured.
140 #pod
141 #pod For backwards compatibility, setting C<is_trial> true in F<dist.ini> is
142 #pod equivalent to using a C<ReleaseStatusProvider>. If C<is_trial> is false,
143 #pod it has no effect.
144 #pod
145 #pod Only B<one> C<ReleaseStatusProvider> may be used.
146 #pod
147 #pod If no providers are used, the release status defaults to 'stable' unless there
148 #pod is an "_" character in the version, in which case, it defaults to 'testing'.
149 #pod
150 #pod =cut
151  
152 # release status must be lazy, after files are gathered
153 53 has release_status => (
154 is => 'ro',
155 isa => ReleaseStatus,
156 lazy => 1,
157 builder => '_build_release_status',
158 );
159  
160 154 ▶sub _build_release_status {
Subroutine _build_release_status: called CC=8 SCAR=20.8
161 154 my ($self) = @_;
162  
163 # environment variables override completely
164 154 ▶ return $self->_release_status_from_env if $self->_release_status_from_env;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_release_status_from_env 7 147 154
165  
166 # other ways of setting status must not conflict
167 147 my $status;
168  
169 # dist.ini is equivalent to a release provider if is_trial is true.
170 # If false, though, we want other providers to run or fall back to
171 # the version
172 147 ▶ $status = 'testing' if $self->_override_is_trial;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_override_is_trial 2 145 147
173  
174 147 for my $plugin (@{ $self->plugins_with(-ReleaseStatusProvider) }) {
175 3 ▶ next unless defined(my $this_status = $plugin->provide_release_status);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $this_status = $plugin->provide_release_status) 0 3 3
176  
177 3 ▶ $self->log_fatal('attempted to set release status twice')
Branch: 1 branch
BranchTrueFalseTotal
if defined $status 1 2 3
178 if defined $status;
179  
180 2 $status = $this_status;
181 }
182  
183 146 ▶ return $status || ( $self->version =~ /_/ ? 'testing' : 'stable' );
Branch: 1 branch
BranchTrueFalseTotal
$self->version =~ /_/u ? : 5 138 143
Condition66%2/3
$status || ($self->version =~ /_/u ? 'testing' : 'stable')
l!l&&r!l&&!r
31430
MC/DC0%0/2
$status || ($self->version =~ /_/u ? 'testing' : 'stable')
$status ($self->version =~ /_/u ? 'testing' : 'stable')
Truth table66%2/3
A || B
A= $statusB= ($self->version =~ /_/u ? 'testing' : 'stable')
ABresult
1X1
011
000
184 }
185  
186 # captures environment variables early during Zilla object construction
187 53 has _release_status_from_env => (
188 is => 'ro',
189 isa => Str,
190 builder => '_build_release_status_from_env',
191 );
192  
193 199 ▶sub _build_release_status_from_env {
Subroutine _build_release_status_from_env: called CC=3 SCAR=11.0
194 199 my ($self) = @_;
195 199 ▶ return $ENV{RELEASE_STATUS} if $ENV{RELEASE_STATUS};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"RELEASE_STATUS"} 1 198 199
196 198 ▶ return $ENV{TRIAL} ? 'testing' : '';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'TRIAL'} ? : 6 192 198
197 }
198  
199 #pod =attr abstract
200 #pod
201 #pod This is a one-line summary of the distribution. If none is given, one will be
202 #pod looked for in the L</main_module> of the dist.
203 #pod
204 #pod =cut
205  
206 has abstract => (
207 is => 'rw',
208 isa => 'Str',
209 lazy => 1,
210 7 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=12.3
211 7 my ($self) = @_;
212  
213 7 ▶ unless ($self->main_module) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->main_module) 0 7 7
214 0 die "no abstract given and no main_module found; make sure your main module is in ./lib\n";
215 }
216  
217 7 my $file = $self->main_module;
218 7 $self->log_debug("extracting distribution abstract from " . $file->name);
219 7 my $abstract = Dist::Zilla::Util->abstract_from_file($file);
220  
221 7 ▶ if (!defined($abstract)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $abstract) 0 7 7
222 0 my $filename = $file->name;
223 0 die "Unable to extract an abstract from $filename. Please add the following comment to the file with your abstract:
224 # ABSTRACT: turns baubles into trinkets
225 ";
226 }
227  
228 7 return $abstract;
229 }
230 53 );
231  
232 #pod =attr main_module
233 #pod
234 #pod This is the module where Dist::Zilla might look for various defaults, like
235 #pod the distribution abstract. By default, it's derived from the distribution
236 #pod name. If your distribution is Foo-Bar, and F<lib/Foo/Bar.pm> exists,
237 #pod that's the main_module. Otherwise, it's the shortest-named module in the
238 #pod distribution. This may change!
239 #pod
240 #pod You can override the default by specifying the file path explicitly,
241 #pod ie:
242 #pod
243 #pod main_module = lib/Foo/Bar.pm
244 #pod
245 #pod =cut
246  
247 53 has _main_module_override => (
248 isa => 'Str',
249 is => 'ro' ,
250 init_arg => 'main_module',
251 predicate => '_has_main_module_override',
252 );
253  
254 has main_module => (
255 is => 'ro',
256 isa => 'Dist::Zilla::Role::File',
257 lazy => 1,
258 init_arg => undef,
259 14 ▶ default => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
260 14 my ($self) = @_;
261  
262 14 my $file;
263 my $guess;
264  
265 14 ▶ if ( $self->_has_main_module_override ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_main_module_override) { } 4 10 14
266 7 ▶ $file = first { $_->name eq $self->_main_module_override }
Subroutine __ANON__: called CC=1 SCAR=0.0
267 4 @{ $self->files };
268 } else {
269 # We're having to guess
270  
271 10 $guess = $self->name =~ s{-}{/}gr;
272 10 $guess = "lib/$guess.pm";
273  
274 10 ▶ $file = (first { $_->name eq $guess } @{ $self->files })
Subroutine __ANON__: called CC=1 SCAR=0.0
275 1 || (sort { length $a->name <=> length $b->name }
276 61 ▶ grep { $_->name =~ m{\.pm\z} and $_->name =~ m{\Alib/} }
Condition66%2/3
$_->name =~ /\.pm\z/u && $_->name =~ m[\Alib/]u
!ll&&!rl&&r
5407
MC/DC50%1/2
$_->name =~ /\.pm\z/u && $_->name =~ m[\Alib/]u
$_->name =~ /\.pm\z/u $_->name =~ m[\Alib/]u
Truth table66%2/3
A && B
A= $_->name =~ /\.pm\z/uB= $_->name =~ m[\Alib/]u
ABresult
0X0
100
111
277 10 ▶ @{ $self->files })[0];
Condition100%3/3
&first(sub { $_->name eq $guess; } , @{$self->files;}) || (sort {length $a->name <=> length $b->name;} grep({$_->name =~ /\.pm\z/u and $_->name =~ m[\Alib/]u;} @{$self->files;}))[0]
l!l&&r!l&&!r
262
MC/DC100%2/2
&first(sub { $_->name eq $guess; } , @{$self->files;}) || (sort {length $a->name <=> length $b->name;} grep({$_->name =~ /\.pm\z/u and $_->name =~ m[\Alib/]u;} @{$self->files;}))[0]
&first(sub { $_->name eq $guess; } , @{$self->files;}) (sort {length $a->name <=> length $b->name;} grep({$_->name =~ /\.pm\z/u and $_->name =~ m[\Alib/]u;} @{$self->files;}))[0]
Truth table100%3/3
A || B
A= &first(sub { $_->name eq $guess; } , @{$self->files;})B= (sort {length $a->name <=> length $b->name;} grep({$_->name =~ /\.pm\z/u and $_->name =~ m[\Alib/]u;} @{$self->files;}))[0]
ABresult
1X1
011
000
278 10 ▶ $self->log("guessing dist's main_module is " . ($file ? $file->name : $guess));
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 8 2 10
279 }
280  
281 14 ▶ if (not $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 5 9 14
282 5 my @errorlines;
283  
284 5 push @errorlines, "Unable to find main_module in the distribution";
285 5 ▶ if ($self->_has_main_module_override) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_main_module_override) { } 3 2 5
286 3 push @errorlines, "'main_module' was specified in dist.ini but the file '" . $self->_main_module_override . "' is not to be found in our dist. ( Did you add it? )";
287 } else {
288 2 push @errorlines,"We tried to guess '$guess' but no file like that existed";
289 }
290 5 ▶ if (not @{ $self->files }) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @{$self->files;}) { } 2 3 5
elsif (&none(sub { $_->name =~ m[^lib/.+\.pm\z]u; } , @{$self->files;})) { } 2 1 3
291 2 push @errorlines, "Upon further inspection we didn't find any files in your dist, did you add any?";
292 3 ▶ } elsif ( none { $_->name =~ m{^lib/.+\.pm\z} } @{ $self->files } ){
Subroutine __ANON__: called CC=1 SCAR=0.0
293 2 push @errorlines, "We didn't find any .pm files in your dist, this is probably a problem.";
294 }
295 5 push @errorlines,"Cannot continue without a main_module";
296 5 $self->log_fatal( join qq{\n}, @errorlines );
297 }
298 9 $self->log_debug("dist's main_module is " . $file->name);
299  
300 9 return $file;
301 },
302 53 );
303  
304 #pod =attr license
305 #pod
306 #pod This is the L<Software::License|Software::License> object for this dist's
307 #pod license and copyright.
308 #pod
309 #pod It will be created automatically, if possible, with the
310 #pod C<copyright_holder> and C<copyright_year> attributes. If necessary, it will
311 #pod try to guess the license from the POD of the dist's main module.
312 #pod
313 #pod A better option is to set the C<license> name in the dist's config to something
314 #pod understandable, like C<Perl_5>.
315 #pod
316 #pod If C<copyright_year> is not given, the current year is used. If it is given,
317 #pod it is used as a string, so a range like C<2008 - 2012> is fine. The string
318 #pod C<$this_year>, wherever it appears in C<copyright_year>, is replaced with the
319 #pod current year when the license is built, so C<2008 - $this_year> would become
320 #pod C<2008 - 2026> when built in 2026.
321 #pod
322 #pod =cut
323  
324 53 has license => (
325 is => 'ro',
326 isa => License,
327 lazy => 1,
328 init_arg => 'license_obj',
329 predicate => '_has_license',
330 builder => '_build_license',
331 handles => {
332 copyright_holder => 'holder',
333 copyright_year => 'year',
334 },
335 );
336  
337 161 ▶sub _build_license {
Subroutine _build_license: called CC=8 SCAR=23.2
338 161 my ($self) = @_;
339  
340 161 my $license_class = $self->_license_class;
341 161 my $copyright_holder = $self->_copyright_holder;
342 161 my $copyright_year = $self->_copyright_year;
343  
344 161 $copyright_year =~ s{\$this_year\b}{ (localtime)[5] + 1900 }ge;
345  
346 161 my $provided_license;
347  
348 161 for my $plugin (@{ $self->plugins_with(-LicenseProvider) }) {
349 1 my $this_license = $plugin->provide_license({
350 copyright_holder => $copyright_holder,
351 copyright_year => $copyright_year,
352 });
353  
354 1 ▶ next unless defined $this_license;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this_license 0 1 1
355  
356 1 ▶ $self->log_fatal('attempted to set license twice')
Branch: 1 branch
BranchTrueFalseTotal
if defined $provided_license 0 1 1
357 if defined $provided_license;
358  
359 1 $provided_license = $this_license;
360 }
361  
362 161 ▶ return $provided_license if defined $provided_license;
Branch: 1 branch
BranchTrueFalseTotal
if defined $provided_license 1 160 161
363  
364 160 ▶ if ($license_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license_class) { } 160 0 160
365 160 $license_class = String::RewritePrefix->rewrite(
366 {
367 '=' => '',
368 '' => 'Software::License::'
369 },
370 $license_class,
371 );
372 } else {
373 0 require Software::LicenseUtils;
374 0 my @guess = Software::LicenseUtils->guess_license_from_pod(
375 $self->main_module->content
376 );
377  
378 0 ▶ if (@guess != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@guess != 1) 0 0 0
379 0 $self->log_fatal(
380 "no license data in config, no %Rights stash,",
381 "couldn't make a good guess at license from Pod; giving up. ",
382 "Perhaps you need to set up a global config file (dzil setup)?"
383 );
384 }
385  
386 0 my $filename = $self->main_module->name;
387 0 $license_class = $guess[0];
388 0 $self->log("based on POD in $filename, guessing license is $guess[0]");
389 }
390  
391 160 ▶ unless (eval { require_module($license_class) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &require_module($license_class) } }) 0 160 160
392 0 $self->log_fatal(
393 "could not load class $license_class for license " . $self->_license_class
394 );
395 }
396  
397 160 my $license = $license_class->new({
398 holder => $self->_copyright_holder,
399 year => $copyright_year,
400 program => $self->name,
401 });
402  
403 160 $self->_clear_license_class;
404 160 $self->_clear_copyright_holder;
405 160 $self->_clear_copyright_year;
406  
407 160 return $license;
408 }
409  
410 has _license_class => (
411 is => 'ro',
412 isa => 'Maybe[Str]',
413 lazy => 1,
414 init_arg => 'license',
415 clearer => '_clear_license_class',
416 2 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
417 2 my $stash = $_[0]->stash_named('%Rights');
418 2 ▶ $stash && return $stash->license_class;
Branch: 1 branch
BranchTrueFalseTotal
$stash and return $stash->license_class 1 1 2
419 1 return;
420 }
421 53 );
422  
423 has _copyright_holder => (
424 is => 'ro',
425 isa => 'Maybe[Str]',
426 lazy => 1,
427 init_arg => 'copyright_holder',
428 clearer => '_clear_copyright_holder',
429 1 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
430 1 ▶ return unless my $stash = $_[0]->stash_named('%Rights');
Branch: 1 branch
BranchTrueFalseTotal
unless my $stash = $_[0]->stash_named("%Rights") 0 1 1
431 1 ▶ $stash && return $stash->copyright_holder;
Branch: 1 branch
BranchTrueFalseTotal
$stash and return $stash->copyright_holder 1 0 1
432 0 return;
433 }
434 53 );
435  
436 has _copyright_year => (
437 is => 'ro',
438 isa => 'Str',
439 lazy => 1,
440 init_arg => 'copyright_year',
441 clearer => '_clear_copyright_year',
442 154 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
443 154 my $stash = $_[0]->stash_named('%Rights');
444 154 ▶ my $year = $stash && $stash->copyright_year;
Condition100%3/3
$stash && $stash->copyright_year
!ll&&!rl&&r
15211
MC/DC100%2/2
$stash && $stash->copyright_year
$stash $stash->copyright_year
Truth table100%3/3
A && B
A= $stashB= $stash->copyright_year
ABresult
0X0
100
111
445 154 ▶ return( $year // (localtime)[5] + 1900 );
Condition100%2/2
$year // (localtime)[5] + 1900
l!l
1153
MC/DC100%1/1
$year // (localtime)[5] + 1900
$year
Truth table100%2/2
A
A= $year
Aresult
11
00
446 }
447 53 );
448  
449 #pod =attr authors
450 #pod
451 #pod This is an arrayref of author strings, like this:
452 #pod
453 #pod [
454 #pod 'Ricardo Signes <rjbs@cpan.org>',
455 #pod 'X. Ample, Jr <example@example.biz>',
456 #pod ]
457 #pod
458 #pod This is likely to change at some point in the near future.
459 #pod
460 #pod =cut
461  
462 has authors => (
463 is => 'ro',
464 isa => ArrayRef[Str],
465 lazy => 1,
466 1 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=16.7
467 1 my ($self) = @_;
468  
469 1 ▶ if (my $stash = $self->stash_named('%User')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stash = $self->stash_named("%User")) 1 0 1
470 1 return $stash->authors;
471 }
472  
473 0 ▶ my $author = try { $self->copyright_holder };
Subroutine __ANON__: not called CC=1 SCAR=6.9
474 0 ▶ return [ $author ] if length $author;
Branch: 1 branch
BranchTrueFalseTotal
if length $author 0 0 0
475  
476 0 $self->log_fatal(
477 "No %User stash and no copyright holder;",
478 "can't determine dist author; configure author or a %User section",
479 );
480 },
481 53 );
482  
483 #pod =attr files
484 #pod
485 #pod This is an arrayref of objects implementing L<Dist::Zilla::Role::File> that
486 #pod will, if left in this arrayref, be built into the dist.
487 #pod
488 #pod Non-core code should avoid altering this arrayref, but sometimes there is not
489 #pod other way to change the list of files. In the future, the representation used
490 #pod for storing files B<will be changed>.
491 #pod
492 #pod =cut
493  
494 has files => (
495 is => 'ro',
496 isa => ArrayRef[ role_type('Dist::Zilla::Role::File') ],
497 lazy => 1,
498 init_arg => undef,
499 178 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
500 53 );
501  
502 30 ▶sub prune_file {
Subroutine prune_file: called CC=3 SCAR=11.0
Pod undocumented
503 30 my ($self, $file) = @_;
504 30 my @files = @{ $self->files };
505  
506 30 for my $i (0 .. $#files) {
507 65 ▶ next unless $file == $files[ $i ];
Branch: 1 branch
BranchTrueFalseTotal
unless $file == $files[$i] 35 30 65
508 30 splice @{ $self->files }, $i, 1;
509 30 return;
510 }
511  
512 0 return;
513 }
514  
515 #pod =attr root
516 #pod
517 #pod This is the root directory of the dist, as a L<Path::Tiny>. It will
518 #pod nearly always be the current working directory in which C<dzil> was run.
519 #pod
520 #pod =cut
521  
522 53 has root => (
523 is => 'ro',
524 isa => Path,
525 coerce => 1,
526 required => 1,
527 );
528  
529 #pod =attr is_trial
530 #pod
531 #pod This attribute tells us whether or not the dist will be a trial release,
532 #pod i.e. whether it has C<release_status> 'testing' or 'unstable'.
533 #pod
534 #pod Do not set this directly, it will be derived from C<release_status>.
535 #pod
536 #pod =cut
537  
538 53 has is_trial => (
539 is => 'ro',
540 isa => Bool,
541 init_arg => undef,
542 lazy => 1,
543 builder => '_build_is_trial',
544 );
545  
546 53 has _override_is_trial => (
547 is => 'ro',
548 isa => Bool,
549 init_arg => 'is_trial',
550 default => 0,
551 );
552  
553 57 ▶sub _build_is_trial {
Subroutine _build_is_trial: called CC=2 SCAR=6.9
554 57 my ($self) = @_;
555 57 ▶ return $self->release_status =~ /\A(?:testing|unstable)\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->release_status =~ /\A(?:testing|unstable)\z/u ? : 14 43 57
556 }
557  
558 #pod =attr plugins
559 #pod
560 #pod This is an arrayref of plugins that have been plugged into this Dist::Zilla
561 #pod object.
562 #pod
563 #pod Non-core code B<must not> alter this arrayref. Public access to this attribute
564 #pod B<may go away> in the future.
565 #pod
566 #pod =cut
567  
568 has plugins => (
569 is => 'ro',
570 isa => 'ArrayRef[Dist::Zilla::Role::Plugin]',
571 init_arg => undef,
572 199 ▶ default => sub { [ ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
573 53 );
574  
575 #pod =attr distmeta
576 #pod
577 #pod This is a hashref containing the metadata about this distribution that will be
578 #pod stored in META.yml or META.json. You should not alter the metadata in this
579 #pod hash; use a MetaProvider plugin instead.
580 #pod
581 #pod =cut
582  
583 53 has distmeta => (
584 is => 'ro',
585 isa => 'HashRef',
586 init_arg => undef,
587 lazy => 1,
588 builder => '_build_distmeta',
589 );
590  
591 153 ▶sub _build_distmeta {
Subroutine _build_distmeta: called CC=4 SCAR=13.9
592 153 my ($self) = @_;
593  
594 153 require CPAN::Meta::Merge;
595 153 my $meta_merge = CPAN::Meta::Merge->new(default_version => 2);
596 153 my $meta = {};
597  
598 153 for (@{ $self->plugins_with(-MetaProvider) }) {
599 13 $meta = $meta_merge->merge($meta, $_->metadata);
600 }
601  
602 153 ▶ my %meta_main = (
Condition50%1/2
$self->VERSION // "(undef)"
l!l
1520
MC/DC0%0/1
$self->VERSION // "(undef)"
$self->VERSION
Truth table50%1/2
A
A= $self->VERSION
Aresult
11
00
603 'meta-spec' => {
604 version => 2,
605 url => 'https://metacpan.org/pod/CPAN::Meta::Spec',
606 },
607 name => $self->name,
608 version => $self->version,
609 abstract => $self->abstract,
610 author => $self->authors,
611 license => [ $self->license->meta2_name ],
612  
613 release_status => $self->release_status,
614  
615 dynamic_config => 0, # problematic, I bet -- rjbs, 2010-06-04
616 generated_by => $self->_metadata_generator_id
617 . ' version '
618 . ($self->VERSION // '(undef)'),
619 x_generated_by_perl => "$^V", # v5.24.0
620 );
621 152 ▶ if (my $spdx = $self->license->spdx_expression) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spdx = $self->license->spdx_expression) 151 1 152
622 151 $meta_main{x_spdx_expression} = $spdx;
623 }
624  
625 152 $meta = $meta_merge->merge($meta, \%meta_main);
626  
627 152 return $meta;
628 }
629  
630 1 ▶sub _metadata_generator_id { 'Dist::Zilla' }
Subroutine _metadata_generator_id: called CC=1 SCAR=0.0
631  
632 #pod =attr prereqs
633 #pod
634 #pod This is a L<Dist::Zilla::Prereqs> object, which is a thin layer atop
635 #pod L<CPAN::Meta::Prereqs>, and describes the distribution's prerequisites.
636 #pod
637 #pod =method register_prereqs
638 #pod
639 #pod Allows registration of prerequisites; delegates to
640 #pod L<Dist::Zilla::Prereqs/register_prereqs> via our L</prereqs> attribute.
641 #pod
642 #pod =cut
643  
644 has prereqs => (
645 is => 'ro',
646 isa => 'Dist::Zilla::Prereqs',
647 init_arg => undef,
648 lazy => 1,
649 170 ▶ default => sub { Dist::Zilla::Prereqs->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
650 53 handles => [ qw(register_prereqs) ],
651 );
652  
653 #pod =method plugin_named
654 #pod
655 #pod my $plugin = $zilla->plugin_named( $plugin_name );
656 #pod
657 #pod =cut
658  
659 2143 ▶sub plugin_named {
Subroutine plugin_named: called CC=2 SCAR=6.9
Pod documented
660 2143 my ($self, $name) = @_;
661 2143 ▶ my $plugin = first { $_->plugin_name eq $name } @{ $self->plugins };
Subroutine __ANON__: called CC=1 SCAR=0.0
662  
663 2143 ▶ return $plugin if $plugin;
Branch: 1 branch
BranchTrueFalseTotal
if $plugin 271 1872 2143
664 1872 return;
665 }
666  
667 #pod =method plugins_with
668 #pod
669 #pod my $roles = $zilla->plugins_with( -SomeRole );
670 #pod
671 #pod This method returns an arrayref containing all the Dist::Zilla object's plugins
672 #pod that perform the named role. If the given role name begins with a dash, the
673 #pod dash is replaced with "Dist::Zilla::Role::"
674 #pod
675 #pod =cut
676  
677 2205 ▶sub plugins_with {
Subroutine plugins_with: called CC=1 SCAR=0.0
Pod documented
678 2205 my ($self, $role) = @_;
679  
680 2205 $role =~ s/^-/Dist::Zilla::Role::/;
681 2205 my $plugins = [ grep { $_->does($role) } @{ $self->plugins } ];
682  
683 2205 return $plugins;
684 }
685  
686 #pod =method find_files
687 #pod
688 #pod my $files = $zilla->find_files( $finder_name );
689 #pod
690 #pod This method will look for a
691 #pod L<FileFinder|Dist::Zilla::Role::FileFinder>-performing plugin with the given
692 #pod name and return the result of calling C<find_files> on it. If no plugin can be
693 #pod found, an exception will be raised.
694 #pod
695 #pod =cut
696  
697 239 ▶sub find_files {
Subroutine find_files: called CC=3 SCAR=11.4
Pod documented
698 239 my ($self, $finder_name) = @_;
699  
700 239 ▶ $self->log_fatal("no plugin named $finder_name found")
Branch: 1 branch
BranchTrueFalseTotal
unless my $plugin = $self->plugin_named($finder_name) 0 239 239
701 unless my $plugin = $self->plugin_named($finder_name);
702  
703 239 ▶ $self->log_fatal("plugin $finder_name is not a FileFinder")
Branch: 1 branch
BranchTrueFalseTotal
unless $plugin->does("Dist::Zilla::Role::FileFinder") 0 239 239
704 unless $plugin->does('Dist::Zilla::Role::FileFinder');
705  
706 239 $plugin->find_files;
707 }
708  
709 151 ▶sub _check_dupe_files {
Subroutine _check_dupe_files: called CC=6 SCAR=25.3
710 151 my ($self) = @_;
711  
712 151 my %files_named;
713 my @dupes;
714 151 for my $file (@{ $self->files }) {
715 659 my $filename = $file->name;
716 659 ▶ if (my $seen = $files_named{ $filename }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $seen = $files_named{$filename}) { } 0 659 659
717 0 push @{ $seen }, $file;
718 0 ▶ push @dupes, $filename if @{ $seen } == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @{$seen;} == 2 0 0 0
719 } else {
720 659 $files_named{ $filename } = [ $file ];
721 }
722 }
723  
724 151 ▶ return unless @dupes;
Branch: 1 branch
BranchTrueFalseTotal
unless @dupes 151 0 151
725  
726 0 for my $name (@dupes) {
727 $self->log("attempt to add $name multiple times; added by: "
728 0 . join('; ', map { $_->added_by } @{ $files_named{ $name } })
729 );
730 }
731  
732 0 Carp::croak("aborting; duplicate files would be produced");
733 }
734  
735 660 ▶sub _write_out_file {
Subroutine _write_out_file: called CC=5 SCAR=16.4
736 660 my ($self, $file, $build_root) = @_;
737  
738 # Okay, this is a bit much, until we have ->debug. -- rjbs, 2008-06-13
739 # $self->log("writing out " . $file->name);
740  
741 660 my $file_path = path($file->name);
742  
743 660 my $to_dir = path($build_root)->child( $file_path->parent );
744 660 my $to = $to_dir->child( $file_path->basename );
745 660 ▶ $to_dir->mkpath unless -e $to_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $to_dir 467 193 660
746 660 ▶ die "not a directory: $to_dir" unless -d $to_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $to_dir 0 660 660
747  
748 660 ▶ Carp::croak("attempted to write $to multiple times") if -e $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to 0 660 660
749  
750 660 path("$to")->spew_raw( $file->encoded_content );
751 660 ▶ chmod $file->mode, "$to" or die "couldn't chmod $to: $!";
Branch: 1 branch
BranchTrueFalseTotal
chmod $file->mode, "$to" or die "couldn't chmod ${to}: $!" 660 0 660
752 }
753  
754 #pod =attr logger
755 #pod
756 #pod This attribute stores a L<Log::Dispatchouli::Proxy> object, used to log
757 #pod messages. By default, a proxy to the dist's L<Chrome|Dist::Zilla::Role::Chrome> is
758 #pod taken.
759 #pod
760 #pod The following methods are delegated from the Dist::Zilla object to the logger:
761 #pod
762 #pod =for :list
763 #pod * log
764 #pod * log_debug
765 #pod * log_fatal
766 #pod
767 #pod =cut
768  
769 has logger => (
770 is => 'ro',
771 isa => 'Log::Dispatchouli::Proxy', # could be duck typed, I guess
772 lazy => 1,
773 handles => [ qw(log log_debug log_fatal) ],
774 175 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
775 175 $_[0]->chrome->logger->proxy({ proxy_prefix => '[DZ] ' })
776 },
777 53 );
778  
779 3 ▶around dump_config => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
780 3 my ($orig, $self) = @_;
781 3 my $config = $self->$orig;
782 3 $config->{is_trial} = $self->is_trial;
783 3 return $config;
784 53 };
785  
786 has _local_stashes => (
787 is => 'ro',
788 isa => HashRef[ Object ],
789 lazy => 1,
790 157 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
791 53 );
792  
793 has _global_stashes => (
794 is => 'ro',
795 isa => HashRef[ Object ],
796 lazy => 1,
797 153 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
798 53 );
799  
800 #pod =method stash_named
801 #pod
802 #pod my $stash = $zilla->stash_named( $name );
803 #pod
804 #pod This method will return the stash with the given name, or undef if none exists.
805 #pod It looks for a local stash (for this dist) first, then falls back to a global
806 #pod stash (from the user's global configuration).
807 #pod
808 #pod =cut
809  
810 167 ▶sub stash_named {
Subroutine stash_named: called CC=2 SCAR=6.9
Pod documented
811 167 my ($self, $name) = @_;
812  
813 167 ▶ return $self->_local_stashes->{ $name } if $self->_local_stashes->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_local_stashes->{$name} 4 163 167
814 163 return $self->_global_stashes->{ $name };
815 }
816  
817 53 __PACKAGE__->meta->make_immutable;
818 53 1;
819  
820 #pod =head1 STABILITY PROMISE
821 #pod
822 #pod None.
823 #pod
824 #pod I will try not to break things within any major release. Minor releases are
825 #pod not extensively tested before release. In major releases, anything goes,
826 #pod although I will try to publish a complete list of known breaking changes in any
827 #pod major release.
828 #pod
829 #pod If Dist::Zilla was a tool, it would have yellow and black stripes and there
830 #pod would be no L<UL
831 #pod certification|https://en.wikipedia.org/wiki/UL_(safety_organization)> on it.
832 #pod It is nasty, brutish, and large.
833 #pod
834 #pod =head1 SUPPORT
835 #pod
836 #pod There are usually people on C<irc.perl.org> in C<#distzilla>, even if they're
837 #pod idling.
838 #pod
839 #pod The L<Dist::Zilla website|https://dzil.org/> has several valuable resources for
840 #pod learning to use Dist::Zilla.
841 #pod
842 #pod =head1 SEE ALSO
843 #pod
844 #pod =over 4
845 #pod
846 #pod =item *
847 #pod
848 #pod In the Dist::Zilla distribution:
849 #pod
850 #pod =over 4
851 #pod
852 #pod =item *
853 #pod
854 #pod Plugin bundles:
855 #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
856 #pod L<@Filter|Dist::Zilla::PluginBundle::Filter>.
857 #pod
858 #pod =item *
859 #pod
860 #pod Major plugins:
861 #pod L<GatherDir|Dist::Zilla::Plugin::GatherDir>,
862 #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs>,
863 #pod L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>,
864 #pod L<MetaYAML|Dist::Zilla::Plugin::MetaYAML>,
865 #pod L<MetaJSON|Dist::Zilla::Plugin::MetaJSON>,
866 #pod ...
867 #pod
868 #pod =back
869 #pod
870 #pod =item *
871 #pod
872 #pod On the CPAN:
873 #pod
874 #pod =over 4
875 #pod
876 #pod =item *
877 #pod
878 #pod Search for plugins: L<https://metacpan.org/search?q=Dist::Zilla::Plugin::>
879 #pod
880 #pod =item *
881 #pod
882 #pod Search for plugin bundles: L<https://metacpan.org/search?q=Dist::Zilla::PluginBundle::>
883 #pod
884 #pod =back
885 #pod
886 #pod =back
887  
888 __END__
« blib/lib/Dist/Zilla/Plugin/MetaResources.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/GatherDir/Template.pm »