summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-02-20 05:06:28 +0000
committerfukachan <fukachan>2001-02-20 05:06:28 +0000
commit734ff29ad0a4f7374dbe72295fea9ab4dff88d14 (patch)
treed1e228b617fa5ef83facd9dd27c09fcda5924a05
parentfc634e5aa605ecfc44ba3aaa1fe6d9b1dddca75c (diff)
downloadfml8-734ff29ad0a4f7374dbe72295fea9ab4dff88d14.tar.gz
fml8-734ff29ad0a4f7374dbe72295fea9ab4dff88d14.tar.bz2
fml8-734ff29ad0a4f7374dbe72295fea9ab4dff88d14.zip
enable modulus sequence
-rw-r--r--fml/lib/FML/SequenceFile.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/fml/lib/FML/SequenceFile.pm b/fml/lib/FML/SequenceFile.pm
index 98e9a296..a68457c1 100644
--- a/fml/lib/FML/SequenceFile.pm
+++ b/fml/lib/FML/SequenceFile.pm
@@ -25,6 +25,23 @@ FML::SequenceFile - maintain the sequence number
my $id = $sfh->increment_id;
if ($sfh->error) { use Carp; carp( $sfh->error ); }
+If you divide the $id by some modulus, use
+
+ my $sfh = new FML::SequenceFile {
+ sequence_file => $seq_file,
+ modulus => $modules,
+ };
+ my $id = $sfh->increment_id;
+
+For example, if you do new() with modulus 3,
+
+ my $sfh = new FML::SequenceFile {
+ sequence_file => $seq_file,
+ modulus => 3,
+ };
+
+$id becomes 0, 1, 2, 0, 1, 2...
+
=head1 DESCRIPTION
=head2 C<new($args)>
@@ -47,6 +64,7 @@ sub new
my ($type) = ref($self) || $self;
my $me = {};
$me->{ _sequence_file } = $args->{ sequence_file };
+ $me->{ _modulus } = $args->{ modulus };
return bless $me, $type;
}
@@ -81,8 +99,16 @@ sub increment_id
return 0;
}
+ # compute the modulus
+ if (defined $self->{ _modulus }) {
+ my $modulus = $self->{ _modulus };
+ $id++;
+ $id = $id % $modulus;
+ }
# increment $id. The incremented number is the current article ID.
- $id++;
+ else {
+ $id++;
+ }
# save $id
print $wh $id, "\n";