| 1 | package Purple::Sequence; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | sub increment_nid { | ||||||||
|
Subroutine
increment_nid: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 7 | 1 | my $old_nid = shift; | |||||||||
| 8 | |||||||||||
| 9 | 1 | my @oldValues = split('', $old_nid); | |||||||||
| 10 | 1 | my @newValues; | |||||||||
| 11 | 1 | my $carryBit = 1; | |||||||||
| 12 | |||||||||||
| 13 | 1 | foreach my $char (reverse(@oldValues)) { | |||||||||
| 14 | 1 | ▶ | if ($carryBit) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 1 | my $newChar; | |||||||||
| 16 | 1 | ($newChar, $carryBit) = _incChar($char); | |||||||||
| 17 | 1 | push(@newValues, $newChar); | |||||||||
| 18 | } else { | ||||||||||
| 19 | 0 | push(@newValues, $char); | |||||||||
| 20 | } | ||||||||||
| 21 | } | ||||||||||
| 22 | 1 | ▶ | push(@newValues, '1') if ($carryBit); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | return join('', (reverse(@newValues))); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub _incChar { | ||||||||
|
Subroutine
_incChar: called CC=4 SCAR=15.9
| |||||||||||
| 27 | 1 | my $char = shift; | |||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | if ($char eq 'Z') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | return '0', 1; | |||||||||
| 31 | } | ||||||||||
| 32 | 1 | ▶ | if ($char eq '9') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | return 'A', 0; | |||||||||
| 34 | } | ||||||||||
| 35 | 1 | ▶ | if ($char =~ /[A-Z0-9]/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | return chr(ord($char) + 1), 0; | |||||||||
| 37 | } | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 2 | 1; | |||||||||
| 41 | |||||||||||
| 42 | =head1 NAME | ||||||||||
| 43 | |||||||||||
| 44 | Purple::Sequence - Generate the next NID in a Sequence of NIDs | ||||||||||
| 45 | |||||||||||
| 46 | =head1 SYNOPSIS | ||||||||||
| 47 | |||||||||||
| 48 | This module contains the code for calculating the next NID | ||||||||||
| 49 | in a sequence of Purple Numbers. | ||||||||||
| 50 | |||||||||||
| 51 | my $next_nid = Purple::Sequence::increment_nid($current_nid); | ||||||||||
| 52 | |||||||||||
| 53 | =head1 FUNCTIONS | ||||||||||
| 54 | |||||||||||
| 55 | =head2 increment_nid($current_nid) | ||||||||||
| 56 | |||||||||||
| 57 | Returns the next NID after $current_nid. | ||||||||||
| 58 | |||||||||||
| 59 | =head1 AUTHORS | ||||||||||
| 60 | |||||||||||
| 61 | Chris Dent, E<lt>cdent@burningchrome.comE<gt> | ||||||||||
| 62 | |||||||||||
| 63 | Eugene Eric Kim, E<lt>eekim@blueoxen.comE<gt> | ||||||||||
| 64 | |||||||||||
| 65 | =head1 BUGS | ||||||||||
| 66 | |||||||||||
| 67 | Please report any bugs or feature requests to | ||||||||||
| 68 | C<bug-purple@rt.cpan.org>, or through the web interface at | ||||||||||
| 69 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Purple>. | ||||||||||
| 70 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 71 | your bug as I make changes. | ||||||||||
| 72 | |||||||||||
| 73 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 74 | |||||||||||
| 75 | (C) Copyright 2006 Blue Oxen Associates, all rights reserved. | ||||||||||
| 76 | |||||||||||
| 77 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 78 | under the same terms as Perl itself. | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | 2 | 1; # End of Purple::Sequence | |||||||||