File Coverage

lib/Dist/Zilla/Plugin/RemovePrereqs/Provided.pm
Criterion Covered Total %
statement 43 47 91.4
branch 3 6 50.0
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 56 64 87.5


line stmt bran cond sub pod time code
1 2     2   783150 use 5.006; # our
  2         33  
  2         110  
2 2     2   9 use strict;
  2         2  
  2         60  
3 2     2   10 use warnings;
  2         30  
  2         240  
4              
5             package Dist::Zilla::Plugin::RemovePrereqs::Provided;
6              
7             our $VERSION = '0.001000';
8              
9             # ABSTRACT: Remove prerequisites that are already provided.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   575 use Moose qw( has with around );
  2         456460  
  2         16  
14 2     2   10795 use Moose::Util::TypeConstraints qw( enum );
  2         4  
  2         19  
15 2     2   1391 use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
  2         2134  
  2         19  
16              
17             my $sources = enum [qw( metaprovides )];
18              
19 2     2   215 no Moose::Util::TypeConstraints;
  2         4  
  2         15  
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   384 no Moose;
  2         2  
  2         13  
33              
34             sub _get_provides_metaprovides {
35 1     1   2 my ( $self, ) = @_;
36 1 50       1 my (@plugins) = @{ $self->zilla->plugins_with('-MetaProvider::Provider') || [] };
  1         24  
37 1 50       239 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         2 my @provided = map { $_->provides } @plugins;
  1         4  
42 1 50       94203 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         2 return map { $_->module } @provided;
  1         56  
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 49421 my ($self) = @_;
58 1         30 my $prereqs = $self->zilla->prereqs;
59 1         60 my $method = '_get_provides_' . $self->provided_source;
60 1         4 my (@modules) = $self->$method;
61 1         43 for my $phase (@phases) {
62 5         23 for my $type (@types) {
63 20         108 my $reqs = $prereqs->requirements_for( $phase, $type );
64 20         1199 for my $module (@modules) {
65 20         31 $reqs->clear_requirement($module);
66             }
67             }
68             }
69 1         8 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.001000
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) 2015 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