blib/lib/Text/Thesaurus/Aiksaurus.pm

filter: Statementstmt 17.4% 11 / 63 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 18.8% 17 / 90 CC 10 SCAR 43.0
CC
10
Cov
14%
search
110.0
new
2.0
errorblank
2.0
CRAP 73.8
↑ Summary
1 package Text::Thesaurus::Aiksaurus;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use String::ShellQuote;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Text::Thesaurus::Aiksaurus - The great new Text::Thesaurus::Aiksaurus!
10  
11 =head1 VERSION
12  
13 Version 0.0.0
14  
15 =cut
16  
17 2 our $VERSION = '0.0.0';
18  
19  
20 =head1 SYNOPSIS
21  
22 use Text::Thesaurus::Aiksaurus;
23 use Data::Dumper;
24
25 my $ata=Text::Thesaurus::Aiksaurus->new;
26 my %h=$ata->search('test');
27
28 print join("\n", keys(%h));
29  
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 =cut
36  
37 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
38 0 my $self={error=>undef, errorString=>undef};
39 0 bless $self;
40  
41 0 return $self;
42 }
43  
44 =head2 search
45  
46 This searches the aiksaurus for the specified word.
47  
48 %returnedH=$ata->search($word);
49 if($ata->{error}){
50 #handles it if it errored
51 print "It errored... ".$ata->{error};
52 }else{
53 my $int=0;
54 if(defined($returnedH{'%misspelled'})){
55 #handles it if it misspelled
56 while(defined($returnedH{'%misspelled'}[$int])){
57 print $returnedH{'%misspelled'}[$int]."\n";
58  
59 $int++;
60 }
61 }else{
62 #handles it if it was not misspelled
63 my @returnedHkeys=keys(%returnedH);
64 while(defined($returnedHkeys[$int])){
65 print $returnedHkeys[$int].":\n";
66  
67 my $int2==0;
68 while(){
69 print ' '.$returnedH{$returnedHkeys[$int]}[$int2];
70 $int2++;
71 }
72  
73 $int++;
74 };
75 }
76 }
77  
78 =cut
79  
80 0 ▶sub search{
Subroutine search: not called CC=10 SCAR=47.0
Pod documented
81 0 my $self=$_[0];
82 0 my $word=$_[1];
83  
84 0 my $wordquote=shell_quote($word);
85  
86 0 my $search=`aiksaurus $wordquote`;
87 0 my $exitcode=$? >> 8;
88  
89 #error if it got a -1... not in path
90 0 ▶ if ($? == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == -1) 0 0 0
91 0 $self->{error}=1;
92 0 $self->{errorString}='"aiksaurus" not found in the current path';
93 0 warn('Text-Thesaurus-Aiksaurus search:1: '.$self->{errorString});
94 0 return undef;
95 }
96  
97 #error if it is something other than 0
98 0 ▶ if (!($? == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? == 0) 0 0 0
99 0 $self->{error}=2;
100 0 $self->{errorString}='"aiksaurus" exit with a non-zero';
101 0 warn('Text-Thesaurus-Aiksaurus search:2: '.$self->{errorString});
102 0 return undef;
103 }
104  
105 #used for holding the returned information
106 0 my %returnedH;
107  
108 #split
109 0 my @searchA=split(/\n/, $search);
110  
111 #this handles it if does not match it
112 0 ▶ if ($searchA[0] =~ /^\*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($searchA[0] =~ /^\*/) 0 0 0
113 0 my $int=2;
114  
115 0 $returnedH{'%misspelled'}=[];
116  
117 0 my $int2=0;
118 0 ▶ while (defined($searchA[$int])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $searchA[$int]) 0 0 0
119 0 $searchA[$int]=~s/^\t//g;
120  
121 0 $returnedH{'%misspelled'}[$int2]=$searchA[$int];
122
123 0 $int2++;
124 0 $int++;
125 }
126  
127 0 return %returnedH;
128 }
129  
130 #if we get here, it means it was matched and we should break it apart
131 0 my $int=0;
132 0 my $last='';
133 0 ▶ while (defined($searchA[$int])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $searchA[$int]) 0 0 0
134 #used for checking if it has been matched or not
135 0 my $matched=0;
136  
137 0 ▶ if ($searchA[$int] =~ /^=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($searchA[$int] =~ /^=/) 0 0 0
138 #removes the stuff around the word
139 0 $searchA[$int]=~s/^=== //;
140 0 $searchA[$int]=~s/ ===*//;
141  
142 #sets the last word
143 0 $last=$searchA[$int];
144  
145 #creates the array that will hold the possibilities
146 0 $returnedH{$last}=[];
147
148 0 $matched=1;
149 }
150  
151 #match the blank lines between words
152 0 ▶ if ($searchA[$int] =~ /^$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($searchA[$int] =~ /^$/) 0 0 0
153 0 $matched=1;
154 }
155  
156 #if it is not matched at this point, it is a list of words
157 0 ▶ if (!$matched) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($matched) 0 0 0
158 0 my @words=split(/\,\ /, $searchA[$int]);
159  
160 0 my $int2=0;
161  
162 0 ▶ while (defined($words[$int2])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $words[$int2]) 0 0 0
163 0 $returnedH{$last}[$int2]=$words[$int2];
164  
165 0 $int2++;
166 }
167 }
168  
169 0 $int++;
170 }
171  
172 0 return %returnedH;
173 }
174  
175 =head2 errorblank
176  
177 This is a internal function.
178  
179 =cut
180  
181 0 ▶sub errorblank{
Subroutine errorblank: not called CC=1 SCAR=6.9
Pod documented
182 0 $_[0]->{error}=undef;
183 0 $_[1]->{errorString}='';
184 }
185  
186 =head1 ERROR CODES
187  
188 =head2 1
189  
190 Failed to execute aiksaurus.
191  
192 =head2 2
193  
194 It exited with a non-zero status.
195  
196 =head1 RETURNED HASH
197  
198 If the only key in the returned has is '%misspelled', it aiksaurus
199 regards it as being mis-spelled. The key is a array of possible matches.
200  
201 Each key in the returned hash is a main word containing various other ones
202 with similar meanings. Each key is a array containing the other words.
203  
204 =head1 AUTHOR
205  
206 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
207  
208 =head1 BUGS
209  
210 Please report any bugs or feature requests to C<bug-text-thesaurus-aiksaurus at rt.cpan.org>, or through
211 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Thesaurus-Aiksaurus>. I will be notified, and then you'll
212 automatically be notified of progress on your bug as I make changes.
213  
214  
215  
216  
217 =head1 SUPPORT
218  
219 You can find documentation for this module with the perldoc command.
220  
221 perldoc Text::Thesaurus::Aiksaurus
222  
223  
224 You can also look for information at:
225  
226 =over 4
227  
228 =item * RT: CPAN's request tracker
229  
230 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Thesaurus-Aiksaurus>
231  
232 =item * AnnoCPAN: Annotated CPAN documentation
233  
234 L<http://annocpan.org/dist/Text-Thesaurus-Aiksaurus>
235  
236 =item * CPAN Ratings
237  
238 L<http://cpanratings.perl.org/d/Text-Thesaurus-Aiksaurus>
239  
240 =item * Search CPAN
241  
242 L<http://search.cpan.org/dist/Text-Thesaurus-Aiksaurus/>
243  
244 =back
245  
246  
247 =head1 ACKNOWLEDGEMENTS
248  
249  
250 =head1 COPYRIGHT & LICENSE
251  
252 Copyright 2009 Zane C. Bowers, all rights reserved.
253  
254 This program is free software; you can redistribute it and/or modify it
255 under the same terms as Perl itself.
256  
257  
258 =cut
259  
260 2 1; # End of Text::Thesaurus::Aiksaurus
↑ Summary