diff options
| author | fukachan <fukachan> | 2003-03-16 10:44:40 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-03-16 10:44:40 +0000 |
| commit | 82bb28981ac79e3f4017b396d2f627eaf4896182 (patch) | |
| tree | cf3cb4169f78841bd3952f97d933f67266d6069d /fml/lib/FML/Article.pm | |
| parent | 010c3f1f92bf862013c46b8457c0dc901d8ba110 (diff) | |
| download | fml8-82bb28981ac79e3f4017b396d2f627eaf4896182.tar.gz fml8-82bb28981ac79e3f4017b396d2f627eaf4896182.tar.bz2 fml8-82bb28981ac79e3f4017b396d2f627eaf4896182.zip | |
move id related functions to FML::Article::Sequence
Diffstat (limited to 'fml/lib/FML/Article.pm')
| -rw-r--r-- | fml/lib/FML/Article.pm | 156 |
1 files changed, 4 insertions, 152 deletions
diff --git a/fml/lib/FML/Article.pm b/fml/lib/FML/Article.pm index d305bf34..4652d33a 100644 --- a/fml/lib/FML/Article.pm +++ b/fml/lib/FML/Article.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Article.pm,v 1.53 2003/03/03 15:27:22 fukachan Exp $ +# $FML: Article.pm,v 1.54 2003/03/16 08:38:58 fukachan Exp $ # package FML::Article; @@ -14,6 +14,9 @@ use vars qw(@ISA @EXPORT @EXPORT_OK); use Carp; use FML::Log qw(Log LogWarn LogError); +use FML::Article::Sequence; +@ISA = qw(FML::Article::Sequence); + =head1 NAME @@ -114,82 +117,6 @@ sub _setup_article_template } -=head2 C<increment_id()> - -increment the sequence number of this article C<$self> and -save it to C<$sequence_file>. - -This routine uses C<File::Sequence> module. - -=cut - - -# Descriptions: determine article id (sequence number) -# Arguments: OBJ($self) -# Side Effects: save and update the current article sequence number -# Return Value: NUM(sequence identifier) -sub increment_id -{ - my ($self) = @_; - my $curproc = $self->{ curproc }; - my $config = $curproc->config(); - my $pcb = $curproc->pcb(); - my $seq_file = $config->{ sequence_file }; - - # XXX-TODO we should enhance IO::Adapter module to handle - # XXX-TODO sequential number. - use File::Sequence; - my $sfh = new File::Sequence { sequence_file => $seq_file }; - my $id = $sfh->increment_id; - if ($sfh->error) { LogError( $sfh->error ); } - - # save $id in pcb (process control block) and return $id - $pcb->set('article', 'id', $id); - - return $id; -} - - -=head2 C<id()> - -return the current article sequence number. - -=cut - -# Descriptions: return the article id (sequence number) -# Arguments: OBJ($self) -# Side Effects: none -# Return Value: NUM(sequence number) -sub id -{ - my ($self) = @_; - my $curproc = $self->{ curproc }; - my $config = $curproc->config(); - my $pcb = $curproc->pcb(); - - my $n = $pcb->get('article', 'id'); - - # within Process::Distribute - if ($n) { - return $n; - } - # processes not Process::Distribute - else { - my $seq_file = $config->{ sequence_file }; - my $n = 0; - - use File::Sequence; - my $sfh = new File::Sequence { sequence_file => $seq_file }; - if (defined $sfh) { - $n = $sfh->get_id(); - $sfh->close(); - } - - return $n; - } -} - - =head2 C<spool_in(id)> save the article to the file name C<id> in the article spool. @@ -314,81 +241,6 @@ sub _filepath } -=head2 speculate_max_id([$spool_dir]) - -scan the spool_dir and get the max number among files in it. It must -be the max (latest) article number in its folder. - -=cut - - -# Descriptions: scan the spool_dir and get max number among files in it. -# It must be the max (latest) article number in its folder. -# Arguments: OBJ($curproc) STR($spool_dir) -# Side Effects: none -# Return Value: NUM(sequence number) or undef -sub speculate_max_id -{ - my ($curproc, $spool_dir) = @_; - my $config = $curproc->config(); - my $use_subdir = $config->{ spool_type } eq 'subdir' ? 1 : 0; - - unless (defined $spool_dir) { - $spool_dir = $config->{ spool_dir }; - } - - Log("max_id: (debug) scan $spool_dir subdir=$use_subdir"); - - if ($use_subdir) { - use DirHandle; - my $dh = new DirHandle $spool_dir; - - if (defined $dh) { - my $fn = ''; # file name - my $subdir = ''; - my $max_subdir = 0; - - ENTRY: - while (defined($fn = $dh->read)) { - next ENTRY unless $fn =~ /^\d+$/; - - use File::Spec; - $subdir = File::Spec->catfile($spool_dir, $fn); - - if (-d $subdir) { - my $max_subdir = $max_subdir > $fn ? $max_subdir : $fn; - } - } - - $dh->close(); - - # XXX-TODO wrong? to speculate max_id in subdir spool? - $subdir = File::Spec->catfile($spool_dir, $max_subdir); - Log("max_id: (debug) scan $subdir"); - $curproc->speculate_max_id($subdir); - } - } - - use DirHandle; - my $dh = new DirHandle $spool_dir; - if (defined $dh) { - my $max = 0; - my $fn = ''; # file name - - while (defined($fn = $dh->read)) { - next unless $fn =~ /^\d+$/; - $max = $max < $fn ? $fn : $max; - } - - $dh->close(); - - return( $max > 0 ? $max : undef ); - } - - return undef; -} - - =head1 SEE ALSO L<FML::Header>, |
