File Coverage

blib/lib/Dist/Zilla/Plugin/Deprecated.pm
Criterion Covered Total %
statement 20 22 90.9
branch 3 4 75.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 3 0.0
total 31 39 79.4


line stmt bran cond sub pod time code
1 2     2   6249010 use strict;
  2         4  
  2         100  
2 2     2   14 use warnings;
  2         5  
  2         195  
3             package Dist::Zilla::Plugin::Deprecated; # git description: v0.006-6-g19e5f22
4             # vim: set ts=8 sts=4 sw=4 tw=115 et :
5             # ABSTRACT: Add metadata to your distribution marking it as deprecated
6             # KEYWORDS: plugin metadata module distribution deprecated
7              
8             our $VERSION = '0.007';
9              
10 2     2   16 use Moose;
  2         4  
  2         25  
11             with 'Dist::Zilla::Role::MetaProvider';
12 2     2   16301 use namespace::autoclean;
  2         7  
  2         27  
13              
14             has all => (
15             is => 'ro', isa => 'Bool',
16             init_arg => 'all',
17             lazy => 1,
18             default => sub {
19             my $self = shift;
20             $self->modules ? 0 : 1;
21             },
22             );
23              
24             has modules => (
25             isa => 'ArrayRef[Str]',
26             traits => [ 'Array' ],
27             handles => { modules => 'elements' },
28             lazy => 1,
29             default => sub { [] },
30             );
31              
32 2     2 0 442 sub mvp_aliases { { module => 'modules' } }
33 2     2 0 1555 sub mvp_multivalue_args { qw(modules) }
34              
35             around dump_config => sub
36             {
37             my ($orig, $self) = @_;
38             my $config = $self->$orig;
39              
40             $config->{+__PACKAGE__} = {
41             all => ( $self->all ? 1 : 0),
42             modules => [ sort $self->modules ],
43             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
44             };
45              
46             return $config;
47             };
48              
49             sub metadata
50             {
51 2     2 0 34707 my $self = shift;
52              
53 2 100       181 return { x_deprecated => 1 } if $self->all;
54              
55             # older Dist::Zilla uses Hash::Merge::Simple, which performs the same sort
56             # of merge we need as in new CPAN::Meta::Merge
57             $self->log_fatal('CPAN::Meta::Merge 2.150002 required to deprecate an individual module!')
58 1         34 if eval { Dist::Zilla->VERSION('5.022') }
59 1 50 33     6 and not eval { require CPAN::Meta::Merge; CPAN::Meta::Merge->VERSION('2.150002') };
  1         11  
  1         43  
60              
61 0           return { provides => { map { $_ => { x_deprecated => 1 } } $self->modules } };
  0            
62             }
63              
64             __PACKAGE__->meta->make_immutable;
65              
66             __END__
67              
68             =pod
69              
70             =encoding UTF-8
71              
72             =head1 NAME
73              
74             Dist::Zilla::Plugin::Deprecated - Add metadata to your distribution marking it as deprecated
75              
76             =head1 VERSION
77              
78             version 0.007
79              
80             =head1 SYNOPSIS
81              
82             In your F<dist.ini>:
83              
84             [Deprecated]
85              
86             or
87              
88             [Deprecated]
89             module = MyApp::OlderAPI
90              
91             =head1 DESCRIPTION
92              
93             This is a L<Dist::Zilla> plugin that adds metadata to your distribution marking it as deprecated.
94              
95             This uses the unofficial C<x_deprecated> field,
96             which is a new convention for marking a CPAN distribution as deprecated.
97             You should still note that the distribution is deprecated in the documentation,
98             for example in the abstract and the first paragraph of the DESCRIPTION section.
99              
100             You can also mark a single module (or subset of modules) as deprecated by
101             listing them with the C<module> option. This will add an C<x_deprecated>
102             field to the C<provides> section of metadata. Note that L<CPAN::Meta::Spec>
103             requires you to populate the rest of C<provides> metadata through some
104             other means, such as L<Dist::Zilla::Plugin::MetaProvides::Package>.
105              
106             =head2 Recommendations
107              
108             =for stopwords metacpan.org
109              
110             =over 4
111              
112             =item *
113              
114             When you mark a module as deprecated, prepend '(DEPRECATED)' to its abstract (the one-line module description used
115             in the C<NAME> pod section, which is used to populate module lists on sites such as metacpan.org).
116              
117             =item *
118              
119             Add a warning in the code (usually in the main body of the module, outside of any subroutine):
120              
121             warnings::warnif('deprecated', 'My::Module is deprecated and should no longer be used');
122              
123             =back
124              
125             =head1 CONFIGURATION OPTIONS
126              
127             =head2 C<module>
128              
129             [Deprecated]
130             module = MyApp::OlderAPI
131              
132             Identify a specific module to be deprecated. Can be used more than once.
133              
134             =head2 C<all>
135              
136             [Deprecated]
137             all = 1
138              
139             Not normally needed directly. Mark an entire distribution as deprecated. This
140             defaults to true when there are no C<module>s listed, and false otherwise.
141              
142             =for Pod::Coverage metadata mvp_aliases mvp_multivalue_args
143              
144             =head1 ACKNOWLEDGEMENTS
145              
146             Neil Bowers requested this. :) And then he
147             L<blogged about it|http://neilb.org/2015/01/17/deprecated-metadata.html>.
148              
149             =head1 SUPPORT
150              
151             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Deprecated>
152             (or L<bug-Dist-Zilla-Plugin-Deprecated@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Deprecated@rt.cpan.org>).
153              
154             There is also a mailing list available for users of this distribution, at
155             L<http://dzil.org/#mailing-list>.
156              
157             There is also an irc channel available for users of this distribution, at
158             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
159              
160             I am also usually active on irc, as 'ether' at C<irc.perl.org>.
161              
162             =head1 AUTHOR
163              
164             Karen Etheridge <ether@cpan.org>
165              
166             =head1 CONTRIBUTOR
167              
168             =for stopwords Neil Bowers
169              
170             Neil Bowers <neil@bowers.com>
171              
172             =head1 COPYRIGHT AND LICENCE
173              
174             This software is copyright (c) 2015 by Karen Etheridge.
175              
176             This is free software; you can redistribute it and/or modify it under
177             the same terms as the Perl 5 programming language system itself.
178              
179             =cut