File Coverage

lib/Dist/Zilla/Plugin/Prereqs/MatchInstalled/All.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


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