File Coverage

blib/lib/Dist/Zilla/Plugin/MetaProvides/FromFile.pm
Criterion Covered Total %
statement 36 36 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 1 1 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1 2     2   2329781 use 5.006;
  2         4  
2 2     2   8 use strict;
  2         2  
  2         42  
3 2     2   14 use warnings;
  2         2  
  2         143  
4              
5             package Dist::Zilla::Plugin::MetaProvides::FromFile;
6              
7             our $VERSION = '2.001002';
8              
9             # ABSTRACT: Pull in hand-crafted metadata from a specified file.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   439 use Moose qw( with has around );
  2         303983  
  2         16  
14 2     2   8205 use Carp ();
  2         4  
  2         47  
15 2     2   10 use Module::Runtime qw( require_module );
  2         3  
  2         12  
16 2     2   1120 use Dist::Zilla::MetaProvides::ProvideRecord;
  2         186729  
  2         88  
17              
18              
19              
20              
21              
22              
23              
24 2     2   19 use namespace::autoclean;
  2         4  
  2         19  
25             with 'Dist::Zilla::Role::MetaProvider::Provider';
26              
27              
28              
29              
30              
31              
32              
33              
34              
35             has file => ( isa => 'Str', is => 'ro', required => 1, );
36              
37              
38              
39              
40              
41              
42              
43              
44              
45             has reader_name => ( isa => 'Str', is => 'ro', default => 'Config::INI::Reader', );
46              
47              
48              
49              
50              
51              
52              
53              
54              
55             has _reader => ( isa => 'Object', is => 'ro', lazy_build => 1, );
56              
57             around dump_config => sub {
58             my ( $orig, $self, @args ) = @_;
59             my $config = $self->$orig(@args);
60             my $localconf = $config->{ +__PACKAGE__ } = {};
61              
62             $localconf->{file} = $self->file;
63             $localconf->{reader_name} = $self->reader_name;
64              
65             $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
66             unless __PACKAGE__ eq ref $self;
67              
68             return $config;
69             };
70              
71             __PACKAGE__->meta->make_immutable;
72 2     2   432 no Moose;
  2         3  
  2         14  
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86             sub provides {
87 1     1 1 69884 my $self = shift;
88 1         34 my $conf = $self->_reader->read_file( $self->file );
89             my $to_record = sub {
90             Dist::Zilla::MetaProvides::ProvideRecord->new(
91             module => $_,
92             file => $conf->{$_}->{file},
93             version => $conf->{$_}->{version},
94 2     2   65 parent => $self,
95             );
96 1         604 };
97 1         2 return map { $to_record->($_) } keys %{$conf};
  2         225  
  1         3  
98             }
99              
100              
101              
102              
103              
104              
105              
106             sub _build__reader {
107 1     1   2 my ($self) = shift;
108 1         34 require_module( $self->reader_name );
109 1         57 return $self->reader_name->new();
110             }
111             1;
112              
113             __END__
114              
115             =pod
116              
117             =encoding UTF-8
118              
119             =head1 NAME
120              
121             Dist::Zilla::Plugin::MetaProvides::FromFile - Pull in hand-crafted metadata from a specified file.
122              
123             =head1 VERSION
124              
125             version 2.001002
126              
127             =head1 SYNOPSIS
128              
129             For a general overview of the C<MetaProvides> family, see
130             L<< Dist::Zilla::Plugin::B<MetaProvides>|Dist::Zilla::Plugin::MetaProvides >>
131              
132             This module is tailored to the situation where probing various files for C<provides> data is not possible, and you just want to
133             declare some in an external file.
134              
135             [MetaProvides::FromFile]
136             inherit_version = 0 ; optional, default = 1
137             inherit_missing = 0 ; optional, default = 1
138             file = some_file.ini ; required
139             reader_name = Config::INI::Reader ; optional, default = Config::INI::Reader
140             meta_no_index ; optional, useless
141              
142             And in C<some_file.ini>
143              
144             [Foo::Package]
145             file = some/module/path
146             version = 0.1
147              
148             =head1 OPTION SUMMARY
149              
150             =head2 inherit_version
151              
152             Shared Logic with all MetaProvides Plugins. See L<Dist::Zilla::Plugin::MetaProvides/inherit_version>
153              
154             =head2 inherit_missing
155              
156             Shared Logic with all MetaProvides Plugins. See L<Dist::Zilla::Plugin::MetaProvides/inherit_missing>
157              
158             =head2 meta_no_index
159              
160             Shared Logic with all MetaProvides Plugins. See L<Dist::Zilla::Plugin::MetaProvides/meta_no_index>
161              
162             However, given you're hard-coding the 'provides' map in the source file, and given that parameter
163             is intended to exclude I<discovered> modules from being indexed, it seems like the smart option would
164             be to simply delete the unwanted entries from the source file.
165              
166             =head2 file
167              
168             Mandatory path to a file within your distribution, relative to the distribution root, to extract C<provides> data from.
169              
170             =head2 reader_name
171              
172             A class that can be used to read the named file. Defaults to Config::INI::Reader.
173              
174             It can be substituted by any class name that matches the following criteria
175              
176             =over 4
177              
178             =item * Can be instantiated via C<new>
179              
180             my $instance = $reader_name->new();
181              
182             =item * has a C<read_file> method on the instance
183              
184             my $result = $instance->read_file( ... )
185              
186             =item * C<read_file> can take the parameter C<file>
187              
188             my $result = $instance->read_file( file => 'path/to/file' )
189              
190             =item * C<read_file> returns a hashref matching the following structure
191              
192             { 'Package::Name' => {
193             file = 'path/to/file',
194             version => '0.1',
195             } }
196              
197             =back
198              
199             =head1 ROLES
200              
201             =head2 L<< C<::Role::MetaProvider::Provider>|Dist::Zilla::Role::MetaProvider::Provider >>
202              
203             =head1 PLUGIN FIELDS
204              
205             =head2 file
206              
207             =head3 type: required, ro, Str
208              
209             =head2 reader_name
210              
211             =head3 type: Str, ro.
212              
213             =head3 default: Config::INI::Reader
214              
215             =head1 PRIVATE PLUGIN FIELDS
216              
217             =head2 _reader
218              
219             =head3 type: Object, ro, built from L</reader_name>
220              
221             =head1 ROLE SATISFYING METHODS
222              
223             =head2 provides
224              
225             A conformant function to the L<< C<::Role::MetaProvider::Provider>|Dist::Zila::Role::MetaProvider::Provider >> Role.
226              
227             =head3 signature: $plugin->provides()
228              
229             =head3 returns: Array of L<< C<MetaProvides::ProvideRecord>|Dist::Zilla::MetaProvides::ProvideRecord >>
230              
231             =head1 BUILDER METHODS
232              
233             =head2 _build__reader
234              
235             =head1 SEE ALSO
236              
237             =over 4
238              
239             =item * L<< C<[MetaProvides]>|Dist::Zilla::Plugin::MetaProvides >>
240              
241             =back
242              
243             =head1 AUTHOR
244              
245             Kent Fredric <kentnl@cpan.org>
246              
247             =head1 COPYRIGHT AND LICENSE
248              
249             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
250              
251             This is free software; you can redistribute it and/or modify it under
252             the same terms as the Perl 5 programming language system itself.
253              
254             =cut