File Coverage

blib/lib/Dist/Zilla/Plugin/Prereqs/AuthorDeps.pm
Criterion Covered Total %
statement 47 47 100.0
branch 4 4 100.0
condition n/a
subroutine 13 13 100.0
pod 0 2 0.0
total 64 66 96.9


line stmt bran cond sub pod time code
1 2     2   5412173 use v5.10;
  2         8  
2 2     2   13 use strict;
  2         16  
  2         75  
3 2     2   13 use warnings;
  2         5  
  2         148  
4              
5             package Dist::Zilla::Plugin::Prereqs::AuthorDeps;
6             # ABSTRACT: Add Dist::Zilla authordeps to META files as develop prereqs
7             our $VERSION = '0.007';
8              
9 2     2   18 use Moose;
  2         6  
  2         17  
10 2     2   13595 use MooseX::Types::Moose qw( HashRef ArrayRef Str );
  2         4  
  2         27  
11 2     2   11218 use List::Util qw/min/;
  2         6  
  2         220  
12 2     2   15 use Path::Tiny;
  2         6  
  2         112  
13              
14 2     2   1080 use Dist::Zilla::Util::AuthorDeps 5.021;
  2         2489  
  2         72  
15 2     2   16 use Dist::Zilla 4;
  2         31  
  2         58  
16              
17 2     2   16 use constant MAX_DZIL_VERSION => 5;
  2         19  
  2         1000  
18              
19             with 'Dist::Zilla::Role::PrereqSource';
20              
21             #pod =attr phase
22             #pod
23             #pod Phase for prereqs. Defaults to 'develop'.
24             #pod
25             #pod =cut
26              
27             has phase => (
28             is => ro =>,
29             isa => Str,
30             lazy => 1,
31             default => sub { 'develop' },
32             );
33              
34             #pod =attr relation
35             #pod
36             #pod Relation type. Defaults to 'requires'.
37             #pod
38             #pod =cut
39              
40             has relation => (
41             is => ro =>,
42             isa => Str,
43             lazy => 1,
44             default => sub { 'requires' },
45             );
46              
47             #pod =attr exclude
48             #pod
49             #pod Module to exclude from prereqs. May be specified multiple times.
50             #pod
51             #pod =cut
52              
53             has exclude => (
54             is => ro =>,
55             isa => ArrayRef [Str],
56             lazy => 1,
57             default => sub { [] }
58             );
59              
60             has _exclude_hash => (
61             is => ro =>,
62             isa => HashRef [Str],
63             lazy => 1,
64             builder => '_build__exclude_hash'
65             );
66              
67             sub _build__exclude_hash {
68 2     2   9 my ( $self, ) = @_;
69 2         6 return { map { ; $_ => 1 } @{ $self->exclude } };
  1         41  
  2         81  
70             }
71              
72 2     2 0 453 sub mvp_multivalue_args { return qw(exclude) }
73              
74             sub register_prereqs {
75 2     2 0 522192 my ($self) = @_;
76 2         71 my $zilla = $self->zilla;
77 2         91 my $phase = $self->phase;
78 2         82 my $relation = $self->relation;
79              
80 2         13 my $authordeps = Dist::Zilla::Util::AuthorDeps::extract_author_deps('.');
81              
82 2         9477 for my $req (@$authordeps) {
83 13         2608 my ( $mod, $version ) = each %$req;
84 13 100       547 next if $self->_exclude_hash->{$mod};
85              
86 12         68 (my $filename = $mod) =~ s{::}{/}g;
87 12 100       358 next if path($self->zilla->root, $filename.'.pm')->exists;
88              
89 11         1240 $zilla->register_prereqs( { phase => $phase, type => $relation }, $mod, $version );
90             }
91              
92             $zilla->register_prereqs(
93 2         448 { phase => $phase, type => $relation },
94             "Dist::Zilla", min( MAX_DZIL_VERSION, int( Dist::Zilla->VERSION ) ),
95             );
96              
97 2         481 return;
98             }
99              
100             1;
101              
102              
103             # vim: ts=4 sts=4 sw=4 et:
104              
105             __END__
106              
107             =pod
108              
109             =encoding UTF-8
110              
111             =head1 NAME
112              
113             Dist::Zilla::Plugin::Prereqs::AuthorDeps - Add Dist::Zilla authordeps to META files as develop prereqs
114              
115             =head1 VERSION
116              
117             version 0.007
118              
119             =head1 SYNOPSIS
120              
121             # in dist.ini:
122              
123             [Prereqs::AuthorDeps]
124              
125             =head1 DESCRIPTION
126              
127             This adds L<Dist::Zilla> itself and the result of the C<dzil authordeps>
128             command to the 'develop' phase prerequisite list.
129              
130             =head1 ATTRIBUTES
131              
132             =head2 phase
133              
134             Phase for prereqs. Defaults to 'develop'.
135              
136             =head2 relation
137              
138             Relation type. Defaults to 'requires'.
139              
140             =head2 exclude
141              
142             Module to exclude from prereqs. May be specified multiple times.
143              
144             =for Pod::Coverage mvp_multivalue_args register_prereqs MAX_DZIL_VERSION
145              
146             =head1 SEE ALSO
147              
148             L<Dist::Zilla::Plugin::Prereqs::Plugins> is similar but puts all plugins after
149             expanding any bundles into prerequisites, which is a much longer list that you
150             would get from C<dzil authordeps>.
151              
152             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
153              
154             =head1 SUPPORT
155              
156             =head2 Bugs / Feature Requests
157              
158             Please report any bugs or feature requests through the issue tracker
159             at L<https://github.com/dagolden/Dist-Zilla-Plugin-Prereqs-AuthorDeps/issues>.
160             You will be notified automatically of any progress on your issue.
161              
162             =head2 Source Code
163              
164             This is open source software. The code repository is available for
165             public review and contribution under the terms of the license.
166              
167             L<https://github.com/dagolden/Dist-Zilla-Plugin-Prereqs-AuthorDeps>
168              
169             git clone https://github.com/dagolden/Dist-Zilla-Plugin-Prereqs-AuthorDeps.git
170              
171             =head1 AUTHOR
172              
173             David Golden <dagolden@cpan.org>
174              
175             =head1 CONTRIBUTORS
176              
177             =for stopwords David Golden Karen Etheridge
178              
179             =over 4
180              
181             =item *
182              
183             David Golden <xdg@xdg.me>
184              
185             =item *
186              
187             Karen Etheridge <ether@cpan.org>
188              
189             =back
190              
191             =head1 COPYRIGHT AND LICENSE
192              
193             This software is Copyright (c) 2013 by David Golden.
194              
195             This is free software, licensed under:
196              
197             The Apache License, Version 2.0, January 2004
198              
199             =cut