File Coverage

blib/lib/Dist/Zilla/Plugin/Prereqs/MatchInstalled/All.pm
Criterion Covered Total %
statement 32 36 88.8
branch 2 4 50.0
condition 1 3 33.3
subroutine 11 11 100.0
pod n/a
total 46 54 85.1


line stmt bran cond sub pod time code
1 2     2   2081690 use 5.008; # 08 => utf, 06 => pragmas, our, 04 => arrow coderef, __PACKAGE__
  2         6  
2 2     2   8 use strict;
  2         3  
  2         40  
3 2     2   14 use warnings;
  2         2  
  2         60  
4 2     2   517 use utf8;
  2         11  
  2         12  
5              
6             package Dist::Zilla::Plugin::Prereqs::MatchInstalled::All;
7              
8             our $VERSION = '1.001001';
9              
10             # ABSTRACT: Upgrade ALL your dependencies to the ones you have installed.
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14 2     2   549 use Moose qw( has around extends );
  2         297207  
  2         14  
15 2     2   9782 use Dist::Zilla::Plugin::Prereqs::MatchInstalled 1.000000;
  2         346690  
  2         111  
16 2     2   16 use MooseX::Types::Moose qw( ArrayRef HashRef Str Bool );
  2         5  
  2         22  
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30             extends 'Dist::Zilla::Plugin::Prereqs::MatchInstalled';
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44             has exclude => (
45             is => ro =>,
46             isa => ArrayRef [Str],
47             lazy => 1,
48             default => sub { [] },
49             );
50              
51              
52              
53              
54              
55             has _exclude_hash => (
56             is => ro =>,
57             isa => HashRef [Str],
58             lazy => 1,
59             builder => '_build__exclude_hash',
60             );
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77             has upgrade_perl => (
78             is => ro =>,
79             isa => Bool,
80             lazy => 1,
81             default => sub { undef },
82             );
83              
84             around mvp_multivalue_args => sub {
85             my ( $orig, $self, @args ) = @_;
86             return ( 'exclude', $orig->( $self, @args ) );
87             };
88              
89             around dump_config => sub {
90             my ( $orig, $self, @args ) = @_;
91             my $config = $self->$orig(@args);
92             my $localconf = $config->{ +__PACKAGE__ } = {};
93              
94             $localconf->{exclude} = $self->exclude;
95             $localconf->{upgrade_perl} = $self->upgrade_perl;
96              
97             $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
98             unless __PACKAGE__ eq ref $self;
99              
100             return $config;
101             };
102              
103              
104              
105              
106              
107             sub _build__exclude_hash {
108 1     1   2 my ($self) = @_;
109 1         2 return { map { ( $_, 1 ) } @{ $self->exclude } };
  0         0  
  1         33  
110             }
111              
112              
113              
114              
115              
116             sub _user_wants_excluded {
117 1     1   2 my ( $self, $module ) = @_;
118 1         43 return exists $self->_exclude_hash->{$module};
119             }
120              
121              
122              
123              
124              
125             my $u_upgrade = q[perl is a dependency, but we won't automatically ];
126             $u_upgrade .= q[upgrade that without upgrade_perl = 1];
127              
128             sub _user_wants_upgrade_on {
129 1     1   70754 my ( $self, $module ) = @_;
130 1 50 33     7 if ( 'perl' eq $module and not $self->upgrade_perl ) {
131 0         0 $self->log_debug($u_upgrade);
132 0         0 return;
133             }
134 1 50       4 if ( $self->_user_wants_excluded($module) ) {
135 0         0 return;
136             }
137 1         2 return 1;
138             }
139              
140             __PACKAGE__->meta->make_immutable;
141 2     2   7790 no Moose;
  2         3  
  2         18  
142              
143             1;
144              
145             __END__
146              
147             =pod
148              
149             =encoding UTF-8
150              
151             =head1 NAME
152              
153             Dist::Zilla::Plugin::Prereqs::MatchInstalled::All - Upgrade ALL your dependencies to the ones you have installed.
154              
155             =head1 VERSION
156              
157             version 1.001001
158              
159             =head1 SYNOPSIS
160              
161             [Prereqs::MatchInstalled::All]
162             ; upgrade_perl = 1 ; if you want to upgrade to your installed perl
163             ; include these too if you don't want to force a perl upgrade indirectly.
164             exclude = strict
165             exclude = warnings
166              
167             =head1 DESCRIPTION
168              
169             This is a special case of
170             L<<< C<< Dist::Zilla::Plugin::B<Prereqs::MatchInstalled> >>|Dist::Zilla::Plugin::Prereqs::MatchInstalled >>> that
171             automatically upgrades all versions of all dependencies, unless asked not to.
172              
173             =head2 PITFALLS
174              
175             Presently, there is one very large gotcha about using this module, in that it will upgrade everything,
176             even things that don't make sense to upgrade.
177              
178             For instance:
179              
180             =head3 Local Versions
181              
182             If you have a single dependency on your system you might use, which is locally patched, and locally patched in such a way the
183             local version is more recent than any on C<CPAN>, you should either
184              
185             =over 4
186              
187             =item a. Not use this module
188              
189             =item b. Put that module in the exclusion list
190              
191             =back
192              
193             =head3 Non-Dual Life modules
194              
195             This plugin is not very smart, and can't differentiate between modules that do exist on C<CPAN> independent of Perl, and
196             modules that don't.
197              
198             For instance, if you use C<Autoprereqs>, its very likely your distribution will add a dependency on either C<strict> or
199             C<warnings>
200              
201             This module will ask your user to upgrade those versions to their latest versions, which will likely require them to upgrade
202             their Perl installation to do so.
203              
204             Which basically means for the mean time, either
205              
206             =over 4
207              
208             =item a. You must be o.k. with end users needing more recent Perls
209              
210             =item b. You should avoid upgrading those dependencies by either
211              
212             =over 4
213              
214             =item a. Not using this plugin
215              
216             =item b. Adding problematic modules to the exclusion list
217              
218             =back
219              
220             =back
221              
222             =head1 ATTRIBUTES
223              
224             =head2 C<exclude>
225              
226             This parameter can be specified multiple times, and each
227             time should represent a single package string to exclude from
228             version upgrades.
229              
230             [Prereqs::MatchInstalled::All]
231             exclude = foo
232             exclude = bar
233              
234             =head2 C<upgrade_perl>
235              
236             If specified, this will permit upgrades on the dependency on C<perl> to the installed version.
237              
238             [Prereqs::MatchInstalled::All]
239             upgrade_perl = 1
240              
241             Note, this has no effect on the modules that may inherently be only available by upgrading Perl.
242              
243             Default is false.
244              
245             See L</PITFALLS> for details.
246              
247             =head1 PRIVATE ATTRIBUTES
248              
249             =head2 C<_exclude_hash>
250              
251             =head1 PRIVATE METHODS
252              
253             =head2 C<_build__exclude_hash>
254              
255             =head2 C<_user_wants_excluded>
256              
257             =head2 C<_user_wants_upgrade_on>
258              
259             =begin MetaPOD::JSON v1.1.0
260              
261             {
262             "namespace":"Dist::Zilla::Plugin::Prereqs::MatchInstalled::All",
263             "inherits":"Dist::Zilla::Plugin::Prereqs::MatchInstalled",
264             "interface":"class"
265             }
266              
267              
268             =end MetaPOD::JSON
269              
270             =head1 AUTHOR
271              
272             Kent Fredric <kentnl@cpan.org>
273              
274             =head1 COPYRIGHT AND LICENSE
275              
276             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
277              
278             This is free software; you can redistribute it and/or modify it under
279             the same terms as the Perl 5 programming language system itself.
280              
281             =cut