line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::ICan::tSpell; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
101673
|
use Moo; |
|
2
|
|
|
|
|
19813
|
|
|
2
|
|
|
|
|
13
|
|
6
|
2
|
|
|
2
|
|
3294
|
use MooX::LazierAttributes qw/rw lzy/; |
|
2
|
|
|
|
|
5307
|
|
|
2
|
|
|
|
|
8
|
|
7
|
2
|
|
|
2
|
|
857
|
use MooX::ValidateSubs; |
|
2
|
|
|
|
|
1052
|
|
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
207389
|
use Types::Standard qw/Object Str HashRef/; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
25
|
|
9
|
2
|
|
|
2
|
|
3033
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
71542
|
|
|
2
|
|
|
|
|
84
|
|
10
|
2
|
|
|
2
|
|
677
|
use URI::Escape; |
|
2
|
|
|
|
|
2121
|
|
|
2
|
|
|
|
|
127
|
|
11
|
2
|
|
|
2
|
|
13
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
688
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
attributes ( |
14
|
|
|
|
|
|
|
tiny => [Object, {lzy, default => sub {HTTP::Tiny->new}}], |
15
|
|
|
|
|
|
|
base_url => [Str, {lzy, default => 'http://www.google.com/search?gws_rd=ssl&hl=en&q='}], |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
validate_subs ( |
19
|
|
|
|
|
|
|
get => { params => [ [Str] ], returns => [[HashRef]] }, |
20
|
|
|
|
|
|
|
spell_check => { |
21
|
|
|
|
|
|
|
params => { check => [Str], base_url => [Str, 'base_url'] }, |
22
|
|
|
|
|
|
|
returns => [[Str]], |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
spell => { params => [[Str]], returns => [[Str]] }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get { |
28
|
|
|
|
|
|
|
my $response = $_[0]->tiny->get($_[1]); |
29
|
|
|
|
|
|
|
$response->{success} and return $response; |
30
|
|
|
|
|
|
|
croak sprintf "something went terribly wrong status - %s - reason - %s", |
31
|
|
|
|
|
|
|
$response->{status}, $response->{reason}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub spell_check { |
35
|
|
|
|
|
|
|
my $moon = $_[0]->get(sprintf('%s%s', $_[1]->{base_url}, uri_escape($_[1]->{check})))->{content}; |
36
|
|
|
|
|
|
|
if ($moon =~ m{(?:Showing results for|Did you mean|Including results for)[^\0]*?(.*?)}){ |
37
|
|
|
|
|
|
|
(my $str = $1) =~ s/<.*?>//g; |
38
|
|
|
|
|
|
|
return $_[0]->spell_check({ check => $str }); # work around googles struggles |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
return $_[1]->{check}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub spell { |
44
|
|
|
|
|
|
|
return $_[0]->spell_check({ check => $_[1] }); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |