| 1 | package IRC::Toolkit::TS6; | ||||||||||||||
| 2 | 1 | $IRC::Toolkit::TS6::VERSION = '0.091001'; | |||||||||||||
| 3 | 1 | ▶ | use strictures 2; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use parent 'Exporter::Tiny'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | sub ts6_id { __PACKAGE__->new(@_) } | ||||||||||||
|
Subroutine
ts6_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 8 | 1 | our @EXPORT = our @EXPORT_OK = 'ts6_id'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | use overload | ||||||||||||||
| 11 | 0 | ▶ | bool => sub { 1 }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 12 | 50000 | ▶ | '&{}' => sub { my $s = shift; sub { $s->next } }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | '""' => 'as_string', | |||||||||||||
| 14 | 1 | ▶ | fallback => 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | =pod | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =for Pod::Coverage new | ||||||||||||||
| 19 | |||||||||||||||
| 20 | =cut | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 2 | ▶ | sub new { bless [ split '', $_[1] || 'A'x6 ], $_[0] } | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
Condition100%2/2
$_[1] || 'AAAAAA'
MC/DC100%1/1
$_[1] || 'AAAAAA'
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 50005 | ▶ | sub as_string { join '', @{ $_[0] } } | ||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | sub next { | ||||||||||||||
| 27 | 50002 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
next: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | 50002 | my $pos = @$self; | |||||||||||||
| 30 | 50002 | ▶ | while (--$pos) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 51433 | ▶ | if ($self->[$pos] eq 'Z') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | 1428 | $self->[$pos] = 0; | |||||||||||||
| 33 | 1428 | return $self->as_string | |||||||||||||
| 34 | } elsif ($self->[$pos] ne '9') { | ||||||||||||||
| 35 | 48573 | $self->[$pos]++; | |||||||||||||
| 36 | 48573 | return $self->as_string | |||||||||||||
| 37 | } else { | ||||||||||||||
| 38 | 1432 | $self->[$pos] = 'A'; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 1 | ▶ | croak "Ran out of IDs!" if $self->[0] eq 'Z'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | 0 | ++$self->[$pos]; | |||||||||||||
| 45 | |||||||||||||||
| 46 | 0 | $self->as_string | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 1 | 1; | |||||||||||||
| 50 | |||||||||||||||
| 51 | =pod | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head1 NAME | ||||||||||||||
| 54 | |||||||||||||||
| 55 | IRC::Toolkit::TS6 - Generate TS6 IDs | ||||||||||||||
| 56 | |||||||||||||||
| 57 | =head1 SYNOPSIS | ||||||||||||||
| 58 | |||||||||||||||
| 59 | use IRC::Toolkit::TS6; | ||||||||||||||
| 60 | |||||||||||||||
| 61 | my $idgen = ts6_id(); | ||||||||||||||
| 62 | my $nextid = $idgen->next; | ||||||||||||||
| 63 | |||||||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||||||
| 65 | |||||||||||||||
| 66 | Lightweight array-type objects that can produce sequential TS6 IDs. | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =head2 ts6_id | ||||||||||||||
| 69 | |||||||||||||||
| 70 | The exported B<ts6_id> function will instance a new ID object. B<ts6_id> | ||||||||||||||
| 71 | optionally takes a start-point as a string (defaults to 'AAAAAA' similar to | ||||||||||||||
| 72 | C<ratbox>). | ||||||||||||||
| 73 | |||||||||||||||
| 74 | The object is overloaded in two ways; it stringifies to the current ID, and | ||||||||||||||
| 75 | calling it as a C<CODE> ref is the same as calling L</next>: | ||||||||||||||
| 76 | |||||||||||||||
| 77 | my $idgen = ts6_id; | ||||||||||||||
| 78 | my $current = "$idgen"; # 'AAAAAA' | ||||||||||||||
| 79 | my $next = $idgen->(); # 'AAAAAB' | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head2 as_string | ||||||||||||||
| 82 | |||||||||||||||
| 83 | The C<as_string> method explicitly stringifies the current ID. | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head2 next | ||||||||||||||
| 86 | |||||||||||||||
| 87 | The C<next> will increment the current ID and return the ID as a string. | ||||||||||||||
| 88 | |||||||||||||||
| 89 | If no more IDs are available, B<next> will croak. | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =head1 AUTHOR | ||||||||||||||
| 92 | |||||||||||||||
| 93 | Jon Portnoy <avenj@cobaltirc.org>; conceptually derived from the relevant | ||||||||||||||
| 94 | C<ratbox> function. | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =cut | ||||||||||||||