File Coverage

lib/Dist/Zilla/Plugin/Bootstrap/ShareDir/Dist.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1 1     1   610 use 5.008; # utf8
  1         3  
  1         31  
2 1     1   3 use strict;
  1         1  
  1         22  
3 1     1   3 use warnings;
  1         8  
  1         24  
4 1     1   486 use utf8;
  1         8  
  1         3  
5              
6             package Dist::Zilla::Plugin::Bootstrap::ShareDir::Dist;
7              
8             our $VERSION = '1.001001';
9              
10             # ABSTRACT: Use a share directory on your dist during bootstrap
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14 1     1   255 use Moose qw( with around has );
  0            
  0            
15             use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30             with 'Dist::Zilla::Role::Bootstrap';
31              
32             around 'dump_config' => config_dumper( __PACKAGE__, { attrs => ['dir'] } );
33              
34              
35              
36              
37              
38             has dir => (
39             is => ro =>,
40             lazy_build => 1,
41             );
42              
43             sub _build_dir {
44             return 'share';
45             }
46              
47             __PACKAGE__->meta->make_immutable;
48             no Moose;
49              
50              
51              
52              
53              
54              
55              
56             sub do_bootstrap_sharedir {
57             my ( $self, ) = @_;
58              
59             my $root = $self->_bootstrap_root;
60              
61             if ( not defined $root ) {
62             $self->log( ['Not bootstrapping'] );
63             return;
64             }
65             my $sharedir = $root->child( $self->dir );
66             $self->log( [ 'Bootstrapping %s for sharedir for %s', "$sharedir", $self->distname ] );
67             require Test::File::ShareDir::Object::Dist;
68             my $share_object = Test::File::ShareDir::Object::Dist->new( dists => { $self->distname => $sharedir } );
69             for my $dist ( $share_object->dist_names ) {
70             $self->log_debug(
71             [
72             'Installing dist %s ( %s => %s )',
73             "$dist",
74             $share_object->dist_share_source_dir($dist) . q{},
75             $share_object->dist_share_target_dir($dist) . q{},
76             ],
77             );
78             $share_object->install_dist($dist);
79             }
80             require lib;
81             lib->import( $share_object->inc->tempdir . q{} );
82             $self->log_debug( [ 'Sharedir for %s installed to %s', $self->distname, $share_object->inc->dist_tempdir . q{} ] );
83             return;
84             }
85              
86              
87              
88              
89              
90              
91              
92             sub bootstrap {
93             my $self = shift;
94             return $self->do_bootstrap_sharedir;
95             }
96              
97             1;
98              
99             __END__
100              
101             =pod
102              
103             =encoding UTF-8
104              
105             =head1 NAME
106              
107             Dist::Zilla::Plugin::Bootstrap::ShareDir::Dist - Use a share directory on your dist during bootstrap
108              
109             =head1 VERSION
110              
111             version 1.001001
112              
113             =head1 DESCRIPTION
114              
115             This module allows one to load a C<Dist> styled C<ShareDir> using a C<Bootstrap>
116             mechanism so a distribution can use files in its own source tree when building with itself.
117              
118             This is very much like the C<Bootstrap::lib> plugin in that it injects libraries into
119             C<@INC> based on your existing source tree, or a previous build you ran.
120              
121             And it is syntactically like the C<ShareDir> plugin.
122              
123             B<Note> that this is really only useful for self consuming I<plugins> and will have no effect
124             on the C<test> or C<run> phases of your dist. ( For that, you'll need C<Test::File::ShareDir> ).
125              
126             =head1 USAGE
127              
128             [Bootstrap::lib]
129              
130             [Bootstrap::ShareDir::Dist]
131             dir = share
132              
133             [ShareDir]
134             dir = share
135              
136             The only significant difference between this module and C<ShareDir> is this module exists to make C<share> visible to
137             plugins for the distribution being built, while C<ShareDir> exists to export the C<share> directory visible after install time.
138              
139             Additionally, there are two primary attributes that are provided by L<< C<Dist::Zilla::Role::Bootstrap>|Dist::Zilla::Role::Bootstrap >>, See L<< Dist::Zilla::Role::Bootstrap/ATTRIBUTES >>
140              
141             For instance, this bootstraps C<ROOT/Your-Dist-Name-$VERSION/share> if it exists and there's only one C<$VERSION>,
142             otherwise it falls back to simply bootstrapping C<ROOT/share>
143              
144             [Bootstrap::ShareDir::Dist]
145             dir = share
146             try_built = 1
147              
148             =head1 METHODS
149              
150             =head2 C<do_bootstrap_sharedir>
151              
152             This is where all the real work is done.
153              
154             =head2 C<bootstrap>
155              
156             Called by L<<< C<< Dist::Zilla::Role::B<Bootstrap> >>|Dist::Zilla::Role::Bootstrap >>>
157              
158             =head1 ATTRIBUTES
159              
160             =head2 C<dir>
161              
162             =begin MetaPOD::JSON v1.1.0
163              
164             {
165             "namespace":"Dist::Zilla::Plugin::Bootstrap::ShareDir::Dist",
166             "interface":"class",
167             "does":"Dist::Zilla::Role::Bootstrap",
168             "inherits":"Moose::Object"
169             }
170              
171              
172             =end MetaPOD::JSON
173              
174             =head1 AUTHOR
175              
176             Kent Fredric <kentnl@cpan.org>
177              
178             =head1 COPYRIGHT AND LICENSE
179              
180             This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>.
181              
182             This is free software; you can redistribute it and/or modify it under
183             the same terms as the Perl 5 programming language system itself.
184              
185             =cut