package Ernad::State; use strict; use warnings; use base 'Ernad'; use Carp qw(confess); use Data::Dumper; ## a placeholder for how to start sub empty { my $s=shift; my $repcode // confess "I need a repcode here."; my $issuedate // confess "I need an issuedate here."; my $e=$s->{'e'} // $main::e // confess "Where is my erimp?"; } ## Futility is only important in Presort, it could go to the ## Presort modules sub is_futile { my $s=shift; my $repcode=shift // confess "I need a repcode here."; my $issuedate=shift // confess "I need an issuedate here."; my $e=$s->{'e'} // $main::e // confess "Where is my erimp?"; my $report_dir=$e->{'report'}->{$repcode}->{'path'} or confess "I need a report_dir here"; foreach my $stage (@{$e->{'const'}->{'stages'}}) { if($stage eq 'source') { next; } my $stage_dir=$report_dir.'/'.$stage; ## FixMe, should use dir module for this foreach my $ext ('.amf.xml','.amf.xml.gz') { my $glob=$stage_dir.'/'.$issuedate.'_*'.$ext; $e->echo(__LINE__,"I am looking for '$glob'",20); my @files=glob($glob); my $file=$files[0] or next; return 1; } } return 0; } ## obsolete, replaced by next function sub is_done { my $s=shift; my $e=$s->{'e'} // $main::e // confess "Where is my erimp?"; my $repcode=shift or confess "I need a repccode here.\n"; my $issuedate=shift or confess "I need an issuedate here.\n"; ## cache the done_dates of the report so as to make this a bit ## more efficent my $rerc=$e->{'report'}->{$repcode} // {}; ## this is zero or one. If it's zero, let's check further. If ## it's one it's likely to stay one. if($rerc->{'dates'}->{'done'}) { ## the above needs to be defined and set to 1 return 1; } my $report_dir=$e->{'report'}->{$repcode}->{'dir'}; if(not $report_dir) { $e->{'r'}->load($repcode); } my $sent_dir=$e->{'report'}->{$repcode}->{'dir'}->{'sent'} or confess "I need a sent_dir for $repcode here."; #my $sent_dir=$report_dir.'/'.$e->{'const'}->{'sent_dir'}; foreach my $ext ('.amf.xml','.amf.xml.gz') { my $glob=$sent_dir.'/'.$issuedate.'_*'.$ext; $e->echo(__LINE__,"I am looking for '$glob'",4); my @files=glob($glob); my $file=$files[0]; if($file) { $rerc->{'dates'}->{'done'}->{$issuedate}=1; return 1; } } $rerc->{'dates'}->{'done'}->{$issuedate}=0; return 0; } ## reports on files done for a repcode at issuedate for stage sub stage_done { my $s=shift; my $e=$s->{'e'} // $main::e // confess "Where is my erimp?"; my $repcode=shift or confess "I need a repccode here.\n"; my $issuedate=shift or confess "I need an issuedate here.\n"; my $stage=shift or confess "I need a stage what to look for here.\n"; ## cache the done_dates of the report so as to make this a bit ## more efficent my $rerc=$e->{'report'}->{$repcode} // {}; ## this is zero or one. If it's zero, let's check further. If ## it's one it's likely to stay one. if($rerc->{'dates'}->{$stage}->{$issuedate}) { ## the above negreeeds to be defined and set to 1 return $rerc->{'dates'}->{$stage}->{$issuedate}; } my $report_dir=$e->{'report'}->{$repcode}->{'dir'}; if(not $report_dir) { $e->{'r'}->load($repcode); } my $stage_dir=$e->{'report'}->{$repcode}->{'dir'}->{$stage} or confess "I need a $stage dir for $repcode here."; foreach my $ext ('.amf.xml','.amf.xml.gz') { my $glob=$stage_dir.'/'.$issuedate.'_*'.$ext; $e->echo(__LINE__,"I am looking for '$glob'",4); my @files=glob($glob); my $total_files = scalar @files; $rerc->{'dates'}->{$stage}->{$issuedate}=$total_files; return $total_files; } $rerc->{'dates'}->{$stage}->{$issuedate}=0; return 0; } 1;