line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::ICan::tSpell; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
136931
|
use Moo; |
|
2
|
|
|
|
|
22744
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
3974
|
use MooX::LazierAttributes qw/rw lzy/; |
|
2
|
|
|
|
|
6547
|
|
|
2
|
|
|
|
|
10
|
|
7
|
2
|
|
|
2
|
|
1124
|
use MooX::ValidateSubs; |
|
2
|
|
|
|
|
1147
|
|
|
2
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
243730
|
use Types::Standard qw/Object Str HashRef/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
20
|
|
9
|
2
|
|
|
2
|
|
3339
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
101829
|
|
|
2
|
|
|
|
|
88
|
|
10
|
2
|
|
|
2
|
|
1089
|
use URI::Escape; |
|
2
|
|
|
|
|
2776
|
|
|
2
|
|
|
|
|
135
|
|
11
|
2
|
|
|
2
|
|
15
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
981
|
|
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__ |