File Coverage

blib/lib/Ham/Reference/Phonetics.pm
Criterion Covered Total %
statement 9 40 22.5
branch 0 14 0.0
condition 0 7 0.0
subroutine 3 7 42.8
pod 4 4 100.0
total 16 72 22.2


line stmt bran cond sub pod time code
1             package Ham::Reference::Phonetics;
2              
3             # --------------------------------------------------------------------------
4             # Ham::Reference::Phonetics - A quick reference for the ITU Phonetic
5             # Alphabet
6             #
7             # Copyright (c) 2008-2010 Brad McConahay N8QQ.
8             # Cincinnat, Ohio USA
9             #
10             # This module is free software; you can redistribute it and/or
11             # modify it under the terms of the Artistic License 2.0. For
12             # details, see the full text of the license in the file LICENSE.
13             #
14             # This program is distributed in the hope that it will be
15             # useful, but it is provided "as is" and without any express
16             # or implied warranties. For details, see the full text of
17             # the license in the file LICENSE.
18             # --------------------------------------------------------------------------
19              
20 1     1   41667 use warnings;
  1         3  
  1         36  
21 1     1   6 use strict;
  1         2  
  1         40  
22              
23 1     1   5 use vars qw($VERSION);
  1         5  
  1         769  
24            
25             our $VERSION = '0.02';
26              
27             my $phonetics = {};
28             $phonetics->{itu} =
29             {
30             'a' => 'Alfa',
31             'b' => 'Bravo',
32             'c' => 'Charlie',
33             'd' => 'Delta',
34             'e' => 'Echo',
35             'f' => 'Foxtrot',
36             'g' => 'Golf',
37             'h' => 'Hotel',
38             'i' => 'India',
39             'j' => 'Juliett',
40             'k' => 'Kilo',
41             'l' => 'Lima',
42             'm' => 'Mike',
43             'n' => 'November',
44             'o' => 'Oscar',
45             'p' => 'Papa',
46             'q' => 'Quebec',
47             'r' => 'Romeo',
48             's' => 'Sierra',
49             't' => 'Tango',
50             'u' => 'Uniform',
51             'v' => 'Victor',
52             'w' => 'Whiskey',
53             'x' => 'X-Ray',
54             'y' => 'Yankee',
55             'z' => 'Zulu'
56             };
57              
58             sub new
59             {
60 0     0 1   my $class = shift;
61 0           my %args = @_;
62 0           my $self = {};
63 0           bless $self, $class;
64 0   0       $self->{phonetic_set} = lc($args{phonetic_set}) || 'itu';
65 0   0       $self->{space} = $args{space} || '';
66 0           return $self;
67             }
68              
69             sub get
70             {
71 0     0 1   my $self = shift;
72 0           my $string = shift;
73 0 0         return undef if !$string;
74 0           $string = lc($string);
75 0           my $p = '';
76 0           foreach my $letter (split '',$string) {
77 0 0         if ($phonetics->{$self->{phonetic_set}}->{$letter})
    0          
78             {
79 0           $p .= $phonetics->{$self->{phonetic_set}}->{$letter}.' ';
80             } elsif ($letter eq ' ') {
81 0           $p .= $self->{space};
82 0 0         $p .= ' ' if $self->{space};
83             }
84             }
85 0           $p =~ s/\s$//;
86 0           return $p;
87             }
88              
89             sub get_arrayref
90             {
91 0     0 1   my $self = shift;
92 0           my $string = shift;
93 0 0         return undef if !$string;
94 0           $string = lc($string);
95 0           my $p = ();
96 0           foreach my $letter (split '',$string) {
97 0 0 0       if ($phonetics->{$self->{phonetic_set}}->{$letter})
    0          
98             {
99 0           push( @$p, $phonetics->{$self->{phonetic_set}}->{$letter});
100             } elsif ($letter eq ' ' and $self->{space}) {
101 0           push( @$p, $self->{space} );
102             }
103             }
104 0           return $p;
105             }
106              
107             sub get_hashref
108             {
109 0     0 1   my $self = shift;
110 0           return $phonetics->{$self->{phonetic_set}};
111             }
112              
113             1;
114              
115             =head1 NAME
116              
117             Ham::Reference::Phonetics - A quick reference for the ITU Phonetic Alphabet.
118              
119             =head1 VERSION
120              
121             Version 0.02
122              
123             =head1 SYNOPSIS
124              
125             use Ham::Reference::Phonetics;
126              
127             my $phonetics = Ham::Reference::Phonetics->new(
128             space => ''
129             );
130              
131             # use the get() function to get a string of phonetics
132              
133             print $phonetics->get('abc xyz');
134             print "\n";
135              
136             # use the get_array() function to get an array of phonetics
137             # with each one in an element
138              
139             my $arrayref = $phonetics->get_arrayref('abc xyz');
140             foreach (@$arrayref) {
141             print "$_\n";
142             }
143              
144             # use a hash reference to get all phonetics
145             # the following will display all letters and corresponding phonetics
146              
147             my $hashref = $phonetics->get_hashref();
148             foreach (sort keys %$hashref)
149             {
150             print "$_ = $hashref->{$_}\n";
151             }
152              
153             =head1 DESCRIPTION
154              
155             The C module is a quick reference to the ITU phonetic alphabet
156             suggested by the ARRL for Amateur Radio use. Other phonetic alphabets may be included in the
157             future. Some can already be found in C.
158              
159             =head1 CONSTRUCTOR
160              
161             =head2 new()
162              
163             Usage : my $phonetics = Ham::Reference::Phonetics->new();
164             Function : creates a new Ham::Reference::Phonetics object
165             Returns : A Ham::Reference::Phonetics object
166             Args : an anonymous hash:
167             key required? value
168             ------- --------- -----
169             phonetic_set no select the phonetic alphabet set
170             the only set for now, and the default set
171             is itu
172             space no set a string to represent a space when
173             using methods to convert to phonetics
174             default is an empty string
175              
176             =head1 METHODS
177              
178             =head2 get()
179              
180             Usage : my $string = $phonetics->get( 'this is my string' );
181             Function : converts a string to a string of corresponding phonetic words
182             Returns : a string
183             Args : a string
184              
185             =head2 get_arrayref()
186              
187             Usage : my $arrayref = $phonetics->get_arrayref( 'this is my string' );
188             Function : converts a string to an array reference of corresponding phonetic words
189             one phonetic word per element
190             Returns : an array reference
191             Args : a string
192              
193             =head2 get_hashref()
194              
195             Usage : my $hashref = $phonetics->get_hashref();
196             Function : get the phonetic alphabet in a hash referenece
197             Returns : a hash reference
198             Args : n/a
199              
200             =head1 ACKNOWLEDGEMENTS
201              
202             The ITU phonetic alphabet for Amateur Radio use was taken from http://www.arrl.org/FandES/field/forms/fsd220.html#alphabet,
203             courtesy of the American Radio Relay League.
204              
205             =head1 SEE ALSO
206              
207             Other phonetic alphabets can found in C.
208              
209             =head1 AUTHOR
210              
211             Brad McConahay N8QQ, C<< >>
212              
213             =head1 COPYRIGHT & LICENSE
214              
215             C is Copyright (C) 2008-2010 Brad McConahay N8QQ.
216              
217             This module is free software; you can redistribute it and/or
218             modify it under the terms of the Artistic License 2.0. For
219             details, see the full text of the license in the file LICENSE.
220              
221             This program is distributed in the hope that it will be
222             useful, but it is provided "as is" and without any express
223             or implied warranties. For details, see the full text of
224             the license in the file LICENSE.
225              
226