| 1 | package App::SocialSKK::Plugin::HatenaBookmark; | ||
| 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 XML::RSS; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | use Jcode; | ||
| 6 | use base qw(App::SocialSKK::Plugin); | ||
| 7 | |||
| 8 | __PACKAGE__->mk_accessors(qw(limit)); | ||
| 9 | |||
| 10 | sub get_candidates { | ||
| 11 | my ($self, $text) = @_; | ||
| 12 | return if ($text || '') eq ''; | ||
| 13 | |||
| 14 | my @candidates; | ||
| 15 | $text = Jcode->new($text, 'euc')->utf8; | ||
| 16 | if ($text =~ /(?:はてぶにんききじ|ほってんとり)/) { | ||
| 17 | my $rss = XML::RSS->new(version => '1.0'); | ||
| 18 | my $uri = URI->new('http://feedproxy.google.com/hatena/b/hotentry'); | ||
| 19 | my $res = $self->ua->get($uri); | ||
| 20 | my $limit = $self->limit || 10; | ||
| 21 | if ($res->is_success) { | ||
| 22 | eval { $rss->parse($res->content) }; | ||
| 23 | return if $@; | ||
| 24 | |||
| 25 | my $i = 0; | ||
| 26 | for my $entry (@{$rss->{items}}) { | ||
| 27 | last if ++$i >= $limit; | ||
| 28 | my $candidate = sprintf '%s;%s', | ||
| 29 | $entry->{title} || '', $entry->{description} || ''; | ||
| 30 | push @candidates, Jcode->new($candidate, 'utf8')->euc; | ||
| 31 | } | ||
| 32 | return @candidates; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ | ||
| 40 | |||
| 41 | =head1 NAME | ||
| 42 | |||
| 43 | App::SocialSKK::Plugin::HatenaBookmark - Retrieves Candidates from | ||
| 44 | Hatena::Bookmark | ||
| 45 | |||
| 46 | =head1 SYNOPSIS | ||
| 47 | |||
| 48 | # Add a line like below into your .socialskk: | ||
| 49 | plugins: | ||
| 50 | - name: Hatena::Bookmark | ||
| 51 | config: | ||
| 52 | limit: 5 | ||
| 53 | |||
| 54 | =head1 DESCRIPTION | ||
| 55 | |||
| 56 | App::SocialSKK::Plugin::HatenaBookmakr performs retrieval of | ||
| 57 | candidates from Hatena::Bookmark | ||
| 58 | |||
| 59 | =head1 SEE ALSO | ||
| 60 | |||
| 61 | =over 4 | ||
| 62 | |||
| 63 | =item * Hatena::Bookmark | ||
| 64 | |||
| 65 | http://b.hatena.ne.jp/ | ||
| 66 | |||
| 67 | =back | ||
| 68 | |||
| 69 | =head1 AUTHOR | ||
| 70 | |||
| 71 | Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt> | ||