@@ -8,6 +8,7 @@ use strict;
88my $task_uuid = ' TaskQueue-Task' ;
99
1010my @fields = qw/ _command _argstring _args _timestamp _uuid _child_timeout _started _pid _retries _userdata/ ;
11+ my @must_be_defined_fields = grep { $_ ne ' _pid' && $_ ne ' _started' } @fields ;
1112
1213# These methods are intended to help document the importance of the message and to supply 'seam' that
1314# could be used to modify the logging behavior of the TaskQueue.
@@ -81,26 +82,24 @@ sub reconstitute {
8182
8283 return unless defined $hash ;
8384 return $hash if ref $hash eq $class ;
85+
8486 $class -> _throw(' Argument is not a hash reference.' ) unless ref {} eq ref $hash ;
87+ if ( my $field = ( grep { !defined $hash -> {$_ } } @must_be_defined_fields )[0] ) {
8588
86- foreach my $field ( @fields ) {
89+ # We only care about the the first one since we throw
8790 $class -> _throw(" Missing '$field ' field in supplied hash" ) unless exists $hash -> {$field };
88- next if $field eq ' _pid' or $field eq ' _started' ;
89- $class -> _throw(" Field '$field ' has no value" ) unless defined $hash -> {$field };
91+ $class -> _throw(" Field '$field ' has no value" );
9092 }
93+ $class -> _throw(" Missing '_pid' field in supplied hash" ) unless exists $hash -> {_pid };
94+ $class -> _throw(" Missing '_started' field in supplied hash" ) unless exists $hash -> {_started };
9195 $class -> _throw(q{ The '_args' field must be an array} ) unless ref [] eq ref $hash -> {_args };
9296
93- my %object ;
94- foreach my $field (@fields ) {
95- if ( ref [] eq ref $hash -> {$field } ) {
96- $object {$field } = [ @{ $hash -> {$field } } ];
97- }
98- else {
99- $object {$field } = $hash -> {$field };
100- }
101- }
97+ return bless {
98+ %$hash ,
10299
103- return bless \%object , $class ;
100+ # _args needs a bit more do do a clone
101+ ' _args' => [ @{ $hash -> {' _args' } } ]
102+ }, $class ;
104103}
105104
106105# Make a copy of the task description.
0 commit comments