Enbld/Command.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 63 SCAR 30.0
CC
4
Cov
0%
validate_target_name
12.0
new
6.0
setup
2.0
CRAP 20.0
1 package Enbld::Command;
2  
3 use strict;
4 use warnings;
5  
6 use Module::Load;
7 use Module::Load::Conditional qw/can_load/;
8  
9 require Enbld::Message;
10 require Enbld::Home;
11 require Enbld::Logger;
12 require Enbld::App::Configuration;
13  
14 sub new {
15 my $class = shift;
16  
17 my $self = {
18 cmd => undef,
19 argv => undef,
20 @_,
21 };
22  
23 my $module = 'Enbld::Command::' . ucfirst( $self->{cmd} );
24  
25 return bless $self, $module if can_load( modules => { $module => undef } );
26  
27 die 'ERROR:Unknown command:' . $self->{cmd} . "\n";
28 }
29  
30 sub setup {
31 Enbld::Home->initialize;
32 Enbld::Home->create_build_directory;
33 Enbld::Logger->rotate( Enbld::Home->log );
34  
35 Enbld::App::Configuration->read_file;
36 }
37  
38 sub teardown {
39 Enbld::App::Configuration->write_file;
40 }
41  
42 sub validate_target_name {
43 my ( $self, $target_name ) = @_;
44  
45 if ( ! $target_name ) {
46 die "ERROR:'$self->{cmd}' command requires target's name argument.\n";
47 }
48  
49 if ( $target_name =~ /[^a-z0-9]/ ) {
50 die "ERROR:target's name '$target_name' is invalid.\n";
51 }
52  
53 return $target_name;
54 }
55  
56 1;