File Coverage

blib/lib/Dist/Zilla/Plugin/BundleInspector.pm
Criterion Covered Total %
statement 47 47 100.0
branch 6 6 100.0
condition n/a
subroutine 12 12 100.0
pod 0 3 0.0
total 65 68 95.5


line stmt bran cond sub pod time code
1             # vim: set ts=2 sts=2 sw=2 expandtab smarttab:
2             #
3             # This file is part of Dist-Zilla-Plugin-BundleInspector
4             #
5             # This software is copyright (c) 2013 by Randy Stauner.
6             #
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             #
10 2     2   1470805 use strict;
  2         4  
  2         66  
11 2     2   8 use warnings;
  2         3  
  2         99  
12              
13             package Dist::Zilla::Plugin::BundleInspector;
14             # git description: v0.003-2-g76040b0
15              
16             our $AUTHORITY = 'cpan:RWSTAUNER';
17             # ABSTRACT: Gather prereq and config info from PluginBundles
18             $Dist::Zilla::Plugin::BundleInspector::VERSION = '0.004';
19 2     2   7 use Moose;
  2         2  
  2         14  
20 2     2   8966 use MooseX::AttributeShortcuts;
  2         224073  
  2         12  
21 2     2   45986 use Moose::Util::TypeConstraints;
  2         3  
  2         18  
22 2     2   3330 use Dist::Zilla::Config::BundleInspector;
  2         8  
  2         79  
23 2     2   14 use namespace::autoclean;
  2         2  
  2         13  
