NAME

SerialNumber::Sequence - make continously serial number sequence to be readable string; and vice verser;

SYNOPSIS

use SerialNumber::Sequence;
my $ss = new SerialNumber::Sequence;
my $sequence = [23,24,25,26,34,35,36,45,46,79,88];
$ss->number_length(3);
my $string = $ss->from_list( $sequence ); # return '#023-026,#034-036,#045-046,#079,#088'
my @array = $ss->from_string( $string ); # return [23,24,25,26,34,35,36,45,46,79,88]

DESCRIPTION

Some bill of document has its serialnumber, almostly are continuously. In some situation, we wanner do somthing with a group of these bills, which serial number are not continuously sequence, like this: [23,24,25,26,34,35,36,45,46,79,88], it is not readable for a person, when we print these infomation on invoice, we wanner a readable string to represent that sequence, which should be more short and clearly. So use this module and it will give a string: '#23-26,#34-36,#45-46,#79,#88' according above, of course we supply a method to do reverse-thing.

the prefix '#' and number length can be customized.

METHODS

new()
my $ss = new SerialNumber::Sequence;

It's very simple. just copy and paste that.

prefix()
# set/get prefix
$ss->prefix('@'); # set serialnumber prefix as '@'
$ss->prefix(); # return '@'

Default is '#'.

number_length()
# set/get number_length
$ss->number_length(5); # set serialnumber as 5 length number, with prefix '0'
$ss->number_length(); # return 5;

Default is 1. If serial number is 45567 and set number length to be 8, then after transform, you will get #00045567

from_list(@array)
my $string = $ss->from_list( $array_ref_of_a_sequence );
my $string = $ss->from_list( @array_of_a_sequence );

give a sequence with array or array ref, and return the readable string.

from_string($string)
my @array = $ss->from_string( $string );
my $array_ref = $ss->from_string( $string );

give some string like above method returned, return the array which elements are the pure serial number( without prefix string ).

_string2number()

private method, transform a single string to a number

_number2string()
$self->_number2string($number, without_prefix => 1 );

private method, transform a single number to a string, if without_prefix => 1, then ignore '#';

TODO

some more other transform style; some caculation for some sequence plus or minus operation;

AUTHOR

Chun Sheng <me@chunzi.org>

COPYRIGHT

Copyright (c) 2004-2005 Chun Sheng. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 147:

'=item' outside of any '=over'

Around line 193:

You forgot a '=back' before '=head1'