File Coverage

blib/lib/Dist/Zilla/Plugin/Bootstrap/lib.pm
Criterion Covered Total %
statement 29 31 93.5
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 39 44 88.6


line stmt bran cond sub pod time code
1 6     6   4065 use 5.008; # utf8
  6         15  
2 6     6   26 use strict;
  6         8  
  6         137  
3 6     6   29 use warnings;
  6         8  
  6         177  
4 6     6   3129 use utf8;
  6         53  
  6         30  
5              
6             ## no critic ( NamingConventions::Capitalization )
7             package Dist::Zilla::Plugin::Bootstrap::lib;
8             ## use critic;
9              
10             our $VERSION = '1.001001';
11              
12             # ABSTRACT: A minimal boot-strapping for Dist::Zilla Plug-ins.
13              
14             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28 6     6   3117 use Moose qw( with );
  6         1741113  
  6         38  
29             with 'Dist::Zilla::Role::Bootstrap';
30              
31             sub bootstrap {
32 5     5   39 my ($self) = @_;
33              
34 5         151 my $bootstrap_root = $self->_bootstrap_root;
35              
36 5 50       3931 if ( not $bootstrap_root ) {
37 0         0 return;
38             }
39              
40 5         21 my $bootstrap_path = $bootstrap_root->child('lib');
41 5         113 $self->_add_inc("$bootstrap_path");
42 5         5381 $self->log( [ 'Bootstrapping %s', "$bootstrap_path" ] );
43 5         2302 my $it = $bootstrap_path->iterator( { recurse => 1 } );
44              
45 5         136 while ( my $file = $it->() ) {
46 5 50       648 next unless $file->basename =~ /[.]pm$/msx;
47 5         142 my $rpath = $file->relative($bootstrap_path)->stringify;
48 5 50       828 if ( exists $INC{$rpath} ) {
49 0         0 $self->log( [ '%s was not bootstrapped. You need to move Bootstrap::lib higher', $rpath ] );
50             }
51             }
52              
53 5         151 return 1;
54              
55             }
56              
57             __PACKAGE__->meta->make_immutable;
58 6     6   24830 no Moose;
  6         10  
  6         31  
