| 1 | package App::SocialSKK::Plugin::Wikipedia; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use URI::QueryParam; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use JSON::Syck; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Jcode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Encode::JavaScript::UCS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use base qw(App::SocialSKK::Plugin); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub get_candidates { | ||||||||||||||||||
|
Subroutine
get_candidates: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 13 | 0 | my ($self, $text) = @_; | |||||||||||||||||||
| 14 | 0 | ▶ | return if ($text || '') eq ''; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$text || ''
MC/DC0%0/1
$text || ''
$text
Truth table0%0/2
A
A= $text
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | $text = Jcode->new($text, 'euc')->utf8; | |||||||||||||||||||
| 17 | 0 | my $uri = URI->new('http://ja.wikipedia.org/w/api.php'); | |||||||||||||||||||
| 18 | 0 | $uri->query_param(action => 'opensearch'); | |||||||||||||||||||
| 19 | 0 | $uri->query_param(namespace => 0); | |||||||||||||||||||
| 20 | 0 | $uri->query_param(search => $text); | |||||||||||||||||||
| 21 | 0 | my $res = $self->ua->get($uri); | |||||||||||||||||||
| 22 | 0 | ▶ | if ($res->is_success) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | my $array = JSON::Syck::Load($res->content); | |||||||||||||||||||
| 24 | map { | ||||||||||||||||||||
| 25 | 0 | my $text = Encode::JavaScript::UCS::decode('JavaScript-UCS', $_); | |||||||||||||||||||
| 26 | 0 | $text = Jcode->new($text, 'utf8')->euc; | |||||||||||||||||||
| 27 | 0 | } @{$array->[-1]}; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | 1; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | __END__ | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head1 NAME | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | App::SocialSKK::Plugin::Wikipedia - Retrieves Candidates from | ||||||||||||||||||||
| 38 | Wikipedia | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 SYNOPSIS | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # Add a line like below into your .socialskk: | ||||||||||||||||||||
| 43 | plugins: | ||||||||||||||||||||
| 44 | - name: Wikipedia | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | App::SocialSKK::Plugin::Wikipedia performs retrieval of candidates | ||||||||||||||||||||
| 49 | from Wikipedia suggest API. | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =head1 SEE ALSO | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =over 4 | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =item * Wikipedia | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | http://ja.wikipedia.org/ | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =back | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 AUTHOR | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt> | ||||||||||||||||||||