diff options
| author | fukachan <fukachan> | 2001-10-17 03:05:58 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-10-17 03:05:58 +0000 |
| commit | 6958c17feb4ae1029b52c31b32abfc3247c2539a (patch) | |
| tree | bb1a3bc7ecf619721ebb26c2ac1813e1640aeae0 /fml/lib/File | |
| parent | 4aae001eea16fef40d5fd6d6892b5db1ed1e783d (diff) | |
| download | fml8-6958c17feb4ae1029b52c31b32abfc3247c2539a.tar.gz fml8-6958c17feb4ae1029b52c31b32abfc3247c2539a.tar.bz2 fml8-6958c17feb4ae1029b52c31b32abfc3247c2539a.zip | |
implemente get_id() method to return the latest article id
update document
Diffstat (limited to 'fml/lib/File')
| -rw-r--r-- | fml/lib/File/Sequence.pm | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/fml/lib/File/Sequence.pm b/fml/lib/File/Sequence.pm index be75d4a8..1a5261bc 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.7 2001/04/08 13:25:39 fukachan Exp $ +# $FML: Sequence.pm,v 1.8 2001/05/27 14:27:55 fukachan Exp $ # package File::Sequence; @@ -19,6 +19,15 @@ File::Sequence - maintain the sequence number =head1 SYNOPSIS +To get the latest $article_id, + + use File::Sequence; + my $sfh = new File::Sequence { sequence_file => $seq_file }; + my $id = $sfh->et_id; + if ($sfh->error) { use Carp; carp( $sfh->error ); } + +to increment $article_id and get it + use File::Sequence; my $sfh = new File::Sequence { sequence_file => $seq_file }; my $id = $sfh->increment_id; @@ -61,6 +70,10 @@ number. increment the sequence number. +=head2 C<get_id([$file])> + +get the sequence number from specified C<$file>. + =cut @@ -134,6 +147,45 @@ sub increment_id } +# Descriptions: get sequence +# Arguments: $self [$file] +# If $file is not specified, +# the sequence_file parameter in new(). +# Side Effects: the number holded in $file is incremented +# Return Value: number (sequence number) +sub get_id +{ + my ($self, $file) = @_; + my $id = 0; + my $seq_file = $file || $self->{ _sequence_file }; + + 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) { + return 0; + }; + + use IO::File::Atomic; + my ($rh, $wh) = IO::File::Atomic->rw_open($seq_file); + + # read the current sequence number + if (defined $rh) { + $id = $rh->getline; + $rh->close; + } + else { + $self->error_set("cannot open the sequence file"); + return 0; + } + + return $id; +} + + =head1 AUTHOR Ken'ichi Fukamachi |
