| 1 | package Unidexer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.006; use strict; use warnings; our $VERSION = '0.01'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | our $CHARS = 149186; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | sub new { | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | my ($class, @words) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | if (ref $words[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 10 | 1 | $CHARS = shift @words; | |||||||||||||||||||||||||||
| 11 | 1 | @words = @{ $words[0] }; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | 2 | my $self = bless [_build_default()], __PACKAGE__; | |||||||||||||||||||||||||||
| 14 | 2 | $self->index($_) for (@words); | |||||||||||||||||||||||||||
| 15 | 2 | return $self; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub _build_default { | ||||||||||||||||||||||||||||
| 19 | 53 | ▶ | return map { [ ] } 0 .. $CHARS | ||||||||||||||||||||||||||
|
Subroutine
_build_default: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub index { | ||||||||||||||||||||||||||||
| 23 | 22 | ▶ | my ($self, $word) = @_; | ||||||||||||||||||||||||||
|
Subroutine
index: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 22 | my $current = $self; | |||||||||||||||||||||||||||
| 25 | 22 | ▶ | for (split "|", ref $word ? $word->{index} : $word) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 83 | my $ord = ord($_); | |||||||||||||||||||||||||||
| 27 | 83 | ▶ | $ord -= 97 if ($CHARS == 26); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 83 | ▶ | unshift @{ $current }, _build_default() if ( scalar @{$current} < $CHARS ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 83 | $current = $current->[$ord]; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 22 | push @{$current}, $word; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub search { | ||||||||||||||||||||||||||||
| 35 | 10 | ▶ | my ($self, $search) = @_; | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 10 | my $word = $self; | |||||||||||||||||||||||||||
| 37 | 10 | for (split "|", $search) { | |||||||||||||||||||||||||||
| 38 | 45 | my $ord = ord($_); | |||||||||||||||||||||||||||
| 39 | 45 | ▶ | $ord -= 97 if ($CHARS == 26); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 45 | $word = $word->[$ord]; | |||||||||||||||||||||||||||
| 41 | 45 | ▶ | last if !$word; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 10 | ▶ | return ref $word && ref $word->[-1] ne 'ARRAY' ? $word->[-1] : die "Index cannot be found: ${search}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $word and ref $word->[-1] ne "ARRAY"
MC/DC50%1/2
ref $word and ref $word->[-1] ne "ARRAY"
ref $word
ref $word->[-1] ne "ARRAY"
Truth table66%2/3
A and B
A= ref $wordB= ref $word->[-1] ne "ARRAY"
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | 1; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||