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