File Coverage

blib/lib/Dist/Zilla/Plugin/AuthorityFromModule.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1 5     5   2807990 use strict;
  5         9  
  5         160  
2 5     5   17 use warnings;
  5         5  
  5         229  
3             package Dist::Zilla::Plugin::AuthorityFromModule; # git description: v0.004-12-ga2ab1f6
4             # ABSTRACT: Add metadata to your distribution indicating what module to copy PAUSE permissions from
5             # KEYWORDS: distribution metadata authority permissions PAUSE users
6             # vim: set ts=8 sts=4 sw=4 tw=78 et :
7              
8             our $VERSION = '0.005';
9              
10 5     5   17 use Moose;
  5         5  
  5         33  
11             with 'Dist::Zilla::Role::MetaProvider',
12             'Dist::Zilla::Role::ModuleMetadata';
13 5     5   21041 use List::Util 1.33 qw(first any);
  5         108  
  5         316  
14 5     5   21 use namespace::autoclean;
  5         8  
  5         39  
15              
16             has module => (
17             is => 'ro', isa => 'Str',
18             );
19              
20             has _module_name => (
21             is => 'ro', isa => 'Str',
22             lazy => 1,
23             default => sub {
24             my $self = shift;
25              
26             if (my $module = $self->module)
27             {
28             if (my $file = first {
29             $_->name =~ m{^lib/} and $_->name =~ m{\.pm$}
30             and any { $module eq $_ } $self->_packages_from_file($_) }
31             @{ $self->zilla->files })
32             {
33             $self->log_debug([ 'found \'%s\' in %s', $module, $file->name ]);
34             return $module;
35             }
36              
37             $self->log_fatal([ 'the module \'%s\' cannot be found in the distribution', $module ]);
38             }
39              
40             $self->log_debug('no module provided; defaulting to the main module');
41              
42             my $file = $self->zilla->main_module;
43             my ($module) = $self->_packages_from_file($file);
44             $self->log_debug([ 'extracted package \'%s\' from %s', $module, $file->name ]);
45             $module;
46             },
47             );
48              
49             around dump_config => sub
50             {
51             my ($orig, $self) = @_;
52             my $config = $self->$orig;
53              
54             $config->{+__PACKAGE__} = {
55             module => $self->_module_name,
56             };
57              
58             return $config;
59             };
60              
61             sub metadata
62             {
63 4     4 0 82795 my $self = shift;
64              
65 4         279 my $module = $self->_module_name;
66              
67             +{
68             # TODO: figure out which field is preferred
69 4         27 x_authority_from_module => $module,
70             x_permissions_from_module => $module,
71             };
72             }
73              
74             sub _packages_from_file
75             {
76 7     7   395 my ($self, $file) = @_;
77              
78 7         24 my $mmd = $self->module_metadata_for_file($file);
79 7         13959 grep { $_ ne 'main' } $mmd->packages_inside;
  13         87  
80             }
81              
82             __PACKAGE__->meta->make_immutable;
83              
84             __END__
85              
86             =pod
87              
88             =encoding UTF-8
89              
90             =head1 NAME
91              
92             Dist::Zilla::Plugin::AuthorityFromModule - Add metadata to your distribution indicating what module to copy PAUSE permissions from
93              
94             =head1 VERSION
95              
96             version 0.005
97              
98             =head1 SYNOPSIS
99              
100             In your F<dist.ini>:
101              
102             [AuthorityFromModule]
103              
104             =head1 DESCRIPTION
105              
106             This is a L<Dist::Zilla> plugin that adds the C<x_authority_from_module> and
107             C<x_permissions_from_module> keys to your distribution metadata, indicating
108             from which module to copy L<PAUSE|http://pause.perl.org> permissions when a
109             module in your distribution enters the L<PAUSE|http://pause.perl.org> index
110             that has not ever previously been indexed.
111              
112             Note that these fields aren't actually supported yet by
113             L<PAUSE|http://pause.perl.org> -- that's still to come (as is figuring out
114             which field name everyone prefers, and ditching the other one).
115              
116             =head1 MOTIVATION
117              
118             The idea is that this is a more useful piece of data for
119             L<PAUSE|http://pause.perl.org> than C<x_authority>. Here is how the release
120             process works with C<x_authority>, using L<Moose> as an example:
121              
122             =for stopwords STEVAN maint
123              
124             =over 4
125              
126             =item *
127              
128             I (ETHER) release a new version of L<Moose> with a new module added, C<Moose::Foo>
129              
130             =item *
131              
132             normally, L<PAUSE|http://pause.perl.org> would give me "first-come" permissions on this module, but since L<PAUSE|http://pause.perl.org> sees the C<< x_authority => 'cpan:STEVAN' >> metadata, it instead gives "first-come" to STEVAN, and "co-maint" to me
133              
134             =item *
135              
136             but now none of the other members of the Moose cabal can do the next Moose release and get the new version of C<Moose::Foo> indexed - they need to contact STEVAN and ask him to give them co-maint at L<http://pause.perl.org>
137              
138             =back
139              
140             So, we can see the only gain is that STEVAN automatically gets permission on
141             the new module, but still, no one else does. Now, let's look at how
142             C<x_authority_from_module> would work:
143              
144             =over 4
145              
146             =item *
147              
148             I (ETHER) release a new version of L<Moose> with a new module added, C<Moose::Foo>
149              
150             =item *
151              
152             L<PAUSE|http://pause.perl.org> sees the C<< x_authority_from_module => 'Moose' >> metadata and looks up the permissions for the L<Moose> module, and, L<finding many authors|https://pause.perl.org/pause/authenquery?pause99_peek_perms_by=me&pause99_peek_perms_query=Moose&pause99_peek_perms_sub=Submit>, copies all those permissions to L<Moose::Foo>: STEVAN gets first-come, and everyone else (ETHER included) gets co-maint.
153              
154             =item *
155              
156             now any of the other members of the Moose cabal can do the next Moose release and everything will be properly indexed, with no manual intervention required.
157              
158             =back
159              
160             =head1 CONFIGURATION OPTIONS
161              
162             =head2 C<module>
163              
164             The module name to copy permissions from. It must exist in the distribution,
165             and exist in the L<PAUSE|http://pause.perl.org> permissions table (see
166             L<peek at PAUSE permissions|https://pause.perl.org/pause/authenquery?ACTION=peek_perms>).
167              
168             This config is optional; it defaults to the L<main module|Dist::Zilla/main_module> in the distribution.
169              
170             =for Pod::Coverage metadata
171              
172             =head1 SUPPORT
173              
174             =for stopwords irc
175              
176             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-AuthorityFromModule>
177             (or L<bug-Dist-Zilla-Plugin-AuthorityFromModule@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-AuthorityFromModule@rt.cpan.org>).
178             I am also usually active on irc, as 'ether' at C<irc.perl.org>.
179              
180             =head1 SEE ALSO
181              
182             =over 4
183              
184             =item *
185              
186             L<Dist::Zilla::Plugin::Authority>
187              
188             =item *
189              
190             L<peek at PAUSE permissions|https://pause.perl.org/pause/authenquery?ACTION=peek_perms>
191              
192             =item *
193              
194             L<What is x_authority?|http://jawnsy.wordpress.com/2011/02/20/what-is-x_authority>
195              
196             =back
197              
198             =head1 AUTHOR
199              
200             Karen Etheridge <ether@cpan.org>
201              
202             =head1 COPYRIGHT AND LICENSE
203              
204             This software is copyright (c) 2014 by Karen Etheridge.
205              
206             This is free software; you can redistribute it and/or modify it under
207             the same terms as the Perl 5 programming language system itself.
208              
209             =cut