Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.70 KB | None | 0 0
  1.     method valid_task {
  2.         shift;
  3.         my $r_task = shift;
  4.         return unless defined $r_task;
  5.         my %h_task = %{$r_task};
  6.         my %h_attrs;
  7.  
  8.         #--- Schedule tag
  9.         if ( !defined $h_task{'schedule'} ) {
  10.             $self->error_log->push('A "schedule" tag is required');
  11.             return 0;    
  12.         }
  13.         %h_attrs = %{ $h_task{'schedule'}[0] };
  14.         my %h_schedule_id;
  15.         foreach (keys %h_attrs) {
  16.             if (/^id$/) {
  17.                 #--- Schedule id's must be unique
  18.                 if (defined $h_schedule_id{'id'}) {
  19.                     $self->error_log->push('Schedule id "'.$h_schedule_id{'id'}.'" is already defined');
  20.                     return 0;
  21.                 }
  22.                 $h_schedule_id{'id'}++;    
  23.             } elsif (/^time$/) {
  24.                 #--- A time attribute can have a list of time specifications
  25.                 my $s_time_spec = &Utils::trim( $h_attrs{'time'} );
  26.                 if ($s_time_spec eq '') {
  27.                     $self->error_log->push('Time specification empty');
  28.                     return 0;    
  29.                 }
  30.                 my @a_time_list = split /$LIST_SEPARATOR/, $s_time_spec;
  31.                 foreach (@a_time_list) {
  32.                     if ( !&Utils::valid_time ($_) ) {
  33.                         print 'Time specification "'.$_.'" invalid';
  34.                         $self->error_log->push('Time specification "'.$_.'" invalid');
  35.                         return 0;    
  36.                     }
  37.                 }
  38.             } else {
  39.                 $self->error_log->push('Tag "'.$_.'" not recognized');
  40.                 return 0;
  41.             }
  42.         }
  43.        
  44.         return 1;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement