| 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
Condition33%2/6
defined $v and ref $v eq "" and $v =~ /\S/
defined $v and ref $v eq ""
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $s eq "" and $s =~ /\S/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $s and ref $s eq "" and $s =~ /\S/
defined $s and ref $s eq ""
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||