Starter/BuilderSet.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 9 / 9 totaltotal 93.6% 89 / 95 CC 9 SCAR 12.0
CC
9
Cov
94%
check_compatibility
7.1
_builder
3.0
BEGIN
1.0
CRAP 3.3
« Starter.pm ↑ Summary Starter/Plugin/Template.pm »
1 package Module::Starter::BuilderSet;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Carp qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Module::Starter::BuilderSet - determine builder metadata
11  
12 =head1 VERSION
13  
14 version 1.82
15  
16 =cut
17  
18 5 our $VERSION = '1.82';
19  
20 =head1 SYNOPSIS
21  
22 use Module::Starter::BuilderSet;
23  
24 my $builder_set = Module::Starter::BuilderSet->new;
25 my @supported_builders = $builder_set->supported_builders();
26 my $default_builder = $builder_set->default_builder();
27 my $output_file = $builder_set->file_for_builder($default_builder);
28  
29 my $create_method = $builder_set->method_for_builder($default_builder);
30 Module::Starter::Simple->$create_method($default_builder); # eeew.
31  
32 my @build_commands = $builder_set->instructions_for_builder($default_builder);
33 my @builder_dependencies = $builder_set->deps_for_builder($default_builder);
34 my @compatible_builders = $builder_set->check_compatibility(@builder_list);
35  
36 my $ms_simple = Module::Starter::Simple->new();
37 my $build_method = $builder_set->manifest_method($builder);
38 $ms_simple->$build_method();
39  
40 =head1 DESCRIPTION
41  
42 Module::Starter::BuilderSet is a collection of utility methods used to
43 provide metadata about builders supported by Module::Starter.
44  
45 =head1 CLASS METHODS
46  
47 =head2 C<< new() >>
48  
49 This method initializes and returns an object representing the set of
50 Builders supported by Module::Starter
51  
52 =cut
53  
54 93 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
55 93 my $class = shift;
56  
57 93 my $self =
58 {
59 'Module::Build' =>
60 {
61 file => "Build.PL",
62 build_method => "create_Build_PL",
63 build_deps => [],
64 build_manifest => 'create_MB_MANIFEST',
65 instructions => [ 'perl Build.PL',
66 './Build',
67 './Build test',
68 './Build install',
69 ],
70 },
71 'Module::Install' =>
72 {
73 file => "Makefile.PL",
74 build_method => "create_MI_Makefile_PL",
75 build_deps => [],
76 build_manifest => 'create_MI_MANIFEST',
77 instructions => [ 'perl Makefile.PL',
78 'make',
79 'make test',
80 'make install',
81 ],
82 },
83 'ExtUtils::MakeMaker' =>
84 {
85 file => "Makefile.PL",
86 build_method => "create_Makefile_PL",
87 build_manifest => 'create_EUMM_MANIFEST',
88 build_deps => [ { command => 'make',
89 aliases => [ 'make', 'gmake' ],
90 },
91 { command => 'chmod',
92 aliases => [ 'chmod' ],
93 },
94 ],
95 instructions => [ 'perl Makefile.PL',
96 'make',
97 'make test',
98 'make install',
99 ],
100 }
101 };
102  
103 93 return bless $self, $class;
104 }
105  
106 361 ▶sub _builder {
Subroutine _builder: called CC=3 SCAR=11.0
107 361 my $self = shift;
108 361 my $builder = shift;
109  
110 361 ▶ $builder = $self->default_builder unless $builder;
Branch: 1 branch
BranchTrueFalseTotal
unless $builder 0 361 361
111  
112 361 ▶ unless (exists $self->{$builder}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$builder}) 4 357 361
113 4 carp("Don't know anything about builder '$builder'.");
114 4 return undef;
115 }
116  
117 357 return $self->{$builder};
118 }
119  
120 =head2 C<< supported_builders() >>
121  
122 This method returns a list of builders supported by Module::Starter
123  
124 =cut
125  
126 5 ▶sub supported_builders {
Subroutine supported_builders: called CC=1 SCAR=0.0
Pod documented
127 5 my $self = shift;
128  
129 5 return keys %$self;
130 }
131  
132 =head2 C<< file_for_builder($builder) >>
133  
134 This method returns the name of the file generated by Module::Starter
135 that will be used to build the generated module
136  
137 =cut
138  
139 154 ▶sub file_for_builder {
Subroutine file_for_builder: called CC=1 SCAR=0.0
Pod documented
140 154 my $self = shift;
141 154 my $builder = shift;
142  
143 154 return $self->_builder($builder)->{file};
144 }
145  
146 =head2 C<< method_for_builder($builder) >>
147  
148 This method returns the name of the method in the
149 C<Module::Starter::Simple> package that is called to create the file
150 returned by C<file_for_builder($builder)>
151  
152 =cut
153  
154 49 ▶sub method_for_builder {
Subroutine method_for_builder: called CC=1 SCAR=0.0
Pod documented
155 49 my $self = shift;
156 49 my $builder = shift;
157  
158 49 return $self->_builder($builder)->{build_method};
159 }
160  
161 =head2 C<< instructions_for_builder($builder) >>
162  
163 This method returns a list of commands that, when run from the command
164 line (or with C<system()>), will cause the generated module to be
165 built, tested and installed.
166  
167 =cut
168  
169 49 ▶sub instructions_for_builder {
Subroutine instructions_for_builder: called CC=1 SCAR=0.0
Pod documented
170 49 my $self = shift;
171 49 my $builder = shift;
172  
173 49 return @{ $self->_builder($builder)->{instructions} };
174 }
175  
176 =head2 C<< deps_for_builder($builder) >>
177  
178 This method returns a list of dependencies in the following format:
179 C<<
180 ( { command => "make",
181 aliases => [ 'make', 'gmake' ],
182 },
183 { command => "another_command",
184 aliases => [ 'alias0', 'alias1', '...' ],
185 },
186 )
187 >>
188  
189 =cut
190  
191 3 ▶sub deps_for_builder {
Subroutine deps_for_builder: called CC=1 SCAR=0.0
Pod documented
192 3 my $self = shift;
193 3 my $builder = shift;
194  
195 3 return @{ $self->_builder($builder)->{build_deps} };
196 }
197  
198 =head2 C<< manifest_method($builder) >>
199  
200 This method returns the command to run to create the manifest according to the
201 builder asked.
202  
203 =cut
204  
205 46 ▶sub manifest_method {
Subroutine manifest_method: called CC=1 SCAR=0.0
Pod documented
206 46 my ( $self, $builder ) = @_;
207  
208 46 return $self->_builder($builder)->{'build_manifest'};
209 }
210  
211 =head2 C<< check_compatibility(@builders) >>
212  
213 This method accepts a list of builders and filters out the ones that
214 are unsupported or mutually exclusive, returning the builders that
215 passed the filter. If none pass the filter, the default builder is
216 returned.
217  
218 =cut
219  
220 53 ▶sub check_compatibility {
Subroutine check_compatibility: called CC=7 SCAR=19.6
Pod documented
221 53 my $self = shift;
222 53 my @builders = @_;
223  
224 # if we're passed an array reference (or even a list of array
225 # references), de-reference the first one passed and assign
226 # @builders its contents
227  
228 0 ▶ @builders = @{$builders[0]} if(@builders && ref $builders[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if @builders and ref $builders[0] eq "ARRAY" 0 53 53
Condition66%2/3
@builders and ref $builders[0] eq "ARRAY"
!ll&&!rl&&r
2510
MC/DC0%0/2
@builders and ref $builders[0] eq "ARRAY"
@builders ref $builders[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @buildersB= ref $builders[0] eq "ARRAY"
ABresult
0X0
100
111
229  
230 # remove empty and unsupported builders
231 53 @builders = grep { $self->_builder($_) } @builders;
232  
233 # if we stripped all of them, use the default
234 53 ▶ push(@builders, $self->default_builder) unless int( @builders ) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int @builders > 0 3 50 53
235  
236 53 my %uniq;
237 my @good;
238 53 foreach my $builder (@builders) {
239 # Builders that generate the same build file are mutually exclusive
240  
241 # If given a list of builder modules that includes mutually
242 # exclusive modules, we'll use the first in the list
243  
244 59 my $file = $self->file_for_builder($builder);
245 59 ▶ if (exists $uniq{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $uniq{$file}) { } 4 55 59
246 # don't print a warning if the same builder was listed twice.
247 # Otherwise, inform the caller that these builders are mutually
248 # exclusive
249 carp("Builders '$builder' and '$uniq{$file}' are mutually exclusive.".
250 " Using '$uniq{$file}'."
251 4 ▶ ) unless $builder eq $uniq{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $builder eq $uniq{$file} 3 1 4
252 } else {
253 55 $uniq{$file} = $builder;
254 55 push(@good, $uniq{$file});
255 }
256 }
257  
258 53 return( @good );
259 }
260  
261 =head2 C<< default_builder() >>
262  
263 This method returns the module name of the default builder.
264  
265 =cut
266  
267 8 ▶sub default_builder {
Subroutine default_builder: called CC=1 SCAR=0.0
Pod documented
268 8 my $self = shift;
269  
270 8 return 'ExtUtils::MakeMaker';
271 }
272  
273 =head1 BUGS
274  
275 Please report any bugs or feature requests to the bugtracker for this project
276 on GitHub at: L<https://github.com/xsawyerx/module-starter/issues>. I will be
277 notified, and then you'll automatically be notified of progress on your bug
278 as I make changes.
279  
280 =head1 AUTHOR
281  
282 C.J. Adams-Collier, C<< <cjac@colliertech.org> >>
283  
284 =head1 Copyright & License
285  
286 Copyright 2007 C.J. Adams-Collier, All Rights Reserved.
287  
288 This program is free software; you can redistribute it and/or modify it
289 under the same terms as Perl itself.
290  
291 Please note that these modules are not products of or supported by the
292 employers of the various contributors to the code.
293  
294 =cut
295  
296 5 1;
297  
298 # vi:et:sw=4 ts=4
« Starter.pm ↑ Summary Starter/Plugin/Template.pm »