File Coverage

blib/lib/Dist/Zilla/App.pm
Criterion Covered Total %
statement 41 77 53.2
branch 9 26 34.6
condition 2 6 33.3
subroutine 10 14 71.4
pod 2 3 66.6
total 64 126 50.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::App 6.037;
2             # ABSTRACT: Dist::Zilla's App::Cmd
3              
4 4     4   1085 use Dist::Zilla::Pragmas;
  4         12  
  4         27  
5              
6 4     4   1723 use App::Cmd::Setup 0.330 -app; # better compilation error detection
  4         95496  
  4         18  
7              
8 4     4   639 use Carp ();
  4         6  
  4         66  
9 4     4   13 use Try::Tiny;
  4         5  
  4         237  
10              
11 4     4   979 use namespace::autoclean;
  4         25541  
  4         22  
12              
13             $Carp::Internal{'Module::Runtime'} = 1;
14              
15             sub global_opt_spec {
16 20     20 1 62471 my ($self) = @_;
17              
18             return (
19             [ "verbose|v", "log additional output" ],
20             [ "verbose-plugin|V=s@", "log additional output from some plugins only" ],
21             [ "lib-inc|I=s@", "additional \@INC dirs", {
22 0     0   0 callbacks => { 'always fine' => sub { unshift @INC, @{$_[0]}; } }
  0         0  
23 20         381 } ],
24             $self->SUPER::global_opt_spec,
25             );
26             }
27              
28             sub _build_global_stashes {
29 21     21   52 my ($self) = @_;
30              
31 21 50       95 return $self->{__global_stashes__} if $self->{__global_stashes__};
32              
33             # tests shouldn't depend on the user's configuration
34 21 50       333 return {} if $ENV{DZIL_TESTING};
35              
36 0         0 my $stash_registry = $self->{__global_stashes__} = {};
37              
38 0         0 require Dist::Zilla::Util;
39 0         0 my $config_dir = Dist::Zilla::Util->_global_config_root;
40              
41 0         0 my $config_base = $config_dir->child('config');
42              
43 0         0 require Dist::Zilla::MVP::Reader::Finder;
44 0         0 require Dist::Zilla::MVP::Assembler::GlobalConfig;
45 0         0 require Dist::Zilla::MVP::Section;
46 0         0 my $assembler = Dist::Zilla::MVP::Assembler::GlobalConfig->new({
47             chrome => $self->chrome,
48             stash_registry => $stash_registry,
49             section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
50             });
51              
52             try {
53             my $reader = Dist::Zilla::MVP::Reader::Finder->new({
54             if_none => sub {
55             # warn <<'END_WARN';
56             # WARNING: No global configuration file was found in ~/.dzil -- this limits the
57             # ability of Dist::Zilla to perform some tasks. You can run "dzil setup" to
58             # create a simple first-pass configuration file, or you can touch the file
59             # ~/.dzil/config.ini to suppress this message in the future.
60             # END_WARN
61             return $_[2]->{assembler}->sequence
62 0         0 },
63 0     0   0 });
64              
65 0         0 my $seq = $reader->read_config($config_base, { assembler => $assembler });
66             } catch {
67 0     0   0 my $e = $_;
68 0 0       0 if (eval { $e->isa('Config::MVP::Error') and $e->ident eq 'package not installed' }) {
  0 0       0  
69 0         0 my $package = $e->package;
70              
71 0 0       0 my $bundle = $package =~ /^@/ ? ' bundle' : '';
72 0         0 die <<"END_DIE";
73             Required plugin$bundle $package isn't installed. Remedy with:
74              
75             cpanm $package
76              
77             END_DIE
78             }
79             else {
80 0         0 die <<'END_DIE';
81              
82             Your global configuration file couldn't be loaded. It's a file matching
83             ~/.dzil/config.*
84              
85             You can try deleting the file or you might need to upgrade from pre-version 4
86             format. In most cases, this will just mean replacing [!release] with [%PAUSE]
87             and deleting any [!new] stanza. You can also delete the existing file and run
88             "dzil setup"
89             END_DIE
90             }
91 0         0 };
92              
93 0         0 return $stash_registry;
94             }
95              
96             #pod =method zilla
97             #pod
98             #pod This returns the Dist::Zilla object in use by the command. If none has yet
99             #pod been constructed, one will be by calling C<< Dist::Zilla->from_config >>.
100             #pod
101             #pod =cut
102              
103             sub chrome {
104 59     59 0 246 my ($self) = @_;
105 59         2089 require Dist::Zilla::Chrome::Term;
106              
107 59 100       1155 return $self->{__chrome__} if $self->{__chrome__};
108              
109 20         1157 $self->{__chrome__} = Dist::Zilla::Chrome::Term->new;
110              
111             my @v_plugins = $self->global_options->verbose_plugin
112 20 50       143 ? grep { length } @{ $self->global_options->verbose_plugin }
  0         0  
  0         0  
113             : ();
114              
115 20         275 my $verbose = $self->global_options->verbose;
116              
117 20 50       934 $self->{__chrome__}->logger->set_debug($verbose ? 1 : 0);
118              
119 20         898 return $self->{__chrome__};
120             }
121              
122             sub zilla {
123 23     23 1 173 my ($self) = @_;
124              
125 23         1139 require Dist::Zilla::Dist::Builder;
126              
127 23   66     317 return $self->{'' . __PACKAGE__}{zilla} ||= do {
128             my @v_plugins = $self->global_options->verbose_plugin
129 20 50       153 ? grep { length } @{ $self->global_options->verbose_plugin }
  0         0  
  0         0  
130             : ();
131              
132 20         256 my $verbose = $self->global_options->verbose;
133              
134 20 50       168 $self->chrome->logger->set_debug($verbose ? 1 : 0);
135              
136 20         225 my $core_debug = grep { m/\A[-_]\z/ } @v_plugins;
  0         0  
137              
138 20         36 my $zilla;
139             try {
140 20     20   1310 $zilla = Dist::Zilla::Dist::Builder->from_config({
141             chrome => $self->chrome,
142             _global_stashes => $self->_build_global_stashes,
143             });
144             } catch {
145 0         0 die $_ unless try { $_->isa('Config::MVP::Error') }
146 0 0 0 0   0 && $_->ident =~ /no viable config/;
147 0         0 $self->chrome->logger->log_fatal("no configuration (e.g, dist.ini) found");
148 20         253 };
149              
150 20 50       1409 $zilla->logger->set_debug($verbose ? 1 : 0);
151              
152 20         250 VERBOSE_PLUGIN: for my $plugin_name (grep { ! m{\A[-_]\z} } @v_plugins) {
  0         0  
153 0         0 my @plugins = grep { $_->plugin_name =~ /\b\Q$plugin_name\E\b/ }
154 0         0 @{ $zilla->plugins };
  0         0  
155              
156 0 0       0 $zilla->log_fatal("can't find plugins matching $plugin_name to set debug")
157             unless @plugins;
158              
159 0         0 $_->logger->set_debug(1) for @plugins;
160             }
161              
162 20         298 $zilla;
163             }
164             }
165              
166             1;
167              
168             __END__
169              
170             =pod
171              
172             =encoding UTF-8
173              
174             =head1 NAME
175              
176             Dist::Zilla::App - Dist::Zilla's App::Cmd
177              
178             =head1 VERSION
179              
180             version 6.037
181              
182             =head1 PERL VERSION
183              
184             This module should work on any version of perl still receiving updates from
185             the Perl 5 Porters. This means it should work on any version of perl
186             released in the last two to three years. (That is, if the most recently
187             released version is v5.40, then this module should work on both v5.40 and
188             v5.38.)
189              
190             Although it may work on older versions of perl, no guarantee is made that the
191             minimum required version will not be increased. The version may be increased
192             for any reason, and there is no promise that patches will be accepted to
193             lower the minimum required perl.
194              
195             =head1 METHODS
196              
197             =head2 zilla
198              
199             This returns the Dist::Zilla object in use by the command. If none has yet
200             been constructed, one will be by calling C<< Dist::Zilla->from_config >>.
201              
202             =head1 AUTHOR
203              
204             Ricardo SIGNES 😏 <cpan@semiotic.systems>
205              
206             =head1 COPYRIGHT AND LICENSE
207              
208             This software is copyright (c) 2026 by Ricardo SIGNES.
209              
210             This is free software; you can redistribute it and/or modify it under
211             the same terms as the Perl 5 programming language system itself.
212              
213             =cut