File Coverage

blib/lib/Dist/Zilla/Plugin/RemovePrereqs.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::RemovePrereqs 6.030;
2             # ABSTRACT: a plugin to remove gathered prereqs
3              
4 2     2   1720 use Moose;
  2         7  
  2         13  
5             with 'Dist::Zilla::Role::PrereqSource';
6              
7 2     2   14226 use Dist::Zilla::Pragmas;
  2         7  
  2         20  
8              
9 2     2   31 use namespace::autoclean;
  2         5  
  2         32  
10              
11 2     2   181 use MooseX::Types::Moose qw(ArrayRef);
  2         25  
  2         34  
12 2     2   10670 use MooseX::Types::Perl qw(ModuleName);
  2         6  
  2         27  
13              
14             #pod =head1 SYNOPSIS
15             #pod
16             #pod In your F<dist.ini>:
17             #pod
18             #pod [RemovePrereqs]
19             #pod remove = Foo::Bar
20             #pod remove = MRO::Compat
21             #pod
22             #pod This will remove any prerequisite of any type from any prereq phase. This is
23             #pod useful for eliminating incorrectly detected prereqs.
24             #pod
25             #pod =head1 SEE ALSO
26             #pod
27             #pod Dist::Zilla plugins:
28             #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs>,
29             #pod L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>.
30             #pod
31             #pod =cut
32              
33 2     2 0 451 sub mvp_multivalue_args { qw(modules_to_remove) }
34              
35             sub mvp_aliases {
36 2     2 0 298 return { remove => 'modules_to_remove' }
37             }
38              
39             has modules_to_remove => (
40             is => 'ro',
41             isa => ArrayRef[ ModuleName ],
42             required => 1,
43             );
44              
45             around dump_config => sub {
46             my ($orig, $self) = @_;
47             my $config = $self->$orig;
48              
49             my $this_config = {
50             modules_to_remove => [ sort @{ $self->modules_to_remove } ],
51             };
52              
53             $config->{'' . __PACKAGE__} = $this_config;
54              
55             return $config;
56             };
57              
58             my @phases = qw(configure build test runtime develop);
59             my @types = qw(requires recommends suggests conflicts);
60              
61             sub register_prereqs {
62 2     2 0 8 my ($self) = @_;
63              
64 2         102 my $prereqs = $self->zilla->prereqs;
65              
66 2         6 for my $p (@phases) {
67 10         401 for my $t (@types) {
68 40         1480 for my $m (@{ $self->modules_to_remove }) {
  40         1315  
69 60         1538 $prereqs->requirements_for($p, $t)->clear_requirement($m);
70             }
71             }
72             }
73             }
74              
75             __PACKAGE__->meta->make_immutable;
76             1;
77              
78             __END__
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =head1 NAME
85              
86             Dist::Zilla::Plugin::RemovePrereqs - a plugin to remove gathered prereqs
87              
88             =head1 VERSION
89              
90             version 6.030
91              
92             =head1 SYNOPSIS
93              
94             In your F<dist.ini>:
95              
96             [RemovePrereqs]
97             remove = Foo::Bar
98             remove = MRO::Compat
99              
100             This will remove any prerequisite of any type from any prereq phase. This is
101             useful for eliminating incorrectly detected prereqs.
102              
103             =head1 PERL VERSION
104              
105             This module should work on any version of perl still receiving updates from
106             the Perl 5 Porters. This means it should work on any version of perl released
107             in the last two to three years. (That is, if the most recently released
108             version is v5.40, then this module should work on both v5.40 and v5.38.)
109              
110             Although it may work on older versions of perl, no guarantee is made that the
111             minimum required version will not be increased. The version may be increased
112             for any reason, and there is no promise that patches will be accepted to lower
113             the minimum required perl.
114              
115             =head1 SEE ALSO
116              
117             Dist::Zilla plugins:
118             L<Prereqs|Dist::Zilla::Plugin::Prereqs>,
119             L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>.
120              
121             =head1 AUTHOR
122              
123             Ricardo SIGNES 😏 <cpan@semiotic.systems>
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             This software is copyright (c) 2023 by Ricardo SIGNES.
128              
129             This is free software; you can redistribute it and/or modify it under
130             the same terms as the Perl 5 programming language system itself.
131              
132             =cut