Sky/Config/Validate.pm

filter: Statementstmt 84.0% 58 / 69 Branchbran 40.9% 9 / 22 Conditioncond 26.6% 4 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 66.1% 84 / 127 CC 23 SCAR 28.1
CC
23
Cov
67%
_validate_section
37.1
_validate_site
14.0
is_valid
4.3
CRAP 16.6
« Sky/CmdLine.pm ↑ Summary Sky/Module.pm »
1 package App::Sky::Config::Validate;
2 3 $App::Sky::Config::Validate::VERSION = '0.8.0';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use List::MoreUtils qw(notall);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 has 'config' => ( isa => 'HashRef', is => 'ro', required => 1, );
16  
17  
18 sub _sorted_keys
19 2 ▶{
Subroutine _sorted_keys: called CC=1 SCAR=0.0
20 2 my $hash_ref = shift;
21  
22 2 my @ret = sort { $a cmp $b } keys(%$hash_ref);
23  
24 2 return @ret;
25 }
26  
27 sub _validate_section
28 3 ▶{
Subroutine _validate_section: called CC=11 SCAR=36.1
29 3 my ( $self, $site_name, $sect_name, $sect_conf ) = @_;
30  
31 3 foreach my $string_key (qw( basename_re target_dir))
32 {
33 6 my $v = $sect_conf->{$string_key};
34  
35 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v and ref $v eq "" and $v =~ /\S/) 0 6 6
Condition33%2/6
defined $v and ref $v eq "" and $v =~ /\S/
!ll&&!rl&&r
006
defined $v and ref $v eq ""
!ll&&!rl&&r
006
MC/DC0%0/3
defined $v and ref $v eq "" and $v =~ /\S/
defined $v ref $v eq "" $v =~ /\S/
Truth table25%1/4
A and B and C
A= defined $vB= ref $v eq ""C= $v =~ /\S/
ABCresult
0XX0
10X0
1100
1111
36 not( defined($v)
37 && ref($v) eq ''
38 && $v =~ /\S/ )
39 )
40 {
41 0 die
42 "Section '$sect_name' at site '$site_name' must contain a non-empty $string_key";
43 }
44 }
45  
46 OVER:
47 3 foreach my $string_key (qw( overrides ))
48 {
49 3 my $v = $sect_conf->{$string_key};
50 3 ▶ next OVER if !defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 3 0 3
51 0 foreach my $kk (qw(dest_upload_prefix dest_upload_url_prefix))
52 {
53 0 my $s = $v->{$kk};
54 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $s ? ref $s eq "" && $s =~ /\S/ : 1) 0 0 0
defined $s ? : 0 0 0
Condition0%0/3
ref $s eq "" and $s =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $s eq "" and $s =~ /\S/
ref $s eq "" $s =~ /\S/
Truth table0%0/3
A and B
A= ref $s eq ""B= $s =~ /\S/
ABresult
0X0
100
111
55 not(
56 defined($s) ? ( ( ref($s) eq '' ) && ( $s =~ m/\S/ ) ) : 1 )
57 )
58 {
59 0 die "$kk for section '$sect_name' is not a string.";
60 }
61 }
62 }
63 3 return;
64 }
65  
66 sub _validate_site
67 1 ▶{
Subroutine _validate_site: called CC=9 SCAR=26.4
68 1 my ( $self, $site_name, $site_conf ) = @_;
69  
70 1 my $base_upload_cmd = $site_conf->{base_upload_cmd};
71 1 ▶ if ( ref($base_upload_cmd) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $base_upload_cmd ne "ARRAY") 0 1 1
72 {
73 0 die "base_upload_cmd for site '$site_name' is not an array.";
74 }
75  
76 1 ▶ if ( notall { defined($_) && ref($_) eq '' } @$base_upload_cmd )
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
BranchTrueFalseTotal
if (&notall(sub { defined $_ and ref $_ eq ""; } , @$base_upload_cmd)) 0 1 1
defined $_ and ref $_ eq "" 5 0 5
77 {
78 0 die "base_upload_cmd for site '$site_name' must contain only strings.";
79 }
80  
81 1 foreach my $kk (qw(dest_upload_prefix dest_upload_url_prefix))
82 {
83 2 my $s = $site_conf->{$kk};
84 2 ▶ if ( not( defined($s) && ( ref($s) eq '' ) && ( $s =~ m/\S/ ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s and ref $s eq "" and $s =~ /\S/) 0 2 2
Condition33%2/6
defined $s and ref $s eq "" and $s =~ /\S/
!ll&&!rl&&r
002
defined $s and ref $s eq ""
!ll&&!rl&&r
002
MC/DC0%0/3
defined $s and ref $s eq "" and $s =~ /\S/
defined $s ref $s eq "" $s =~ /\S/
Truth table25%1/4
A and B and C
A= defined $sB= ref $s eq ""C= $s =~ /\S/
ABCresult
0XX0
10X0
1100
1111
85 {
86 0 die "$kk for site '$site_name' is not a string.";
87 }
88 }
89  
90 1 my $sections = $site_conf->{sections};
91 1 ▶ if ( ref($sections) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sections ne "HASH") 0 1 1
92 {
93 0 die "Sections for site '$site_name' is not a hash.";
94 }
95  
96 1 foreach my $sect_name ( _sorted_keys($sections) )
97 {
98 $self->_validate_section( $site_name, $sect_name,
99 3 $sections->{$sect_name} );
100 }
101  
102 1 return;
103 }
104  
105 sub is_valid
106 1 ▶{
Subroutine is_valid: called CC=4 SCAR=14.6
Pod documented
107 1 my ($self) = @_;
108  
109 1 my $config = $self->config();
110  
111 # Validate the configuration
112 {
113 1 ▶ if ( !exists( $config->{default_site} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $config->{"default_site"}) 0 1 1
114 {
115 0 die "A 'default_site' key must be present in the configuration.";
116 }
117  
118 1 my $sites = $config->{sites};
119 1 ▶ if ( ref($sites) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sites ne "HASH") 0 1 1
120 {
121 0 die "sites key must be a hash.";
122 }
123  
124 1 foreach my $name ( _sorted_keys($sites) )
125 {
126 1 $self->_validate_site( $name, $sites->{$name} );
127 }
128 }
129  
130 1 return;
131 }
132  
133 3 1;
134  
135 __END__
« Sky/CmdLine.pm ↑ Summary Sky/Module.pm »