File Coverage

blib/lib/Dist/Zilla/Plugin/Breaks.pm
Criterion Covered Total %
statement 26 26 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 35 38 92.1


line stmt bran cond sub pod time code
1 2     2   3568084 use strict;
  2         2  
  2         55  
2 2     2   6 use warnings;
  2         3  
  2         91  
3             package Dist::Zilla::Plugin::Breaks; # git description: v0.003-23-gd774732
4             # ABSTRACT: Add metadata about potential breakages caused by your distribution
5             # KEYWORDS: distribution metadata prerequisites upstream dependencies modules conflicts breaks breakages
6             # vim: set ts=8 sts=4 sw=4 tw=115 et :
7              
8             our $VERSION = '0.004';
9              
10 2     2   6 use Moose;
  2         4  
  2         13  
11             with 'Dist::Zilla::Role::MetaProvider';
12              
13 2     2   7915 use CPAN::Meta::Requirements;
  2         2  
  2         40  
14 2     2   7 use Carp 'confess';
  2         2  
  2         96  
15 2     2   8 use namespace::autoclean;
  2         2  
  2         14  
16              
17 2     2 0 788 sub mvp_multivalue_args { qw(breaks) }
18              
19             has breaks => (
20             is => 'ro', isa => 'HashRef[Str]',
21             required => 1,
22             );
23              
24             around BUILDARGS => sub
25             {
26             my $orig = shift;
27             my $class = shift;
28              
29             my $args = $class->$orig(@_);
30             my ($zilla, $plugin_name) = delete @{$args}{qw(zilla plugin_name)};
31              
32             confess 'Missing modules in [Breaks]' if not keys %$args;
33              
34             return {
35             zilla => $zilla,
36             plugin_name => $plugin_name,
37             breaks => $args,
38             };
39             };
40              
41             around dump_config => sub
42             {
43             my ($orig, $self) = @_;
44             my $config = $self->$orig;
45              
46             my $data = {
47             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
48             };
49             $config->{+__PACKAGE__} = $data if keys %$data;
50              
51             return $config;
52             };
53              
54             sub metadata
55             {
56 2     2 0 111003 my $self = shift;
57              
58 2         18 my $reqs = CPAN::Meta::Requirements->new;
59 2         86 my $breaks_data = $self->breaks;
60 2         8 foreach my $package (keys %$breaks_data)
61             {
62             # this validates input data, and canonicalizes formatting
63 3         191 $reqs->add_string_requirement($package, $breaks_data->{$package});
64             }
65              
66 1         104 $breaks_data = $reqs->as_string_hash;
67 1 50       82 return keys %$breaks_data ? { x_breaks => $breaks_data } : {};
68             }
69              
70             __PACKAGE__->meta->make_immutable;
71              
72             __END__
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             Dist::Zilla::Plugin::Breaks - Add metadata about potential breakages caused by your distribution
81              
82             =head1 VERSION
83              
84             version 0.004
85              
86             =head1 SYNOPSIS
87              
88             In your F<dist.ini>:
89              
90             [Breaks]
91             Foo::Bar = <= 1.0 ; anything at this version or below is out of date
92             Foo::Baz = == 2.35 ; just this one exact version is problematic
93              
94             =head1 DESCRIPTION
95              
96             This plugin adds distribution metadata regarding other modules and version
97             that are not compatible with your distribution's release. It is not quite the
98             same as the C<conflicts> field in prerequisite metadata (see
99             L<CPAN::Meta::Spec/Relationships>), but rather
100             indicates what modules will likely not work once your distribution is
101             installed.
102              
103             =for stopwords darkPAN
104              
105             This is a not-uncommon problem when modifying a module's API - there are other
106             existing modules out on the CPAN (or a darkPAN) which use the old API, and will
107             need to be updated when the new API is removed. These modules are not
108             prerequisites -- our distribution does not use those modules, but rather those
109             modules use B<us>. So, it's not valid to list those modules in our
110             prerequisites -- besides, it would likely (almost certainly) be a circular dependency!
111              
112             The data is added to metadata in the form of the C<x_breaks> field, as set out
113             by the L<Lancaster consensus|http://www.dagolden.com/index.php/2098/the-annotated-lancaster-consensus/>.
114             The exact syntax and use may continue to change until it is accepted as an
115             official part of the meta specification.
116              
117             Version ranges can and normally should be specified; see
118             L<CPAN::Meta::Spec/Version Ranges>. They are
119             interpreted as for C<conflicts> -- version(s) specified indicate the B<bad>
120             versions of modules, not version(s) that must be present for normal operation.
121             That is, packages should be specified with the version(s) that will B<not>
122             work when your distribution is installed; for example, if all version of
123             C<Foo::Bar> up to and including 1.2 will break, but a release of 1.3 will
124             work, then specify the breakage as:
125              
126             [Breaks]
127             Foo::Bar = <= 1.2
128              
129             or more accurately:
130              
131             [Breaks]
132             Foo::Bar = < 1.3
133              
134             A bare version with no operator is interpreted as C<< >= >> -- all versions at
135             or above the one specified are considered bad -- which is generally not what
136             you want to say!
137              
138             =for stopwords CheckBreaks
139              
140             The L<[Test::CheckBreaks]|Dist::Zilla::Plugin::Test::CheckBreaks> plugin can
141             generate a test for your distribution that will check this field and provide
142             diagnostic information to the user should any problems be identified.
143              
144             Additionally, the L<[Conflicts]|Dist::Zilla::Plugin::Conflicts> plugin can
145             generate C<x_breaks> data, as well as a (non-standard) mechanism for checking for conflicts
146             from within F<Makefile.PL>/F<Build.PL>.
147              
148             =for Pod::Coverage mvp_multivalue_args metadata
149              
150             =head1 SEE ALSO
151              
152             =over 4
153              
154             =item *
155              
156             L<Annotated Lancaster consensus|http://www.dagolden.com/index.php/2098/the-annotated-lancaster-consensus/>.
157              
158             =item *
159              
160             L<CPAN::Meta::Spec/Relationships>
161              
162             =item *
163              
164             L<Dist::Zilla::Plugin::Test::CheckBreaks>
165              
166             =item *
167              
168             L<Dist::Zilla::Plugin::Conflicts>
169              
170             =item *
171              
172             L<Dist::CheckConflicts>
173              
174             =item *
175              
176             L<Module::Install::CheckConflicts>
177              
178             =back
179              
180             =head1 SUPPORT
181              
182             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Breaks>
183             (or L<bug-Dist-Zilla-Plugin-Breaks@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Breaks@rt.cpan.org>).
184              
185             There is also a mailing list available for users of this distribution, at
186             L<http://dzil.org/#mailing-list>.
187              
188             There is also an irc channel available for users of this distribution, at
189             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
190              
191             I am also usually active on irc, as 'ether' at C<irc.perl.org>.
192              
193             =head1 AUTHOR
194              
195             Karen Etheridge <ether@cpan.org>
196              
197             =head1 COPYRIGHT AND LICENCE
198              
199             This software is copyright (c) 2014 by Karen Etheridge.
200              
201             This is free software; you can redistribute it and/or modify it under
202             the same terms as the Perl 5 programming language system itself.
203              
204             =cut