| 1 | package Lingua::Klingon::Collate; | ||||||||||
| 2 | # vim:set tw=72 sw=2: | ||||||||||
| 3 | |||||||||||
| 4 | 5 | ▶ | use 5.005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | require Exporter; | |||||||||
| 8 | 5 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | @ISA = qw(Exporter); | |||||||||
| 10 | |||||||||||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 13 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 14 | |||||||||||
| 15 | # This allows declaration use Lingua::Klingon::Collate ':all'; | ||||||||||
| 16 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||
| 17 | # will save memory. | ||||||||||
| 18 | 5 | %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 19 | strxfrm | ||||||||||
| 20 | strunxfrm | ||||||||||
| 21 | strcoll | ||||||||||
| 22 | ) ] ); | ||||||||||
| 23 | |||||||||||
| 24 | 5 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 25 | |||||||||||
| 26 | 5 | @EXPORT = qw( | |||||||||
| 27 | |||||||||||
| 28 | ); | ||||||||||
| 29 | 5 | $VERSION = '1.03'; | |||||||||
| 30 | |||||||||||
| 31 | 5 | my %xfrm = ( | |||||||||
| 32 | a => 'a', | ||||||||||
| 33 | b => 'b', | ||||||||||
| 34 | ch => 'c', | ||||||||||
| 35 | D => 'd', | ||||||||||
| 36 | e => 'e', | ||||||||||
| 37 | gh => 'f', | ||||||||||
| 38 | H => 'g', | ||||||||||
| 39 | I => 'h', | ||||||||||
| 40 | j => 'i', | ||||||||||
| 41 | l => 'j', | ||||||||||
| 42 | m => 'k', | ||||||||||
| 43 | n => 'l', | ||||||||||
| 44 | ng => 'm', | ||||||||||
| 45 | o => 'n', | ||||||||||
| 46 | p => 'o', | ||||||||||
| 47 | q => 'p', | ||||||||||
| 48 | Q => 'q', | ||||||||||
| 49 | r => 'r', | ||||||||||
| 50 | S => 's', | ||||||||||
| 51 | t => 't', | ||||||||||
| 52 | tlh => 'u', | ||||||||||
| 53 | u => 'v', | ||||||||||
| 54 | v => 'w', | ||||||||||
| 55 | w => 'x', | ||||||||||
| 56 | y => 'y', | ||||||||||
| 57 | "'" => 'z', | ||||||||||
| 58 | ); | ||||||||||
| 59 | |||||||||||
| 60 | 5 | my %unxfrm = reverse %xfrm; | |||||||||
| 61 | |||||||||||
| 62 | 5 | my $letter = qr/tlh|ch|gh|ng(?!h)|[abDeHIjlmnopqQrStuvwy']/; | |||||||||
| 63 | 5 | my $nonletter = qr/[^a-zA-Z']/; | |||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | 16 | ▶ | sub strcoll ($$) { | ||||||||
|
Subroutine
strcoll: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 16 | strxfrm($_[0]) cmp strxfrm($_[1]); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | 65 | ▶ | sub strxfrm { | ||||||||
|
Subroutine
strxfrm: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 72 | # TODO use Lingua::Klingon::Segment for this | ||||||||||
| 73 | 65 | my @result; | |||||||||
| 74 | |||||||||||
| 75 | 65 | ▶ | for my $string (wantarray ? @_ : $_[0]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | # only transform letters; leave all the rest as it is | ||||||||||
| 77 | 67 | (my $copy = $string) =~ s/($letter)/$xfrm{$1}/g; | |||||||||
| 78 | 67 | push @result, $copy; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 65 | ▶ | wantarray ? @result : $result[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | 33 | ▶ | sub strunxfrm { | ||||||||
|
Subroutine
strunxfrm: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 86 | 33 | my @result; | |||||||||
| 87 | |||||||||||
| 88 | 33 | ▶ | for my $string (wantarray ? @_ : $_[0]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 35 | (my $copy = $string) =~ s/([a-z])/$unxfrm{$1}/g; | |||||||||
| 90 | 35 | push @result, $copy; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 33 | ▶ | wantarray ? @result : $result[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | 5 | 1; | |||||||||
| 98 | __END__ | ||||||||||