| 1 | package Acme::ICan::tSpell; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.05'; | |||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use MooX::LazierAttributes qw/rw lzy/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use MooX::ValidateSubs; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Types::Standard qw/Object Str HashRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use HTTP::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use URI::Escape; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | attributes ( | ||||||||||
| 14 | 0 | ▶ | tiny => [Object, {lzy, default => sub {HTTP::Tiny->new}}], | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||
| 15 | base_url => [Str, {lzy, default => 'http://www.google.com/search?gws_rd=ssl&hl=en&q='}], | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 1 | 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 | 3 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 28 | 3 | my $response = $_[0]->tiny->get($_[1]); | |||||||||
| 29 | 3 | ▶ | $response->{success} and return $response; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | croak sprintf "something went terribly wrong: status - %s - reason - %s", | ||||||||||
| 31 | 1 | $response->{status}, $response->{reason}; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 3 | ▶ | sub spell_check { | ||||||||
|
Subroutine
spell_check: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | 3 | my $moon = $_[0]->get(sprintf('%s%s', $_[1]->{base_url}, uri_escape($_[1]->{check})))->{content}; | |||||||||
| 36 | 2 | ▶ | if ($moon =~ m{(?:Showing results for|Did you mean|Including results for)[^\0]*?<a.*?>(.*?)</a>}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | (my $str = $1) =~ s/<.*?>//g; | |||||||||
| 38 | 1 | return $_[0]->spell_check({ check => $str }); # work around googles struggles | |||||||||
| 39 | } | ||||||||||
| 40 | 1 | return $_[1]->{check}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | ▶ | sub spell { | ||||||||
|
Subroutine
spell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 2 | return $_[0]->spell_check({ check => $_[1] }); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||