24              
25             with qw(
26             Dist::Zilla::Role::FileMunger
27             Dist::Zilla::Role::PrereqSource
28             );
29              
30 5     5 0 74966 sub mvp_multivalue_args { qw( bundle ) }
31              
32             {
33             my $type = subtype as 'RegexpRef';
34             coerce $type, from 'Str', via { qr/$_/ };
35             has file_name_re => (
36             is => 'ro',
37             isa => $type,
38             coerce => 1,
39             default => sub {
40             qr{(?: ^lib/ )? ( (?: [^/]+/ )+ PluginBundle/.+? ) \.pm$}x
41             },
42             );
43             }
44              
45              
46             has bundles => (
47             is => 'lazy',
48             isa => 'ArrayRef',
49             init_arg => 'bundle',
50             );
51              
52             sub _build_bundles {
53 1     1   2 my ($self) = @_;
54              
55             # TODO: warn if ./lib/ not found in @INC?
56              
57 3 100       26 my $found = [
58             # combine map/grep into one... it feels weird, but why do the m// more than once?
59 1         21 map { $_->name =~ $self->file_name_re ? $1 : () }
60 1         1 @{ $self->zilla->files }
61             ];
62              
63 1         7 s{/}{::}g for @$found;
64              
65 1         26 return $found;
66             }
67              
68             has inspectors => (
69             is => 'lazy',
70             isa => 'HashRef',
71             init_arg => undef,
72             );
73              
74             sub _build_inspectors {
75 4     4   6 my ($self) = @_;
76             return {
77 6         179 map {
78 4         107 ($_ => Dist::Zilla::Config::BundleInspector->new({ bundle_class => $_ }))
79             }
80 4         5 @{ $self->bundles }
81             };
82             }
83              
84             sub register_prereqs {
85 4     4 0 3294 my ($self) = @_;
86              
87 6         1521 $self->zilla->register_prereqs(
88 4         141 %{ $_->prereqs->as_string_hash }
89             )
90 4         9 for values %{ $self->inspectors };
91             }
92              
93             sub munge_file {
94 12     12 0 73274 my ($self, $file) = @_;
95              
96             return
97             # FIXME: build up a list? join('|', map { s{::}{/}g; $_ } @{ $self->bundles })?
98 12 100       28 unless my $class = ($file->name =~ $self->file_name_re)[0];
99              
100 8         31 $class =~ s{/}{::}g;
101              
102             return
103 8 100       237 unless my $inspector = $self->inspectors->{ $class };
104              
105 6         15 my $content = $file->content;
106 6         3499 my $ini_string = $inspector->ini_string;
107 6         4379 chomp $ini_string;
108              
109             # prepend spaces to make verbatim paragraph
110 6         74 $ini_string =~ s/^(.+)$/ $1/mg;
111              
112 6         39 $content =~ s/^=bundle_ini_string$/$ini_string/m;
113 6         25 $file->content($content);
114              
115 6         1118 return;
116             }
117              
118             __PACKAGE__->meta->make_immutable;
119             1;
120              
121             __END__
122              
123             =pod
124              
125             =encoding UTF-8
126              
127             =for :stopwords Randy Stauner ACKNOWLEDGEMENTS INI PluginBundles Mengué Olivier cpan
128             testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto
129             metadata placeholders metacpan
130              
131             =head1 NAME
132              
133             Dist::Zilla::Plugin::BundleInspector - Gather prereq and config info from PluginBundles
134              
135             =head1 VERSION
136              
137             version 0.004
138              
139             =head1 SYNOPSIS
140              
141             ; in dist.ini
142             [Bootstrap::lib]
143             [BundleInspector]
144              
145             =head1 DESCRIPTION
146              
147             This plugin is useful when using L<Dist::Zilla> to release
148             a plugin bundle for L<Dist::Zilla> or L<Pod::Weaver>
149             (others could be supported in the future).
150              
151             Each bundle inspected will be loaded to gather the plugin specs.
152             B<Note> that this means you will probably want to use
153             L<Dist::Zilla::Plugin::Bootstrap::lib>
154             in order to inspect the included bundle
155             (rather than an older, installed version).
156              
157             This plugin does L<Dist::Zilla::Role::PrereqSource>
158             and the bundle's plugin specs will be used
159             to determine additional prereqs for the dist.
160              
161             Additionally this plugin does L<Dist::Zilla::Role::FileMunger>
162             so that if you include a line in the pod of your plugin bundle
163             of exactly C<=bundle_ini_string> it will be replaced with
164             a verbatim block of the roughly equivalent INI config for the bundle.
165              
166             =head1 ATTRIBUTES
167              
168             =head2 bundle
169              
170             Specify the name of a bundle to inspect.
171             Can be used multiple times.
172              
173             If none are specified the plugin will attempt to discover
174             any included bundles.
175              
176             =for Pod::Coverage munge_file
177             mvp_multivalue_args
178             register_prereqs
179              
180             =head1 SEE ALSO
181              
182             =over 4
183              
184             =item *
185              
186             L<Config::MVP::Writer::INI>
187              
188             =item *
189              
190             L<Config::MVP::BundleInspector>
191              
192             =item *
193              
194             L<Dist::Zilla::Config::BundleInspector>
195              
196             =item *
197              
198             L<Dist::Zilla::Role::BundleDeps>
199              
200             =back
201              
202             =head1 SUPPORT
203              
204             =head2 Perldoc
205              
206             You can find documentation for this module with the perldoc command.
207              
208             perldoc Dist::Zilla::Plugin::BundleInspector
209              
210             =head2 Websites
211              
212             The following websites have more information about this module, and may be of help to you. As always,
213             in addition to those websites please use your favorite search engine to discover more resources.
214              
215             =over 4
216              
217             =item *
218              
219             MetaCPAN
220              
221             A modern, open-source CPAN search engine, useful to view POD in HTML format.
222              
223             L<http://metacpan.org/release/Dist-Zilla-Plugin-BundleInspector>
224              
225             =back
226              
227             =head2 Bugs / Feature Requests
228              
229             Please report any bugs or feature requests by email to C<bug-dist-zilla-plugin-bundleinspector at rt.cpan.org>, or through
230             the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugin-BundleInspector>. You will be automatically notified of any
231             progress on the request by the system.
232              
233             =head2 Source Code
234              
235              
236             L<https://github.com/rwstauner/Dist-Zilla-Plugin-BundleInspector>
237              
238             git clone https://github.com/rwstauner/Dist-Zilla-Plugin-BundleInspector.git
239              
240             =head1 AUTHOR
241              
242             Randy Stauner <rwstauner@cpan.org>
243              
244             =head1 CONTRIBUTOR
245              
246             =for stopwords Olivier Mengué
247              
248             Olivier Mengué <dolmen@cpan.org>
249              
250             =head1 COPYRIGHT AND LICENSE
251              
252             This software is copyright (c) 2013 by Randy Stauner.
253              
254             This is free software; you can redistribute it and/or modify it under
255             the same terms as the Perl 5 programming language system itself.
256              
257             =cut