| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Sky::Config::Validate; |
|
2
|
|
|
|
|
|
|
$App::Sky::Config::Validate::VERSION = '0.4.1'; |
|
3
|
1
|
|
|
1
|
|
77070
|
use strict; |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
23
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
476
|
use Moo; |
|
|
1
|
|
|
|
|
9290
|
|
|
|
1
|
|
|
|
|
5
|
|
|
10
|
1
|
|
|
1
|
|
1560
|
use MooX 'late'; |
|
|
1
|
|
|
|
|
8336
|
|
|
|
1
|
|
|
|
|
5
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
21179
|
use Scalar::Util qw(reftype); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
58
|
|
|
13
|
1
|
|
|
1
|
|
593
|
use List::MoreUtils qw(notall); |
|
|
1
|
|
|
|
|
10455
|
|
|
|
1
|
|
|
|
|
7
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'config' => ( isa => 'HashRef', is => 'ro', required => 1, ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _sorted_keys |
|
19
|
|
|
|
|
|
|
{ |
|
20
|
2
|
|
|
2
|
|
4
|
my $hash_ref = shift; |
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
8
|
return sort { $a cmp $b } keys(%$hash_ref); |
|
|
3
|
|
|
|
|
7
|
|
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _validate_section |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
3
|
|
|
3
|
|
6
|
my ( $self, $site_name, $sect_name, $sect_conf ) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
4
|
foreach my $string_key (qw( basename_re target_dir)) |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
6
|
|
|
|
|
10
|
my $v = $sect_conf->{$string_key}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
6
|
50
|
33
|
|
|
28
|
if ( |
|
|
|
|
33
|
|
|
|
|
|
34
|
|
|
|
|
|
|
not( defined($v) |
|
35
|
|
|
|
|
|
|
&& ref($v) eq '' |
|
36
|
|
|
|
|
|
|
&& $v =~ /\S/ ) |
|
37
|
|
|
|
|
|
|
) |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
0
|
|
|
|
|
0
|
die |
|
40
|
|
|
|
|
|
|
"Section '$sect_name' at site '$site_name' must contain a non-empty $string_key"; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
4
|
return; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _validate_site |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
1
|
|
|
1
|
|
3
|
my ( $self, $site_name, $site_conf ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
my $base_upload_cmd = $site_conf->{base_upload_cmd}; |
|
52
|
1
|
50
|
|
|
|
4
|
if ( ref($base_upload_cmd) ne 'ARRAY' ) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
0
|
|
|
|
|
0
|
die "base_upload_cmd for site '$site_name' is not an array."; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
5
|
|
13
|
if ( notall { defined($_) && ref($_) eq '' } @$base_upload_cmd ) |
|
|
5
|
50
|
|
|
|
16
|
|
|
58
|
|
|
|
|
|
|
{ |
|
59
|
0
|
|
|
|
|
0
|
die "base_upload_cmd for site '$site_name' must contain only strings."; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
5
|
foreach my $kk (qw(dest_upload_prefix dest_upload_url_prefix)) |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
2
|
|
|
|
|
5
|
my $s = $site_conf->{$kk}; |
|
65
|
2
|
50
|
33
|
|
|
16
|
if ( not( defined($s) && ( ref($s) eq '' ) && ( $s =~ m/\S/ ) ) ) |
|
|
|
|
33
|
|
|
|
|
|
66
|
|
|
|
|
|
|
{ |
|
67
|
0
|
|
|
|
|
0
|
die "$kk for site '$site_name' is not a string."; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
2
|
my $sections = $site_conf->{sections}; |
|
72
|
1
|
50
|
|
|
|
4
|
if ( ref($sections) ne 'HASH' ) |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
0
|
|
|
|
|
0
|
die "Sections for site '$site_name' is not a hash."; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
2
|
foreach my $sect_name ( _sorted_keys($sections) ) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
$self->_validate_section( $site_name, $sect_name, |
|
80
|
3
|
|
|
|
|
9
|
$sections->{$sect_name} ); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
3
|
return; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub is_valid |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
1
|
|
|
1
|
1
|
2284
|
my ($self) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
8
|
my $config = $self->config(); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Validate the configuration |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
1
|
50
|
|
|
|
2
|
if ( !exists( $config->{default_site} ) ) |
|
|
1
|
|
|
|
|
5
|
|
|
95
|
|
|
|
|
|
|
{ |
|
96
|
0
|
|
|
|
|
0
|
die "A 'default_site' key must be present in the configuration."; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
my $sites = $config->{sites}; |
|
100
|
1
|
50
|
|
|
|
4
|
if ( ref($sites) ne 'HASH' ) |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
0
|
|
|
|
|
0
|
die "sites key must be a hash."; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
13
|
foreach my $name ( _sorted_keys($sites) ) |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
1
|
|
|
|
|
12
|
$self->_validate_site( $name, $sites->{$name} ); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
2
|
return; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |