blib/lib/Dist/Zilla/App/Command/listdeps.pm

filter: Statementstmt 67.5% 52 / 77 Branchbran 50.0% 15 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 50.0% 3 / 6 totaltotal 62.8% 76 / 121 CC 29 SCAR 33.5
CC
29
Cov
63%
filter_core
90.0
execute
11.4
extract_dependencies
7.8
CRAP 28.4
« blib/lib/Dist/Zilla/App/Command/new.pm ↑ Summary blib/lib/Dist/Zilla/Util/AuthorDeps.pm »
1 package Dist::Zilla::App::Command::listdeps 6.040;
2 # ABSTRACT: print your distribution's prerequisites
3  
4 4 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Dist::Zilla::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod $ dzil listdeps | cpan
11 #pod
12 #pod =head1 DESCRIPTION
13 #pod
14 #pod This is a command plugin for L<Dist::Zilla>. It provides the C<listdeps>
15 #pod command, which prints your distribution's prerequisites. You could pipe that
16 #pod list to a CPAN client like L<cpan> to install all of the dependencies in one
17 #pod quick go.
18 #pod
19 #pod =head1 OPTIONS
20 #pod
21 #pod =head2 --author (or --develop)
22 #pod
23 #pod Include author dependencies (those listed under C<develop_requires>).
24 #pod
25 #pod =head2 --missing
26 #pod
27 #pod List only dependencies which are unsatisfied.
28 #pod
29 #pod =head2 --requires / --no-requires
30 #pod
31 #pod Add required dependencies to the list (or don't).
32 #pod
33 #pod Default: on.
34 #pod
35 #pod =head2 --recommends / --no-recommends
36 #pod
37 #pod Add recommended dependencies to the list (or don't).
38 #pod
39 #pod Default: on.
40 #pod
41 #pod =head2 --suggests / --no-suggests
42 #pod
43 #pod Add suggested dependencies to the list (or don't).
44 #pod
45 #pod Default: off.
46 #pod
47 #pod =head2 --versions
48 #pod
49 #pod Also display the required versions of listed modules.
50 #pod
51 #pod =head2 --cpanm-versions
52 #pod
53 #pod Also display the required versions of listed modules, but in a format suitable
54 #pod for piping into F<cpanm>.
55 #pod
56 #pod =head2 --json
57 #pod
58 #pod Lists all prerequisites in JSON format, as they would appear in META.json
59 #pod (broken out into phases and types)
60 #pod
61 #pod =head1 ACKNOWLEDGEMENTS
62 #pod
63 #pod This code was originally more or less a direct copy of Marcel Gruenauer (hanekomu)
64 #pod Dist::Zilla::App::Command::prereqs, updated to work with the Dist::Zilla v2
65 #pod API.
66 #pod
67 #pod =cut
68  
69 0 ▶sub abstract { "print your distribution's prerequisites" }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
70  
71 18 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
72 18 [ 'develop|author', 'include author/develop dependencies' ],
73 [ 'missing', 'list only the missing dependencies' ],
74 [ 'requires!', 'list the required dependencies', { default => 1 } ],
75 [ 'recommends!', 'list the recommended dependencies', { default => 1 } ],
76 [ 'suggests!', 'list the suggested dependencies', {default => 0 } ],
77 [ 'versions', 'include required version numbers in listing' ],
78 [ 'cpanm-versions', 'format versions for consumption by cpanm' ],
79 [ 'json', 'list dependencies by phase, in JSON format' ],
80 [ 'omit-core=s', 'Omit dependencies that are shipped with the specified version of perl' ],
81 }
82  
83 18 ▶sub prereqs {
Subroutine prereqs: called CC=7 SCAR=19.5
Pod undocumented
84 18 my ($self, $zilla) = @_;
85  
86 18 $_->before_build for @{ $zilla->plugins_with(-BeforeBuild) };
87 18 $_->gather_files for @{ $zilla->plugins_with(-FileGatherer) };
88 18 $_->set_file_encodings for @{ $zilla->plugins_with(-EncodingProvider) };
89 18 $_->prune_files for @{ $zilla->plugins_with(-FilePruner) };
90 18 $_->munge_files for @{ $zilla->plugins_with(-FileMunger) };
91 18 $_->register_prereqs for @{ $zilla->plugins_with(-PrereqSource) };
92  
93 18 my $prereqs = $zilla->prereqs;
94 }
95  
96 4 my @phases = qw/configure build test runtime develop/;
97 4 my @relationships = qw/requires recommends suggests/;
98  
99 0 ▶sub filter_core {
Subroutine filter_core: not called CC=9 SCAR=45.0
Pod undocumented
100 0 my ($prereqs, $core_version) = @_;
101 0 ▶ $core_version = sprintf '%7.6f', $core_version if $core_version >= 5.010;
Branch: 1 branch
BranchTrueFalseTotal
if $core_version >= "5.01" 0 0 0
102 0 ▶ $prereqs = $prereqs->clone if $prereqs->is_finalized;
Branch: 1 branch
BranchTrueFalseTotal
if $prereqs->is_finalized 0 0 0
103 0 require Module::CoreList;
104 0 for my $phase (@phases) {
105 0 for my $relation (@relationships) {
106 0 my $req = $prereqs->requirements_for($phase, $relation);
107 0 ▶ $req->clear_requirement('perl') if $req->accepts_module('perl', $core_version);
Branch: 1 branch
BranchTrueFalseTotal
if $req->accepts_module("perl", $core_version) 0 0 0
108 0 for my $module ($req->required_modules) {
109 0 ▶ next if not exists $Module::CoreList::version{$core_version}{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::CoreList::version{$core_version}{$module} 0 0 0
110 0 ▶ $req->clear_requirement($module) if $req->accepts_module($module, $Module::CoreList::version{$core_version}{$module});
Branch: 1 branch
BranchTrueFalseTotal
if $req->accepts_module($module, $Module::CoreList::version{$core_version}{$module}) 0 0 0
111 }
112 }
113 }
114 0 return $prereqs;
115 }
116  
117 18 ▶sub extract_dependencies {
Subroutine extract_dependencies: called CC=7 SCAR=20.6
Pod undocumented
118 18 my ($self, $zilla, $phases, $opt) = @_;
119  
120 18 my $prereqs = $self->prereqs($zilla);
121 18 ▶ $prereqs = filter_core($prereqs, $opt->omit_core) if $opt->omit_core;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->omit_core 0 18 18
122  
123 18 require CPAN::Meta::Requirements;
124 18 my $req = CPAN::Meta::Requirements->new;
125  
126 18 for my $phase (@$phases) {
127 78 ▶ $req->add_requirements( $prereqs->requirements_for($phase, 'requires') ) if $opt->requires;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->requires 66 12 78
128 78 ▶ $req->add_requirements( $prereqs->requirements_for($phase, 'recommends') ) if $opt->recommends;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->recommends 66 12 78
129 78 ▶ $req->add_requirements( $prereqs->requirements_for($phase, 'suggests') ) if $opt->suggests;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->suggests 12 66 78
130 }
131  
132 18 my @required = grep { $_ ne 'perl' } $req->required_modules;
133 18 ▶ if ($opt->missing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->missing) 0 18 18
134 0 require Module::Runtime;
135 @required =
136 grep {
137 # Keep modules that can't be loaded or that don't have a $VERSION
138 # matching our requirements
139 0 ! eval {
140 0 my $m = $_;
141 # Will die if module is not installed
142 0 Module::Runtime::require_module($m);
143 # Returns true if $VERSION matches, so we will exclude the module
144 0 $req->accepts_module($m => $m->VERSION)
145 }
146 } @required;
147 }
148  
149 18 my $versions = $req->as_string_hash;
150 18 return map { $_ => $versions->{$_} } @required;
151 }
152  
153 18 ▶sub execute {
Subroutine execute: called CC=9 SCAR=24.4
Pod documented
154 18 my ($self, $opt, $arg) = @_;
155  
156 18 $self->app->chrome->logger->mute;
157  
158 18 my @phases = qw(build test configure runtime);
159 18 ▶ push @phases, 'develop' if $opt->develop;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->develop 6 12 18
160  
161 18 my $omit_core = $opt->omit_core;
162 18 ▶ if($opt->json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->json) 0 18 18
163 0 my $prereqs = $self->prereqs($self->zilla);
164 0 ▶ $prereqs = filter_core($prereqs, $omit_core) if $omit_core;
Branch: 1 branch
BranchTrueFalseTotal
if $omit_core 0 0 0
165 0 my $output = $prereqs->as_string_hash;
166  
167 0 require JSON::MaybeXS;
168 0 print JSON::MaybeXS->new(ascii => 1, canonical => 1, pretty => 1)->encode($output), "\n";
169 0 return 1;
170 }
171  
172 18 my %modules = $self->extract_dependencies($self->zilla, \@phases, $opt);
173  
174 18 my @names = sort { lc $a cmp lc $b } keys %modules;
175 18 ▶ if ($opt->versions) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->versions) { } 6 12 18
elsif ($opt->cpanm_versions) { } 6 6 12
176 6 print "$_ = $modules{$_}\n" for @names;
177 } elsif ($opt->cpanm_versions) {
178 6 print "$_~$modules{$_}\n" for @names;
179 } else {
180 6 print "$_\n" for @names;
181 }
182 }
183  
184 4 1;
185  
186 __END__
« blib/lib/Dist/Zilla/App/Command/new.pm ↑ Summary blib/lib/Dist/Zilla/Util/AuthorDeps.pm »