blib/lib/Text/T9.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 97.1% 34 / 35 CC 3 SCAR 6.2
CC
3
Cov
97%
t9_find_words
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 package Text::T9;
2 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.01';
8  
9 1 our @ISA = qw( Exporter );
10 1 our @EXPORT = qw( t9_find_words );
11  
12 1 our @T9NL = ( '', '', 'ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ' );
13  
14 sub t9_find_words($$)
15 4 ▶{
Subroutine t9_find_words: called CC=3 SCAR=11.0
Pod documented
16 4 my $num = shift;
17 4 my $words = shift;
18
19 4 ▶ return () unless $num =~ /^[2-9]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $num =~ /^[2-9]+$/ 0 4 4
20
21 4 my $len = length( $num );
22 4 my $re;
23 4 for( 0 .. $len - 1 )
24 {
25 17 $re .= "[" . $T9NL[substr( $num, $_, 1 )] . "]";
26 }
27 4 $re = "^$re\$";
28 4 return grep { /$re/i } grep { length( $_ ) == $len } @$words;
29 }
30  
31 =pod
32  
33 =head1 NAME
34  
35 Text::T9 - Text in 9 keys (T9) input.
36  
37 =head1 SYNOPSIS
38  
39 # array with words
40 my @words = qw( this is just a simple kiss test lips here how );
41
42 # what is word(s) for the sequence
43 print "$_ " for( t9_find_words( 5477, \@words ) );
44
45 # this prints: kiss lips
46  
47 =head1 DESCRIPTION
48  
49 What is T9 Text Input?
50  
51 T9 Text Input is software that enables users to easily enter text
52 into small devices with limited size keyboards, like mobile phones.
53 T9 Text Input replaces the traditional "multi-tap" method of entering
54 text providing the ability to enter text using only one keystroke per
55 letter.
56  
57 (you can find more inforation at http://www.t9.com/)
58  
59 This module provides simple way to find which words match a number
60 sequence in T9 sense.
61  
62 Examples:
63  
64 5477 : KISS, LIPS
65 8447 : THIS
66 746753 : SIMPLE
67 469 : HOW
68  
69 Allowed number are 2,3,4,5,6,7,8,9 which are mapped in this way:
70  
71 2 ABC
72 3 DEF
73 4 GHI
74 5 JKL
75 6 MNO
76 7 PQRS
77 8 TUV
78 9 WXYZ
79  
80 =over 4
81  
82 =item t9_find_words( $num, \@words_arr )
83  
84 This functions takes two arguments: number sequence and words array
85 reference. The return value is a list of matching words.
86  
87 =back
88  
89 =head1 EXAMPLES
90  
91 open( i, "/tmp/words.lst" );
92 @words = <i>;
93 close( i );
94 chomp( @words );
95 print "$#words were loaded\n";
96
97 for my $num ( qw( 5477 8447 746753 469 ) )
98 {
99 print "$num: ";
100 print "$_ " for( t9_find_words( $num, \@words ) );
101 print "\n";
102 }
103  
104 =head1 AUTHOR
105  
106 Vladi Belperchinov-Shabanski "Cade"
107
108 <cade@bis.bg> <cade@biscom.net> <cade@datamax.bg> <cade@cpan.org>
109  
110 http://cade.datamax.bg
111  
112 =cut
↑ Summary