Google/Spelling.pm

filter: Statementstmt 50.0% 18 / 36 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 75.0% 3 / 4 totaltotal 38.8% 26 / 67 CC 9 SCAR 25.6
CC
9
Cov
34%
init
20.7
phrase
20.0
new
2.5
CRAP 12.9
« Google/Search.pm ↑ Summary Google/tool.pm »
1 {
2  
3 1 =head1 NAME
4  
5 Net::Google::Spelling - simple OOP-ish interface to the Google SOAP API for spelling suggestions
6  
7 =head1 SYNOPSIS
8  
9 use Net::Google::Spelling;
10 my $spelling = Net::Google::Spelling(\%args);
11  
12 $spelling->phrase("muntreal qweebec");
13 print $spelling->suggest()."\n";
14  
15 =head1 DESCRIPTION
16  
17 Provides a simple OOP-ish interface to the Google SOAP API for
18 spelling suggestions.
19  
20 This package is used by I<Net::Google>.
21  
22 =cut
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 package Net::Google::Spelling;
27 1 ▶use base qw (Net::Google::tool);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 $Net::Google::Spelling::VERSION = '1.0';
32  
33 =head1 PACKAGE METHODS
34  
35 =cut
36  
37 =head2 $pkg = __PACKAGE__->new(\%args)
38  
39 Valid arguments are :
40  
41 =over 4
42  
43 =item *
44  
45 B<key>
46  
47 I<string>.A Google API key.
48  
49 If none is provided then the key passed to the parent I<Net::Google>
50 object will be used.
51  
52 =item *
53  
54 B<phrase>
55  
56 I<string> or I<array reference>.
57  
58 =item *
59  
60 B<http_proxy>
61  
62 I<url>. A URL for proxy-ing HTTP requests.
63  
64 =item *
65  
66 B<debug>
67  
68 Valid options are:
69  
70 =over 4
71  
72 =item *
73  
74 I<boolean>
75  
76 If true prints debugging information returned by SOAP::Lite
77 to STDERR
78  
79 =item *
80  
81 I<coderef>.
82  
83 Your own subroutine for munging the debugging information
84 returned by SOAP::Lite.
85  
86 =back
87  
88 =back
89  
90 The object constructor in Net::Google 0.53, and earlier, expected
91 a I<GoogleSearchService> object as its first argument followed by
92 a hash reference of argument. Versions 0.6 and higher are backwards
93 compatible.
94  
95 Returns an object. Woot!
96  
97 =cut
98  
99 1 ▶sub new {
Subroutine new: called CC=2 SCAR=9.2
Pod documented
100 1 my $pkg = shift;
101  
102 1 my $self = {};
103 1 bless $self,$pkg;
104  
105 1 ▶ if (! $self->init(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->init(@_)) 0 0 0
106 0 return undef;
107 }
108  
109 0 return $self;
110 }
111  
112 1 ▶sub init {
Subroutine init: called CC=5 SCAR=30.3
Pod undocumented
113 1 my $self = shift;
114  
115 1 ▶ my $args = $self->SUPER::init("spelling",@_)
Condition0%0/2
$self->SUPER::init('spelling', @_) || (return 0)
l!l
00
MC/DC0%0/1
$self->SUPER::init('spelling', @_) || (return 0)
$self->SUPER::init('spelling', @_)
Truth table0%0/2
A
A= $self->SUPER::init('spelling', @_)
Aresult
11
00
116 || return 0;
117  
118 #
119  
120 0 ▶ if ($args->{'phrase'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"phrase"}) 0 0 0
121 0 ▶ defined($self->phrase( (ref($args->{'phrase'}) eq "ARRAY") ? @{$args->{'phrase'}} : $args->{'phrase'} )) || return 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $self->phrase(ref $args->{"phrase"} eq "ARRAY" ? @{$$args{"phrase"};} : $args->{"phrase"}) or return 0 0 0 0
ref $args->{'phrase'} eq 'ARRAY' ? : 0 0 0
122 }
123
124 0 return 1;
125 }
126  
127 =head1 OBJECT METHODS
128  
129 =cut
130  
131 =head2 $obj->key($string)
132  
133 Get/set the Google API key for this object.
134  
135 =cut
136  
137 # Defined in Net::Google::tool
138  
139 =head2 $obj->http_proxy($url)
140  
141 Get/set the HTTP proxy for this object.
142  
143 Returns a string.
144  
145 =cut
146  
147 # Defined in Net::Google::tool
148  
149 =head2 $obj->phrase(@words)
150  
151 Add one or more words to the phrase you want to spell-check.
152  
153 If the first item in I<@words> is empty, then any existing I<phrase>
154 data will be removed before the new data is added.
155  
156 Returns a string. Returns undef if there was an error.
157  
158 =cut
159  
160 0 ▶sub phrase {
Subroutine phrase: not called CC=4 SCAR=30.0
Pod documented
161 0 my $self = shift;
162 0 my @words = @_;
163  
164 0 ▶ if ((scalar(@words) > 1) && ($words[0] == "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @words > 1 and $words[0] == "") 0 0 0
Condition0%0/3
scalar @words > 1 and $words[0] == ""
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @words > 1 and $words[0] == ""
scalar @words > 1 $words[0] == ""
Truth table0%0/3
A and B
A= scalar @words > 1B= $words[0] == ""
ABresult
0X0
100
111
165 0 $self->{'_phrase'} = [];
166 }
167  
168 0 ▶ if (@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 0 0 0
169 0 push @{$self->{'_phrase'}} , @words;
170 }
171  
172 0 return join("",@{$self->{'_phrase'}});
173 }
174  
175 =head2 $obj->suggest()
176  
177 Fetch the spelling suggestion from the Google servers.
178  
179 Returns a string. Returns undef if there was an error.
180  
181 =cut
182  
183 0 ▶sub suggest {
Subroutine suggest: not called CC=1 SCAR=6.9
Pod documented
184 0 my $self = shift;
185  
186 0 $self->_queries(1);
187  
188 0 return $self->{'_service'}->doSpellingSuggestion(
189 $self->key(),
190 $self->phrase(),
191 );
192 }
193  
194 =head2 $obj->queries_exhausted()
195  
196 Returns true or false depending on whether or not the current in-memory
197 B<session> has exhausted the Google API 1000 query limit.
198  
199 =cut
200  
201 # Defined in Net::Google::tool
202  
203 =head1 VERSION
204  
205 1.0
206  
207 =head1 DATE
208  
209 $Date: 2005/03/26 20:49:03 $
210  
211 =head1 AUTHOR
212  
213 Aaron Straup Cope
214  
215 =head1 SEE ALSO
216  
217 L<Net::Google>
218  
219 =head1 LICENSE
220  
221 Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved.
222  
223 This is free software, you may use it and distribute it under the same
224 terms as Perl itself.
225  
226 =cut
227  
228 1 return 1;
229  
230 }
« Google/Search.pm ↑ Summary Google/tool.pm »