File Coverage

blib/lib/Dist/Zilla/Plugin/RemovePrereqs/Provided.pm
Criterion Covered Total %
statement 42 46 91.3
branch 3 6 50.0
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 55 63 87.3


line stmt bran cond sub pod time code
1 2     2   1651436 use 5.006; # our
  2         6  
2 2     2   8 use strict;
  2         3  
  2         41  
3 2     2   14 use warnings;
  2         3  
  2         142  
4              
5             package Dist::Zilla::Plugin::RemovePrereqs::Provided;
6              
7             our $VERSION = '0.001001';
8              
9             # ABSTRACT: Remove prerequisites that are already provided.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   517 use Moose qw( has with around );
  2         300304  
  2         13  
14 2     2   8102 use Moose::Util::TypeConstraints qw( enum );
  2         2  
  2         16  
15 2     2   1612 use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
  2         1753  
  2         11  
16              
17             my $sources = enum [qw( metaprovides )];
18              
19 2     2   174 no Moose::Util::TypeConstraints;
  2         2  
  2         12  
20              
21             with 'Dist::Zilla::Role::PrereqSource';
22              
23             has provided_source => (
24             isa => $sources,
25             is => 'ro',
26             default => sub { qw( metaprovides ) },
27             );
28              
29             around dump_config => config_dumper( __PACKAGE__, { attrs => 'provided_source' } );
30              
31             __PACKAGE__->meta->make_immutable;
32 2     2   303 no Moose;
  2         5  
  2         9  
33              
34             sub _get_provides_metaprovides {
35 1     1   1 my ( $self, ) = @_;
36 1 50       2 my (@plugins) = @{ $self->zilla->plugins_with('-MetaProvider::Provider') || [] };
  1         23  
37 1 50       335 if ( not @plugins ) {
38 0         0 $self->log('No MetaProvides::Provider plugins found in dist to extract metaprovides from');
39 0         0 return ();
40             }
41 1         4 my @provided = map { $_->provides } @plugins;
  1         7  
42 1 50       89962 if ( not @plugins ) {
43 0         0 $self->log('No modules found while extracting provides from MetaProvider::Provider plugins');
44 0         0 return ();
45             }
46 1         3 return map { $_->module } @provided;
  1         31  
47             }
48              
49             my @phases = qw(configure build test runtime develop);
50             my @types = qw(requires recommends suggests conflicts);
51              
52              
53              
54              
55              
56             sub register_prereqs {
57 1     1 0 48230 my ($self) = @_;
58 1         29 my $prereqs = $self->zilla->prereqs;
59 1         60 my $method = '_get_provides_' . $self->provided_source;
60 1         5 my (@modules) = $self->$method;
61 1         45 for my $phase (@phases) {
62 5         21 for my $type (@types) {
63 20         105 my $reqs = $prereqs->requirements_for( $phase, $type );
64 20         1013 for my $module (@modules) {
65 20         28 $reqs->clear_requirement($module);
66             }
67             }
68             }
69 1         9 return;
70             }
71              
72             1;
73              
74             __END__
75              
76             =pod
77              
78             =encoding UTF-8
79              
80             =head1 NAME
81              
82             Dist::Zilla::Plugin::RemovePrereqs::Provided - Remove prerequisites that are already provided.
83              
84             =head1 VERSION
85              
86             version 0.001001
87              
88             =head1 DESCRIPTION
89              
90             This module is a utility for people who are working with self-consuming code ( predominantly C<Dist::Zilla> distributions )
91             who wish to avoid self-dependencies in cases where some other prerequisite providing tool is over-zealous in determining
92             prerequisites.
93              
94             This is an initial implementation that assumes you have L<< C<[MetaProvides]>|Dist::Zilla::Plugin::MetaProvides >> of some
95             description in place, and uses the data it provides to make sure the same modules don't exist as prerequisites.
96              
97             =for Pod::Coverage register_prereqs
98              
99             =head1 AUTHOR
100              
101             Kent Fredric <kentnl@cpan.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut