summaryrefslogtreecommitdiff
path: root/fml/lib/File
diff options
context:
space:
mode:
authorfukachan <fukachan>2002-11-17 08:00:37 +0000
committerfukachan <fukachan>2002-11-17 08:00:37 +0000
commit88cf583ad2392197497c32ac0cce915dc380f8af (patch)
tree12aacef7ab5647cfabc65ab433aafc00bcff9615 /fml/lib/File
parent8c95c4e97a5c3b26de4b1dc14e152601cd4a593e (diff)
downloadfml8-88cf583ad2392197497c32ac0cce915dc380f8af.tar.gz
fml8-88cf583ad2392197497c32ac0cce915dc380f8af.tar.bz2
fml8-88cf583ad2392197497c32ac0cce915dc380f8af.zip
fix get_id(); not use chomp() but use s/[\s\r\n]*$//.
define set_id($id) to update value in the sequence file.
Diffstat (limited to 'fml/lib/File')
-rw-r--r--fml/lib/File/Sequence.pm54
1 files changed, 51 insertions, 3 deletions
diff --git a/fml/lib/File/Sequence.pm b/fml/lib/File/Sequence.pm
index 8b153efb..90364bcc 100644
--- a/fml/lib/File/Sequence.pm
+++ b/fml/lib/File/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.27 2002/09/22 14:56:57 fukachan Exp $
+# $FML: Sequence.pm,v 1.28 2002/10/28 10:03:26 tmu Exp $
#
package File::Sequence;
@@ -164,7 +164,7 @@ sub increment_id
# Descriptions: get sequence
# Arguments: OBJ($self) [STR($file)]
# If $file is not specified,
-# the sequence_file parameter in new().
+# the sequence_file parameter in new() is used.
# Side Effects: the number holded in $file is incremented
# Return Value: NUM(sequence number)
sub get_id
@@ -202,7 +202,55 @@ sub get_id
return 0;
}
- return chomp($id);
+ $id =~ s/[\s\r\n]*$//;
+ return $id;
+}
+
+
+# Descriptions: store sequence number into specified $file
+# Arguments: OBJ($self) NUM($id) [STR($file)]
+# If $file is not specified,
+# the sequence_file parameter in new() is used.
+# Side Effects: create sequence file if not found.
+# Return Value: NUM(sequence number)
+sub set_id
+{
+ my ($self, $id, $file) = @_;
+ my $seq_file = defined $file ? $file : $self->{ _sequence_file };
+
+ unless (defined $seq_file) {
+ $self->error_set("the sequence file is undefined");
+ return 0;
+ };
+
+ unless ($seq_file) {
+ $self->error_set("the sequence file is not specified");
+ return 0;
+ };
+
+ # touch the sequence file if it does not exist.
+ unless (-f $seq_file) {
+ eval q{
+ use File::Utils qw(touch);
+ touch($seq_file);
+ };
+ };
+
+ use IO::Adapter::AtomicFile;
+ my ($rh, $wh) = IO::Adapter::AtomicFile->rw_open($seq_file);
+
+ # read the current sequence number
+ if (defined $wh) {
+ print $wh $id, "\n";
+ $wh->close;
+ }
+ else {
+ $self->error_set("cannot open the sequence file");
+ return 0;
+ }
+
+ $id =~ s/[\s\r\n]*$//;
+ return $id;
}