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.037;
2             # ABSTRACT: Stop CPAN from indexing stuff
3              
4 2     2   2452 use Moose;
  2         5  
  2         16  
5             with 'Dist::Zilla::Role::MetaProvider';
6              
7 2     2   11243 use Dist::Zilla::Pragmas;
  2         5  
  2         17  
8              
9 2     2   10 use namespace::autoclean;
  2         4  
  2         19  
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 106 my %alias_for;
49              
50 1         4 for my $key (keys %ATTR_ALIAS) {
51 4         6 $alias_for{ $_ } = $key for @{ $ATTR_ALIAS{$key} };
  4         16  
52             }
53              
54 1         32 return \%alias_for;
55             }
56              
57 1     1 0 261 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 3 my $self = shift;
105             return {
106             no_index => {
107 4         7 map {; my $reader = $_->[0]; ($_->[1] => [ sort @{ $self->$reader } ]) }
  4         5  
  4         86  
108 4         6 grep {; my $pred = "_has_$_->[0]"; $self->$pred }
  4         113  
109 1         5 map {; [ $_ => $ATTR_ALIAS{$_}[0] ] }
  4         10  
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.037
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
165             released in the last two to three years. (That is, if the most recently
166             released version is v5.40, then this module should work on both v5.40 and
167             v5.38.)
168              
169             Although it may work on older versions of perl, no guarantee is made that the
170             minimum required version will not be increased. The version may be increased
171             for any reason, and there is no promise that patches will be accepted to
172             lower the minimum required perl.
173              
174             =head1 ATTRIBUTES
175              
176             =head2 directories
177              
178             Exclude folders and everything in them, for example: F<author.t>
179              
180             Aliases: C<folder>, C<dir>, C<directory>
181              
182             =head2 files
183              
184             Exclude a specific file, for example: F<lib/Foo.pm>
185              
186             Alias: C<file>
187              
188             =head2 packages
189              
190             Exclude by package name, for example: C<My::Package>
191              
192             Aliases: C<class>, C<module>, C<package>
193              
194             =head2 namespaces
195              
196             Exclude everything under a specific namespace, for example: C<My::Package>
197              
198             Alias: C<namespace>
199              
200             B<NOTE:> This will not exclude the package C<My::Package>, only everything
201             under it like C<My::Package::Foo>.
202              
203             =head1 METHODS
204              
205             =head2 metadata
206              
207             Returns a reference to a hash containing the distribution's no_index metadata.
208              
209             =for Pod::Coverage mvp_aliases mvp_multivalue_args
210              
211             =head1 SEE ALSO
212              
213             Dist::Zilla roles: L<MetaProvider|Dist::Zilla::Role::MetaProvider>.
214              
215             =head1 AUTHOR
216              
217             Ricardo SIGNES 😏 <cpan@semiotic.systems>
218              
219             =head1 COPYRIGHT AND LICENSE
220              
221             This software is copyright (c) 2026 by Ricardo SIGNES.
222              
223             This is free software; you can redistribute it and/or modify it under
224             the same terms as the Perl 5 programming language system itself.
225              
226             =cut