File Coverage

blib/lib/Dist/Zilla/Plugin/MetaNoIndex.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 3 33.3
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::MetaNoIndex 6.030;
2             # ABSTRACT: Stop CPAN from indexing stuff
3              
4 2     2   1860 use Moose;
  2         5  
  2         23  
5             with 'Dist::Zilla::Role::MetaProvider';
6              
7 2     2   14361 use Dist::Zilla::Pragmas;
  2         5  
  2         19  
8              
9 2     2   17 use namespace::autoclean;
  2         5  
  2         16  
10              
11             #pod =encoding utf8
12             #pod
13             #pod =head1 SYNOPSIS
14             #pod
15             #pod In your F<dist.ini>:
16             #pod
17             #pod [MetaNoIndex]
18             #pod
19             #pod directory = t/author
20             #pod directory = examples
21             #pod
22             #pod file = lib/Foo.pm
23             #pod
24             #pod package = My::Module
25             #pod
26             #pod namespace = My::Module
27             #pod
28             #pod =head1 DESCRIPTION
29             #pod
30             #pod This plugin allows you to prevent PAUSE/CPAN from indexing files you don't
31             #pod want indexed. This is useful if you build test classes or example classes
32             #pod that are used for those purposes only, and are not part of the distribution.
33             #pod It does this by adding a C<no_index> block to your F<META.json> (or
34             #pod F<META.yml>) file in your distribution.
35             #pod
36             #pod =for Pod::Coverage mvp_aliases mvp_multivalue_args
37             #pod
38             #pod =cut
39              
40             my %ATTR_ALIAS = (
41             directories => [ qw(directory dir folder) ],
42             files => [ qw(file) ],
43             packages => [ qw(package class module) ],
44             namespaces => [ qw(namespace) ],
45             );
46              
47             sub mvp_aliases {
48 1     1 0 150 my %alias_for;
49              
50 1         4 for my $key (keys %ATTR_ALIAS) {
51 4         8 $alias_for{ $_ } = $key for @{ $ATTR_ALIAS{$key} };
  4         22  
52             }
53              
54 1         26 return \%alias_for;
55             }
56              
57 1     1 0 236 sub mvp_multivalue_args { return keys %ATTR_ALIAS }
58              
59             #pod =attr directories
60             #pod
61             #pod Exclude folders and everything in them, for example: F<author.t>
62             #pod
63             #pod Aliases: C<folder>, C<dir>, C<directory>
64             #pod
65             #pod =attr files
66             #pod
67             #pod Exclude a specific file, for example: F<lib/Foo.pm>
68             #pod
69             #pod Alias: C<file>
70             #pod
71             #pod =attr packages
72             #pod
73             #pod Exclude by package name, for example: C<My::Package>
74             #pod
75             #pod Aliases: C<class>, C<module>, C<package>
76             #pod
77             #pod =attr namespaces
78             #pod
79             #pod Exclude everything under a specific namespace, for example: C<My::Package>
80             #pod
81             #pod Alias: C<namespace>
82             #pod
83             #pod B<NOTE:> This will not exclude the package C<My::Package>, only everything
84             #pod under it like C<My::Package::Foo>.
85             #pod
86             #pod =cut
87              
88             for my $attr (keys %ATTR_ALIAS) {
89             has $attr => (
90             is => 'ro',
91             isa => 'ArrayRef[Str]',
92             init_arg => $attr,
93             predicate => "_has_$attr",
94             );
95             }
96              
97             #pod =method metadata
98             #pod
99             #pod Returns a reference to a hash containing the distribution's no_index metadata.
100             #pod
101             #pod =cut
102              
103             sub metadata {
104 1     1 1 2 my $self = shift;
105             return {
106             no_index => {
107 4         11 map {; my $reader = $_->[0]; ($_->[1] => [ sort @{ $self->$reader } ]) }
  4         7  
  4         134  
108 4         12 grep {; my $pred = "_has_$_->[0]"; $self->$pred }
  4         158  
109 1         7 map {; [ $_ => $ATTR_ALIAS{$_}[0] ] }
  4         15  
110             keys %ATTR_ALIAS
111             }
112             };
113             }
114              
115             __PACKAGE__->meta->make_immutable;
116             1;
117              
118             #pod =head1 SEE ALSO
119             #pod
120             #pod Dist::Zilla roles: L<MetaProvider|Dist::Zilla::Role::MetaProvider>.
121             #pod
122             #pod =cut
123              
124             __END__
125              
126             =pod
127              
128             =encoding UTF-8
129              
130             =head1 NAME
131              
132             Dist::Zilla::Plugin::MetaNoIndex - Stop CPAN from indexing stuff
133              
134             =head1 VERSION
135              
136             version 6.030
137              
138             =head1 SYNOPSIS
139              
140             In your F<dist.ini>:
141              
142             [MetaNoIndex]
143              
144             directory = t/author
145             directory = examples
146              
147             file = lib/Foo.pm
148              
149             package = My::Module
150              
151             namespace = My::Module
152              
153             =head1 DESCRIPTION
154              
155             This plugin allows you to prevent PAUSE/CPAN from indexing files you don't
156             want indexed. This is useful if you build test classes or example classes
157             that are used for those purposes only, and are not part of the distribution.
158             It does this by adding a C<no_index> block to your F<META.json> (or
159             F<META.yml>) file in your distribution.
160              
161             =head1 PERL VERSION
162              
163             This module should work on any version of perl still receiving updates from
164             the Perl 5 Porters. This means it should work on any version of perl released
165             in the last two to three years. (That is, if the most recently released
166             version is v5.40, then this module should work on both v5.40 and v5.38.)
167              
168             Although it may work on older versions of perl, no guarantee is made that the
169             minimum required version will not be increased. The version may be increased
170             for any reason, and there is no promise that patches will be accepted to lower
171             the minimum required perl.
172              
173             =head1 ATTRIBUTES
174              
175             =head2 directories
176              
177             Exclude folders and everything in them, for example: F<author.t>
178              
179             Aliases: C<folder>, C<dir>, C<directory>
180              
181             =head2 files
182              
183             Exclude a specific file, for example: F<lib/Foo.pm>
184              
185             Alias: C<file>
186              
187             =head2 packages
188              
189             Exclude by package name, for example: C<My::Package>
190              
191             Aliases: C<class>, C<module>, C<package>
192              
193             =head2 namespaces
194              
195             Exclude everything under a specific namespace, for example: C<My::Package>
196              
197             Alias: C<namespace>
198              
199             B<NOTE:> This will not exclude the package C<My::Package>, only everything
200             under it like C<My::Package::Foo>.
201              
202             =head1 METHODS
203              
204             =head2 metadata
205              
206             Returns a reference to a hash containing the distribution's no_index metadata.
207              
208             =for Pod::Coverage mvp_aliases mvp_multivalue_args
209              
210             =head1 SEE ALSO
211              
212             Dist::Zilla roles: L<MetaProvider|Dist::Zilla::Role::MetaProvider>.
213              
214             =head1 AUTHOR
215              
216             Ricardo SIGNES 😏 <cpan@semiotic.systems>
217              
218             =head1 COPYRIGHT AND LICENSE
219              
220             This software is copyright (c) 2023 by Ricardo SIGNES.
221              
222             This is free software; you can redistribute it and/or modify it under
223             the same terms as the Perl 5 programming language system itself.
224              
225             =cut