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.030;
2             # ABSTRACT: Dist::Zilla's App::Cmd
3              
4 4     4   2347 use Dist::Zilla::Pragmas;
  4         9  
  4         27  
5              
6 4     4   1964 use App::Cmd::Setup 0.330 -app; # better compilation error detection
  4         105852  
  4         33  
7              
8 4     4   805 use Carp ();
  4         16  
  4         78  
9 4     4   18 use Try::Tiny;
  4         23  
  4         218  
10              
11 4     4   980 use namespace::autoclean;
  4         24171  
  4         30  
12              
13             $Carp::Internal{'Module::Runtime'} = 1;
14              
15             sub global_opt_spec {
16 20     20 1 64719 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         345 } ],
24             $self->SUPER::global_opt_spec,
25             );
26             }
27              
28             sub _build_global_stashes {
29 21     21   90 my ($self) = @_;
30              
31 21 50       96 return $self->{__global_stashes__} if $self->{__global_stashes__};
32              
33             # tests shouldn't depend on the user's configuration
34 21 50       317 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 260 my ($self) = @_;
105 59         2044 require Dist::Zilla::Chrome::Term;
106              
107 59 100       886 return $self->{__chrome__} if $self->{__chrome__};
108              
109 20         965 $self->{__chrome__} = Dist::Zilla::Chrome::Term->new;
110              
111             my @v_plugins = $self->global_options->verbose_plugin
112 20 50       145 ? grep { length } @{ $self->global_options->verbose_plugin }
  0         0  
  0         0  
113             : ();
114              
115 20         315 my $verbose = $self->global_options->verbose;
116              
117 20 50       822 $self->{__chrome__}->logger->set_debug($verbose ? 1 : 0);
118              
119 20         687 return $self->{__chrome__};
120             }
121              
122             sub zilla {
123 23     23 1 201 my ($self) = @_;
124              
125 23         1301 require Dist::Zilla::Dist::Builder;
126              
127 23   66     362 return $self->{'' . __PACKAGE__}{zilla} ||= do {
128             my @v_plugins = $self->global_options->verbose_plugin
129 20 50       114 ? grep { length } @{ $self->global_options->verbose_plugin }
  0         0  
  0         0  
130             : ();
131              
132 20         297 my $verbose = $self->global_options->verbose;
133              
134 20 50       211 $self->chrome->logger->set_debug($verbose ? 1 : 0);
135              
136 20         179 my $core_debug = grep { m/\A[-_]\z/ } @v_plugins;
  0         0  
137              
138 20         57 my $zilla;
139             try {
140 20     20   1469 $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         287 };
149              
150 20 50       1058 $zilla->logger->set_debug($verbose ? 1 : 0);
151              
152 20         161 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         269 $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.030
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 released
186             in the last two to three years. (That is, if the most recently released
187             version is v5.40, then this module should work on both v5.40 and v5.38.)
188              
189             Although it may work on older versions of perl, no guarantee is made that the
190             minimum required version will not be increased. The version may be increased
191             for any reason, and there is no promise that patches will be accepted to lower
192             the minimum required perl.
193              
194             =head1 METHODS
195              
196             =head2 zilla
197              
198             This returns the Dist::Zilla object in use by the command. If none has yet
199             been constructed, one will be by calling C<< Dist::Zilla->from_config >>.
200              
201             =head1 AUTHOR
202              
203             Ricardo SIGNES 😏 <cpan@semiotic.systems>
204              
205             =head1 COPYRIGHT AND LICENSE
206              
207             This software is copyright (c) 2023 by Ricardo SIGNES.
208              
209             This is free software; you can redistribute it and/or modify it under
210             the same terms as the Perl 5 programming language system itself.
211              
212             =cut