summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2004-04-11 13:02:14 +0000
committerfukachan <fukachan>2004-04-11 13:02:14 +0000
commit6435dce137b06b3dd2a59f46aec1c08389d8000a (patch)
treec01e67e952cfa043346658576c93f13be21e4d6d
parentf85683e1598aad3506803cfa4311445f70a9df16 (diff)
downloadfml8-6435dce137b06b3dd2a59f46aec1c08389d8000a.tar.gz
fml8-6435dce137b06b3dd2a59f46aec1c08389d8000a.tar.bz2
fml8-6435dce137b06b3dd2a59f46aec1c08389d8000a.zip
switch File::Sequence to IO::Adapter based sequence operation
-rw-r--r--fml/lib/FML/Article/Sequence.pm51
-rw-r--r--fml/lib/FML/Digest.pm35
2 files changed, 48 insertions, 38 deletions
diff --git a/fml/lib/FML/Article/Sequence.pm b/fml/lib/FML/Article/Sequence.pm
index 3d06f475..3d37d70f 100644
--- a/fml/lib/FML/Article/Sequence.pm
+++ b/fml/lib/FML/Article/Sequence.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: Sequence.pm,v 1.8 2004/02/01 14:38:03 fukachan Exp $
+# $FML: Sequence.pm,v 1.9 2004/02/01 15:54:45 fukachan Exp $
#
package FML::Article::Sequence;
@@ -31,8 +31,6 @@ FML::Article::Sequence - article sequence manipulation
increment the sequence number of this article C<$self> and
save it to C<$sequence_file>.
-This routine uses C<File::Sequence> module.
-
=cut
@@ -50,12 +48,12 @@ sub increment_id
$curproc->lock($lock_channel);
- # 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) { $curproc->logerror( $sfh->error ); }
+ use IO::Adapter;
+ my $io = new IO::Adapter "file:$seq_file";
+ my $id = $io->sequence_increment();
+ if ($io->error()) {
+ $curproc->logerror( $io->error() );
+ }
# save $id in pcb (process control block) and return $id
$pcb->set('article', 'id', $id);
@@ -92,16 +90,37 @@ sub id
# processes not Process::Distribute
else {
my $seq_file = $config->{ article_sequence_file };
- my $n = 0;
+ my $map = sprintf("file:%s", $seq_file);
- use File::Sequence;
- my $sfh = new File::Sequence { sequence_file => $seq_file };
- if (defined $sfh) {
- $n = $sfh->get_id() || 0;
- }
+ return( $self->get_number_from_map($map) || 0 );
+ }
+}
- return $n;
+
+# Descriptions: get number from map.
+# Arguments: OBJ($self) STR($map)
+# Side Effects: none
+# Return Value: NUM
+sub get_number_from_map
+{
+ my ($self, $map) = @_;
+
+ use IO::Adapter;
+ my $io = new IO::Adapter $map;
+ if (defined $io) {
+ $n = $io->getline() || 0;
+ $n =~ s/^\s*//;
+ $n =~ s/\s*$//;
+
+ if ($n =~ /^\d+$/) {
+ return $n;
+ }
+ else {
+ return 0;
+ }
}
+
+ return 0;
}
diff --git a/fml/lib/FML/Digest.pm b/fml/lib/FML/Digest.pm
index 4a456612..ae92407b 100644
--- a/fml/lib/FML/Digest.pm
+++ b/fml/lib/FML/Digest.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: Digest.pm,v 1.16 2004/02/15 04:38:25 fukachan Exp $
+# $FML: Digest.pm,v 1.17 2004/03/12 04:22:53 fukachan Exp $
#
package FML::Digest;
@@ -129,20 +129,12 @@ sub _get_id
$curproc->lock($channel);
- # XXX-TODO: we should enhance IO::Adapter module to handle
- # XXX-TODO: sequential number.
if (-f $seq_file) {
- use File::Sequence;
- my $sfh = new File::Sequence { sequence_file => $seq_file };
- if (defined $sfh) {
- my $_id = $sfh->get_id();
- unless ($sfh->error) {
- $id = $_id;
- }
- else {
- $curproc->logerror( $sfh->error );
- }
- }
+ my $map = sprintf("file:%s", $seq_file);
+
+ use FML::Article::Sequence;
+ my $seq = new FML::Article::Sequence $curproc;
+ $id = $seq->get_number_from_map($map) || 0;
}
$curproc->unlock($channel);
@@ -162,18 +154,17 @@ sub set_digest_id
my $curproc = $self->{ _curproc };
my $config = $curproc->config();
my $seq_file = $config->{ digest_sequence_file };
+ my $map = sprintf("file:%s", $seq_file);
my $channel = $self->get_lock_channel_name();
- # XXX-TODO: we should enhance IO::Adapter module to handle
- # XXX-TODO: sequential number.
- # XXX-TODO: defined() check for $sfh.
- use File::Sequence;
-
$curproc->lock($channel);
- my $sfh = new File::Sequence { sequence_file => $seq_file };
- $sfh->set_id($id);
- if ($sfh->error) { $curproc->logerror( $sfh->error ); }
+ use IO::Adapter;
+ my $io = new IO::Adapter $map;
+ $io->sequence_replace($id);
+ if ($io->error()) {
+ $curproc->logerror( $io->error() );
+ }
$curproc->unlock($channel);