59              
60             1;
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Dist::Zilla::Plugin::Bootstrap::lib - A minimal boot-strapping for Dist::Zilla Plug-ins.
71              
72             =head1 VERSION
73              
74             version 1.001001
75              
76             =head1 SYNOPSIS
77              
78             [Bootstrap::lib]
79             try_built = 1 ; try using an existing built distribution named Dist-Name-*
80             fallback = 0 ; if try_built can't find a built distribution, or there's more than one, don't bootstrap
81             ; using lib/ instead
82              
83             =head1 DESCRIPTION
84              
85             This module exists for loading either C</lib> or C</Dist-Name-$VERSION/lib> into your C<@INC> early on.
86              
87             This is mostly useful for writing L<< C<Dist::Zilla>|Dist::Zilla >> plug-ins, so that you may build and release
88             a plug-in using itself.
89              
90             =begin MetaPOD::JSON v1.1.0
91              
92             {
93             "namespace":"Dist::Zilla::Plugin::Bootstrap::lib",
94             "interface":"class",
95             "does":"Dist::Zilla::Role::Bootstrap"
96             }
97              
98              
99             =end MetaPOD::JSON
100              
101             =head1 USE CASES
102              
103             =head2 Simple single-phase self-dependency
104              
105             This module really is only useful in the case where you need to use something like
106              
107             dzil -Ilib
108              
109             For I<every> call to L<< C<Dist::Zilla>|Dist::Zilla >>, and this is mainly a convenience.
110              
111             For that
112              
113             [Bootstrap::lib]
114              
115             on its own will do the right thing.
116              
117             =head2 Installed-Only self-dependency
118              
119             The other useful case is when you would normally do
120              
121             dzil build # pass 1 that generates Foo-1.234 with a pre-installed Foo-1.233
122             dzil -IFoo-1.234/lib build # pass 2 that generates Foo-1.234 with Foo-1.234
123              
124             For that
125              
126             [Bootstap::lib]
127             try_built = 1
128             fallback = 0
129              
130             Will do what you want.
131              
132             dzil build # pass1 -> creates Foo-1.234 without bootstrapping
133             dzil build # pass2 -> creates Foo-1.234 boot-strapped from the previous build
134              
135             =head2 2-step self-dependency
136              
137             There's a 3rd useful case which is a hybrid of the 2, where you /can/ build from your own sources without needing a
138             pre-installed version, just you don't want that for release code ( e.g.: $VERSION being C<undef> in code that is run during
139             release is "bad" )
140              
141             [Bootstrap::lib]
142             try_built = 1
143             fallback = 1
144              
145             Then
146              
147             dzil build # pass1 -> creates Foo-1.234 from bootstrapped $root/lib
148             dzil build # pass2 -> creates Foo-1.234 from bootstrapped $root/Foo-1.234
149              
150             =head1 PRECAUTIONS
151              
152             =head2 DO NOT
153              
154             B<DO NOT> use this library from inside a bundle. It will not likely work as expected, and you B<DO NOT> want
155             to bootstrap everything in all cases.
156              
157             =head2 NO VERSION
158              
159             On its own,
160              
161             [Bootstrap::lib]
162              
163             At present, using this module in conjunction with a module with no explicitly defined version in the
164             source will result in the I<executed> instance of that plug-in I<also> having B<NO VERSION>.
165              
166             If this is a problem for you, then its suggested you try either variation of using
167              
168             [Bootstrap::lib]
169             try_built = 1
170             ; no_fallback = 1 #
171              
172             =head2 SUCKS AT GUESSING
173              
174             The core mechanism behind C<try_built> relies on looking in your project directory for a previous build directory of some kind.
175              
176             And there's no way for it to presently pick a "best" version when there are more than one, or magically provide a better
177             solution if there are "zero" versions readily available.
178              
179             This is mostly because there is no way to determine the "current" version we are building for, because the point in the
180             execution cycle is so early, no version plugins are likely to be even instantiated yet, and some version plugins are dependent on
181             incredibly complex precursors ( like git ), so by even trying to garner the version we're currently building, we could be
182             prematurely cutting off a vast majority of modules from even being able to bootstrap.
183              
184             Even as it is, us using C<< zilla->name >> means that if your dist relies on some process to divine its name, the module that
185             does this must:
186              
187             =over 4
188              
189             =item * be loaded and declared prior to C<Bootstrap::lib> in the C<dist.ini>
190              
191             =item * not itself be the module you are presently developing/bootstrapping
192              
193             =back
194              
195             The only way of working around that I can envision is adding parameters to C<Bootstrap::lib> to specify the dist name and version
196             name... but if you're going to do that, you may as well stop using external plugins to discover that, and hard-code those values
197             in C<dist.ini> to start with.
198              
199             =head2 STILL NOT REALLY A PLUGIN
200              
201             Starting at version 0.04000000 ( read: 0.04_0000_00 aka 0.04 + 0 x 4 + 0 x 2 ) this module is a fully fledged class, different
202             only from standard Dist::Zilla Plugins in that it doesn't partake in normal phase order, and only executes during a special
203             custom C<::Bootstrap> phase, which is more or less a different name and implementation of C<BUILD>, in that C<bootstrap> is
204             invoked after C<plugin_from_config> is called ( where C<new> is called ), which occurs somewhere in the middle of
205             C<register_component>
206              
207             This module also appears on the plugin stash, and responds naturally to C<metaconfig> requests.
208              
209             =head1 AUTHOR
210              
211             Kent Fredric <kentnl@cpan.org>
212              
213             =head1 COPYRIGHT AND LICENSE
214              
215             This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
216              
217             This is free software; you can redistribute it and/or modify it under
218             the same terms as the Perl 5 programming language system itself.
219              
220             =cut