root/branches/feature-server/plagger/lib/Plagger/Plugin/Filter/HatenaBookmarkTag.pm

Revision 189 (checked in by miyagawa, 3 years ago)

Added docs to some plugins

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Filter::HatenaBookmarkTag;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use URI;
6 use XML::Feed;
7
8 $XML::Feed::RSS::PREFERRED_PARSER = 'XML::RSS::LibXML';
9
10 sub register {
11     my($self, $context) = @_;
12     $context->register_hook(
13         $self,
14         'update.entry.fixup' => \&update,
15     );
16 }
17
18 sub update {
19     my($self, $context, $args) = @_;
20
21     # xxx need cache & interval
22     my $url  = 'http://b.hatena.ne.jp/entry/rss/' . $args->{entry}->permalink;
23     my $feed = XML::Feed->parse( URI->new($url) );
24
25     unless ($feed) {
26         $context->log(warn => "Feed error $url: " . XML::Feed->errstr);
27         return;
28     }
29
30     for my $entry ($feed->entries) {
31         my $tag = $entry->category or next;
32            $tag = [ $tag ] unless ref($tag);
33
34         for my $t (@{$tag}) {
35             $args->{entry}->add_tag($t);
36         }
37     }
38 }
39
40 1;
41
42 __END__
43
44 =head1 NAME
45
46 Plagger::Plugin::Filter::HatenaBookmarkTag - Fetch tags from Hatena Bookmark
47
48 =head1 SYNOPSIS
49
50   - module: Filter::HatenaBookmarkTag
51
52 =head1 DESCRIPTION
53
54 B<Note: this module is mostly untested and written just for a proof of
55 concept. If you run this on your box with real feeds, Hatena might
56 throttle your IP. See http://b.hatena.ne.jp/ for details.>
57
58 This plugin queries Hatena Bookmark (L<http://b.hatena.ne.jp/>) using
59 its RSS feeds API to get the tags people added to the entries.
60
61 =head1 AUTHOR
62
63 Tatsuhiko Miyagawa
64
65 =head1 SEE ALSO
66
67 L<Plagger>, L<Plagger::Plugin::Filter::HatenaBookmarkUsersCount>,
68 L<http://b.hatena.ne.jp/>
69
70 =cut
Note: See TracBrowser for help on using the browser.