Enbld.pm

filter: Statementstmt 19.2% 41 / 213 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 18.9% 7 / 37 Podpod 18.1% 4 / 22 totaltotal 14.8% 52 / 351 SCAR 71.9
CC
45
Cov
14%
enbld
56.0
check_targets_in_DSL
42.0
parse_option
42.0
CRAP 1326.8
↑ Summary Enbld/RcFile.pm »
1 package Enbld;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.7039';
11  
12 1 ▶use FindBin qw/$Script/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Try::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 require Exporter;
17 1 our @ISA = qw(Exporter);
18 1 our @EXPORT = qw/
19 enbld
20 build
21 target
22 define
23 version
24 make_test
25 module_file
26 modules
27 arguments
28 annotation
29 conf
30 load
31 copy
32 set
33 from
34 to
35 content
36 /;
37  
38 1 require Enbld::App::Configuration;
39 1 require Enbld::Logger;
40 1 require Enbld::Target;
41 1 require Enbld::Condition;
42 1 require Enbld::Error;
43 1 require Enbld::Exception;
44 1 require Enbld::RcFile;
45 1 require Enbld::Deployed;
46  
47 1 our $initialized;
48 1 our %target_result;
49 1 our %rcfile_result;
50  
51 1 our %rcfile_collection;
52 1 our %target_collection;
53  
54 sub enbld($$) {
55 0 ▶ my ( $envname, $coderef ) = @_;
Subroutine enbld: not called CC=7 SCAR=40.3
Pod undocumented
56  
57 0 ▶ if ( ref( $envname ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $envname) 0 0 0
58 0 _err(
59 "Function 'enbld' first requires " .
60 "string type parameter 'env name'."
61 );
62 }
63  
64 0 ▶ if ( $envname =~ /[^0-9a-zA-Z_]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envname =~ /[^0-9a-zA-Z_]/) 0 0 0
65 0 _err(
66 "Env name '$envname' contains invalid character.",
67 $envname
68 );
69 }
70  
71 0 ▶ if ( ref( $coderef ) ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $coderef ne "CODE") 0 0 0
72 0 _err( "Function 'enbld' second requires code reference parameter." );
73 }
74  
75 0 require Enbld::Message;
76 0 Enbld::Message->set_verbose;
77  
78 0 parse_option();
79  
80 0 require Enbld::Home;
81 0 Enbld::Home->initialize;
82  
83 0 Enbld::App::Configuration->read_file;
84 0 Enbld::App::Configuration->set_envname( $_[0] );
85  
86 0 $initialized++;
87  
88 0 $_[1]->();
89  
90 0 Enbld->_setup_directory;
91  
92 0 foreach my $name ( sort keys %target_collection ) {
93 0 build_target( $name );
94 }
95  
96 0 foreach my $filepath ( sort keys %rcfile_collection ) {
97 0 do_rcfile( $rcfile_collection{$filepath} );
98 }
99  
100 0 undef $initialized;
101  
102 0 show_result_message();
103  
104 0 check_targets_in_DSL();
105  
106 0 ▶ if ( ! Enbld::App::Configuration->is_dirty ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Enbld::App::Configuration"->is_dirty) 0 0 0
107 0 Enbld::Message->notify(
108 "INFO:No builded targets & loaded configuration file."
109 );
110 }
111  
112 0 return 1;
113 }
114  
115 sub build_target {
116 0 ▶ my $name = shift;
Subroutine build_target: not called CC=4 SCAR=30.0
Pod undocumented
117  
118 0 ▶ my $config = Enbld::Feature->is_deploy_mode ? undef :
Branch: 1 branch
BranchTrueFalseTotal
'Enbld::Feature'->is_deploy_mode ? : 0 0 0
119 Enbld::App::Configuration->search_config( $name );
120  
121 0 my $target = Enbld::Target->new( $name, $config );
122  
123 my $installed = try {
124 0 ▶ return Enbld::Feature->is_deploy_mode ?
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
'Enbld::Feature'->is_deploy_mode ? : 0 0 0
125 $target->deploy_declared( \%target_collection ) :
126 $target->install_declared( \%target_collection );
127 } ( 'Enbld::Error' => sub {
128 0 ▶ Enbld::Message->alert( $@ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
129  
130 0 ▶ if ( $^O ne 'darwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O ne "darwin") 0 0 0
131 0 say "If you run Enbld at Linux or BSD, there is a possibility " .
132 "that the Software which depends is not installed.";
133 }
134  
135 0 say "\n" . "Please check build logile:" . Enbld::Logger->logfile;
136  
137 0 $target_result{$name} = $name . ' is failure to build.';
138  
139 0 return;
140 }
141 0 );
142  
143 # Target is installed.
144 0 ▶ if ( $installed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($installed) 0 0 0
145 0 $target_result{$name} = $name . ' ' . $installed->enabled .
146 " is installed.";
147  
148 0 Enbld::App::Configuration->set_config( $installed );
149 0 Enbld::App::Configuration->write_file;
150  
151 0 ▶ if ( Enbld::Feature->is_deploy_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Enbld::Feature"->is_deploy_mode) 0 0 0
152 0 Enbld::Deployed->add( $installed );
153 }
154  
155 0 return $name;
156 }
157  
158 # Target is up-to-date.
159 0 $target_result{$name} = $name . ' is up-to-date.';
160  
161 0 return $name;
162 }
163  
164 sub check_targets_in_DSL {
165  
166 0 ▶ return if Enbld::Feature->is_deploy_mode;
Subroutine check_targets_in_DSL: not called CC=6 SCAR=37.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if "Enbld::Feature"->is_deploy_mode 0 0 0
167  
168 0 my %not_in_dsl;
169 0 foreach my $name ( keys %{ Enbld::App::Configuration->config } ) {
170 0 my $config = Enbld::App::Configuration->search_config( $name );
171  
172 0 ▶ $not_in_dsl{$name}++ unless defined $target_result{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Enbld::target_result{$name} 0 0 0
173 }
174  
175 0 ▶ if ( keys %not_in_dsl ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %not_in_dsl) 0 0 0
176 0 Enbld::Message->notify(
177 "WARN:The following targets are not defined in DSL $Script.\n" .
178 "Please check $Script."
179 );
180  
181 0 foreach my $target ( sort keys %not_in_dsl ) {
182 0 Enbld::Message->notify( " " . $target );
183 }
184 }
185 }
186  
187 sub show_result_message {
188  
189 0 ▶ foreach my $target ( sort keys %target_result ) {
Subroutine show_result_message: not called CC=3 SCAR=24.8
Pod undocumented
190 0 Enbld::Message->notify( $target_result{$target} );
191 }
192  
193 0 foreach my $file ( sort keys %rcfile_result ) {
194 0 Enbld::Message->notify( $rcfile_result{$file} );
195 }
196 }
197  
198 sub build(&) {
199 0 ▶ return $_[0];
Subroutine build: not called CC=1 SCAR=6.9
Pod undocumented
200 }
201  
202 1 our $condition_ref;
203  
204 sub target($$) {
205 0 ▶ my ( $targetname, $coderef ) = @_;
Subroutine target: not called CC=5 SCAR=34.0
Pod documented
206  
207 0 ▶ if ( ! $initialized ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Enbld::initialized) 0 0 0
208 0 _err(
209 "Environment is not initialized.".
210 "Isn't the syntax of DSL possibly mistaken?"
211 );
212 }
213  
214 0 ▶ if ( ref( $targetname ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $targetname) 0 0 0
215 0 _err(
216 "Function 'target' first requsres " .
217 "string type parameter 'target name'."
218 );
219 }
220  
221 0 ▶ if( $targetname =~ /[^0-9a-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($targetname =~ /[^0-9a-z]/) 0 0 0
222 0 _err( "Target name '$targetname' contains invalid character." );
223 }
224  
225 0 ▶ if ( ref( $coderef ) ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $coderef ne "CODE") 0 0 0
226 0 _err( "Function 'target' seconde requires code reference parameter." );
227 }
228  
229 $condition_ref = {
230 0 name => $targetname,
231 };
232  
233 0 $coderef->();
234  
235 0 my $condition = Enbld::Condition->new( %{ $condition_ref } );
236 0 $target_collection{$targetname} = $condition;
237  
238 0 undef $condition_ref;
239 }
240  
241 sub define(&) {
242 0 ▶ my $coderef = shift;
Subroutine define: not called CC=1 SCAR=6.9
Pod undocumented
243  
244 0 return $coderef;
245 }
246  
247 sub version($) {
248 0 ▶ my $version = shift;
Subroutine version: not called CC=2 SCAR=17.9
Pod documented
249  
250 0 ▶ if ( ref( $version ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $version) 0 0 0
251 0 _err( "Function 'version' requires string type parameter." );
252 }
253  
254 0 $condition_ref->{version} = $version;
255 }
256  
257 sub make_test(;$) {
258 0 ▶ my $make_test = shift;
Subroutine make_test: not called CC=4 SCAR=30.0
Pod undocumented
259  
260 0 ▶ if ( $make_test && ref( $make_test ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($make_test and ref $make_test) 0 0 0
Condition0%0/3
$make_test and ref $make_test
!ll&&!rl&&r
000
MC/DC0%0/2
$make_test and ref $make_test
$make_test ref $make_test
Truth table0%0/3
A and B
A= $make_testB= ref $make_test
ABresult
0X0
100
111
261 0 _err( "Function 'make_test' requires string type parameter." );
262 }
263  
264 0 ▶ $condition_ref->{make_test} = $make_test if $make_test;
Branch: 1 branch
BranchTrueFalseTotal
if $make_test 0 0 0
265 }
266  
267 sub arguments($) {
268 0 ▶ my $arguments = shift;
Subroutine arguments: not called CC=2 SCAR=17.9
Pod undocumented
269  
270 0 ▶ if ( ref( $arguments ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arguments) 0 0 0
271 0 _err( "Function 'arguments' requires string type parameter." );
272 }
273  
274 0 $condition_ref->{arguments} = $arguments;
275 }
276  
277 sub annotation($) {
278 0 ▶ my $annotation = shift;
Subroutine annotation: not called CC=2 SCAR=17.9
Pod undocumented
279  
280 0 ▶ if ( ref( $annotation ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $annotation) 0 0 0
281 0 _err( "Function 'annotation' requires string type parameter." );
282 }
283  
284 0 $condition_ref->{annotation} = $annotation;
285 }
286  
287 sub module_file($) {
288 0 ▶ my $module_file = shift;
Subroutine module_file: not called CC=2 SCAR=17.9
Pod undocumented
289  
290 0 ▶ if ( ref( $module_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $module_file) 0 0 0
291 0 _err( "Function 'module_file' requires string type parameter." );
292 }
293  
294 0 $condition_ref->{module_file} = $module_file;
295 }
296  
297 sub modules {
298 0 ▶ croak "'modules' function is deparecated. Please use 'module_file'.";
Subroutine modules: not called CC=1 SCAR=6.9
Pod undocumented
299 }
300  
301 1 our $rcfile_condition;
302 sub conf($$) {
303 0 ▶ my ( $filepath, $coderef ) = @_;
Subroutine conf: not called CC=5 SCAR=34.0
Pod undocumented
304  
305 0 ▶ if ( ! $initialized ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Enbld::initialized) 0 0 0
306 0 _err(
307 "Environment is not initialized.".
308 "Isn't the syntax of DSL possibly mistaken?"
309 );
310 }
311  
312 0 ▶ if ( ref( $filepath ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filepath) 0 0 0
313 0 _err( "Function 'conf' first requires string type parameter." );
314 }
315  
316 0 ▶ if ( $filepath =~ /\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filepath =~ /\s/) 0 0 0
317 0 _err(
318 "Configuration file path parameter must " .
319 "not contain space character."
320 );
321 }
322  
323 0 ▶ if ( ref( $coderef ) ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $coderef ne "CODE") 0 0 0
324 0 _err( "Function 'conf' requires code reference type parameter." );
325 }
326  
327 0 $coderef->();
328  
329 0 $rcfile_condition->{filepath} = $filepath;
330 0 $rcfile_collection{$filepath} = Enbld::RcFile->new( %{ $rcfile_condition } );
331  
332 0 undef $rcfile_condition;
333 }
334  
335 sub do_rcfile {
336 0 ▶ my $rcfile = shift;
Subroutine do_rcfile: not called CC=2 SCAR=17.9
Pod undocumented
337  
338 my $result = try {
339 0 ▶ return $rcfile->do;
Subroutine __ANON__: not called CC=1 SCAR=6.9
340 } ( 'Enbld::Error' => sub {
341 0 ▶ Enbld::Message->alert( $@ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
342  
343 0 say "\n" . "Please check build logile:" . Enbld::Logger->logfile;
344  
345 0 $rcfile_result{$rcfile->filepath} =
346 $rcfile->filepath . ' is failure to create.';
347  
348 0 return;
349 }
350 0 );
351  
352 # Configuration file is loaded or set.
353 0 ▶ if ( $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
354  
355 0 Enbld::App::Configuration->set_rcfile( $rcfile );
356 0 Enbld::App::Configuration->write_file;
357  
358 0 $rcfile_result{$rcfile->filepath} =
359 $rcfile->filepath . ' is created.';
360  
361 0 return $result;
362 }
363  
364 # Configuration file is not loaded or set.
365 0 $rcfile_result{$rcfile->filepath} =
366 $rcfile->filepath . ' is not created.';
367  
368 0 return;
369 }
370  
371 sub load(&) {
372 0 ▶ $rcfile_condition->{command} = 'load';
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
373  
374 0 return $_[0];
375 }
376  
377 sub set(&) {
378 0 ▶ $rcfile_condition->{command} = 'set';
Subroutine set: not called CC=1 SCAR=6.9
Pod undocumented
379  
380 0 return $_[0];
381 }
382  
383 sub copy(&) {
384 0 ▶ $rcfile_condition->{command} = 'copy';
Subroutine copy: not called CC=1 SCAR=6.9
Pod undocumented
385  
386 0 return $_[0];
387 }
388  
389 sub from($) {
390 0 ▶ my $from = shift;
Subroutine from: not called CC=2 SCAR=17.9
Pod documented
391  
392 0 ▶ if ( ref( $from ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $from) 0 0 0
393 0 _err( "Function 'from' requsres string type parameter." );
394 }
395  
396 0 $rcfile_condition->{from} = $from;
397 }
398  
399 sub to($) {
400 0 ▶ my $to = shift;
Subroutine to: not called CC=3 SCAR=24.8
Pod documented
401  
402 0 ▶ if ( ref( $to ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to) 0 0 0
403 0 _err( "Function 'to' requsres string type parameter." );
404 }
405  
406 0 ▶ if ( $to =~ /\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to =~ /\s/) 0 0 0
407 0 _err( "Function 'to' must not contain space character." );
408 }
409  
410 0 $rcfile_condition->{directory} = $to;
411 }
412  
413 sub content($) {
414 0 ▶ my $content = shift;
Subroutine content: not called CC=2 SCAR=17.9
Pod undocumented
415  
416 0 ▶ if ( ref( $content ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content) 0 0 0
417 0 _err( "Function 'content' reuqires string type parameter." );
418 }
419  
420 0 chomp( $content );
421  
422 0 $rcfile_condition->{contents} .= $content . "\n";
423 }
424  
425 1 our $setuped;
426 sub _setup_directory {
427  
428 0 ▶ unless ( $setuped ) {
Subroutine _setup_directory: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ($Enbld::setuped) 0 0 0
429 0 Enbld::Home->create_build_directory;
430 0 Enbld::Logger->rotate( Enbld::Home->log );
431  
432 0 $setuped++;
433 }
434 }
435  
436 sub parse_option {
437  
438 0 ▶ my $make_test;
Subroutine parse_option: not called CC=6 SCAR=37.4
Pod undocumented
439 my $force;
440 0 my $deploy_path;
441  
442 0 Getopt::Long::Configure( "bundling" );
443 Getopt::Long::GetOptions(
444 0 ▶ 't|test' => sub { $make_test++ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
445 0 ▶ 'f|force' => sub { $force++ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
446 0 'd|deploy=s' => \$deploy_path,
447 );
448  
449 ### to absolute path
450 0 ▶ if ( $deploy_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deploy_path) 0 0 0
451 0 ▶ unless ( File::Spec->file_name_is_absolute( $deploy_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($deploy_path)) 0 0 0
452 0 $deploy_path = File::Spec->rel2abs( $deploy_path );
453 }
454 }
455  
456 0 require Enbld::Feature;
457 0 Enbld::Feature->initialize(
458 make_test => $make_test,
459 force => $force,
460 deploy => $deploy_path,
461 );
462  
463 0 ▶ if ( Enbld::Feature->is_deploy_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Enbld::Feature"->is_deploy_mode) 0 0 0
464 0 Enbld::Message->notify(
465 "INFO:Enbld is set 'deploy mode'.\n" .
466 "All targets will be deployed in $deploy_path."
467 );
468 }
469  
470 0 ▶ if ( Enbld::Feature->is_make_test_all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Enbld::Feature"->is_make_test_all) 0 0 0
471 0 Enbld::Message->notify(
472 "INFO:Enbld is set 'make test mode'.\n" .
473 "All targets will be tested."
474 );
475 }
476  
477 0 ▶ if ( Enbld::Feature->is_force_install ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Enbld::Feature"->is_force_install) 0 0 0
478 0 Enbld::Message->notify(
479 "INFO:Enbld is set 'force install mode'.\n" .
480 "All targets will be builded by force."
481 );
482 }
483  
484 }
485  
486 sub _err {
487 0 ▶ my ( $msg, $param ) = @_;
Subroutine _err: not called CC=1 SCAR=6.9
488  
489 0 Enbld::Error->throw( $msg, $param );
490 }
491  
492 1 1;
493  
494 __END__
↑ Summary Enbld/RcFile.pm »