| 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 | 1 | ▶ | after BUILD => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 18 | 1 | $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 | 1 | ▶ | sub _validate_config { | ||||||||||||||||||||||||||
|
Subroutine
_validate_config: called CC=18 SCAR=41.7
| |||||||||||||||||||||||||||||
| 23 | 1 | my ($self, $params) = @_; | |||||||||||||||||||||||||||
| 24 | 1 | my $job_config = $self->get_job_config($params); # get_job_config from JobsPlugin | |||||||||||||||||||||||||||
| 25 | 1 | my $status = $self->_get_status(); | |||||||||||||||||||||||||||
| 26 | 1 | my %prerequisites = (); | |||||||||||||||||||||||||||
| 27 | 1 | my $jobs = []; | |||||||||||||||||||||||||||
| 28 | 1 | ▶ | 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 | 1 | $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 | 1 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 44 | 1 | $status->{Groups}{ $job->{name} }{ $job->{name} } = 1; | |||||||||||||||||||||||||||
| 45 | 1 | 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 | 1 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 49 | 1 | $status->{Groups}{ $job->{name} }{ $job->{name} } = 1; | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | 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 | 1 | foreach my $job (@{ $jobs }) { | |||||||||||||||||||||||||||
| 63 | 1 | my $job_name = $job->{name}; | |||||||||||||||||||||||||||
| 64 | 1 | $status->{Jobs}{ $job_name } = { %{ $job } }; | |||||||||||||||||||||||||||
| 65 | 1 | $status->{TotalJobs}++; | |||||||||||||||||||||||||||
| 66 | 1 | ▶ | if ($job->{prerequisites} or $prerequisites{ $job_name }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$job->{"prerequisites"} or $prerequisites{$job_name}
MC/DC0%0/2
$job->{"prerequisites"} or $prerequisites{$job_name}
$job->{"prerequisites"}
$prerequisites{$job_name}
Truth table33%1/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 | 1 | $status->{Jobs}{ $job_name }->{ pending_prerequisites } = 0; | |||||||||||||||||||||||||||
| 79 | 1 | $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 | 1 | delete $status->{Jobs}{ $job_name }->{ dependencies }; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 1 | return $status; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub _get_values { | ||||||||||||||||||||||||||
|
Subroutine
_get_values: called CC=6 SCAR=28.1
| |||||||||||||||||||||||||||||
| 89 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 1 | my @values = (); | |||||||||||||||||||||||||||
| 91 | 1 | foreach my $what (@_) { | |||||||||||||||||||||||||||
| 92 | 2 | ▶ | 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 | 1 | return @values; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 3 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 3 | 1; | |||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||