| 1 | package Schedule::Pluggable::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | has JobsPlugin => ( is => 'rw', | |||||||||||||||||||||||||||
| 10 | isa => 'Str', | ||||||||||||||||||||||||||||
| 11 | reader => '_get_JobsPlugin', | ||||||||||||||||||||||||||||
| 12 | default => 'JobsFromData', | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | after BUILD => sub { | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | 0 | $self->load_plugins( $self->_get_JobsPlugin ); | |||||||||||||||||||||||||||
| 19 | 3 | }; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Gets the job config via the plugin method get_job_config, validates it, works out the dependencies | ||||||||||||||||||||||||||||
| 22 | sub _validate_config { | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my ($self, $params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_validate_config: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||
| 24 | 0 | my $job_config = $self->get_job_config($params); # get_job_config from JobsPlugin | |||||||||||||||||||||||||||
| 25 | 0 | my $status = $self->_get_status(); | |||||||||||||||||||||||||||
| 26 | 0 | my %prerequisites = (); | |||||||||||||||||||||||||||
| 27 | 0 | my $jobs = []; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (ref ($job_config) eq "HASH") { # if we get passed a hash - convert it into an array of hashes | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 29 | 0 | foreach my $job_name (sort keys %{ $job_config }) { | |||||||||||||||||||||||||||
| 30 | 0 | my %j = %{ $job_config->{$job_name} }; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | $j{name} ||= $job_name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$j{"name"} ||= $job_name
MC/DC0%0/2
$j{"name"} ||= $job_name
$j{"name"}
$job_name
Truth table0%0/3
A ||= B
A= $j{"name"}B= $job_name
| |||||||||||||||||||||||||||||
| 32 | 0 | push(@{ $jobs }, { %j }); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | elsif (ref ($job_config) eq "ARRAY") { | ||||||||||||||||||||||||||||
| 36 | 0 | $jobs = $job_config; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 0 | croak "Invalid jobs specification supplied via ".$self->get_JobsPlugin." : must be a reference to an array or a hash not ".Data::Dumper->Dump([$job_config],[qw/$job_config/]); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # First, setup the groups | ||||||||||||||||||||||||||||
| 43 | 0 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 44 | 0 | $status->{Groups}{ $job->{name} }{ $job->{name} } = 1; | |||||||||||||||||||||||||||
| 45 | 0 | my @groups = $self->_get_values($job->{groups}, $job->{group}); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | map { $status->{Groups}{ $_ }{ $job->{name} } = 1; } @groups if @groups; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 49 | 0 | $status->{Groups}{ $job->{name} }{ $job->{name} } = 1; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($job->{dependencies}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my @dependencies = $self->_get_values( $job->{dependencies} ); | |||||||||||||||||||||||||||
| 52 | 0 | foreach my $dependency (@dependencies) { | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($status->{ Groups }{ $dependency }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | map { $prerequisites{ $_ }{ $job->{name} } = undef; } keys %{ $status->{Groups}{$dependency} }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 0 | $prerequisites{ $job->{name} } { $dependency } = undef; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 63 | 0 | my $job_name = $job->{name}; | |||||||||||||||||||||||||||
| 64 | 0 | $status->{Jobs}{ $job_name } = { %{ $job } }; | |||||||||||||||||||||||||||
| 65 | 0 | $status->{TotalJobs}++; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($job->{prerequisites} or $prerequisites{ $job_name }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$job->{"prerequisites"} or $prerequisites{$job_name}
MC/DC0%0/2
$job->{"prerequisites"} or $prerequisites{$job_name}
$job->{"prerequisites"}
$prerequisites{$job_name}
Truth table0%0/3
A or B
A= $job->{"prerequisites"}B= $prerequisites{$job_name}
| |||||||||||||||||||||||||||||
| 67 | 0 | my @prerequisites = $self->_get_values( $job->{prerequisites}, keys %{ $prerequisites{ $job_name } } ); | |||||||||||||||||||||||||||
| 68 | 0 | foreach my $prerequisite (@prerequisites) { | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($status->{Groups}{$prerequisite}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | map { $prerequisites{ $job->{name} }{ $_ } = undef; } keys %{ $status->{Groups}{$prerequisite} }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | $prerequisites{ $job->{name} }{ $prerequisite } = undef; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | 0 | $status->{Jobs}{ $job_name }->{ pending_prerequisites } = 0; | |||||||||||||||||||||||||||
| 79 | 0 | $status->{Ready_to_Run}{$job_name} = { %{ $job } }; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $status->{Jobs}{ $job_name }->{ prerequisites } = { %{ $prerequisites{ $job_name } } } if $prerequisites{ $job_name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $status->{Jobs}{ $job_name }->{ pending_prerequisites } = scalar( keys ( %{ $prerequisites{ $job_name } } ) ) if $prerequisites{ $job_name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | delete $status->{Jobs}{ $job_name }->{ dependencies }; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | return $status; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | sub _get_values { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_get_values: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 90 | 0 | my @values = (); | |||||||||||||||||||||||||||
| 91 | 0 | foreach my $what (@_) { | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | next unless $what; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | push (@values, @{ $what }) if ref $what eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | push (@values, values %{ $what }) if ref $what eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | push (@values, $what) if ref $what eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | return @values; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 3 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 3 | 1; | |||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 NAME | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Schedule::Pluggable::Config - Moose Role to provide methods to validate the Schedule config | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Moose Role to add method to Schedule::Pluggable to provide methods to validate the Schedule config- not runnable on it's own | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 METHODS | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | No public methods | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||