root/trunk/plagger/lib/Plagger/Plugin/Filter/AtomLinkRelated.pm

Revision 649 (checked in by miyagawa, 15 years ago)

new plugin AtomLinkRelated?: use link rel=related as true link. Refs #148

Line 
1 package Plagger::Plugin::Filter::AtomLinkRelated;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use List::Util qw(first);
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'aggregator.entry.fixup' => \&fixup,
12     );
13 }
14
15 # Note: Bloglines doesn't return link rel="related" value in its API and we're doomed
16
17 sub fixup {
18     my($self, $context, $args) = @_;
19
20     # Use Atom's link rel="related"
21     if (my $orig_link = $args->{orig_feed}->format eq 'Atom') {
22         my $rel = first { $_->rel eq 'related' } $args->{orig_entry}->{entry}->link; # XXX uses XML::Feed internal
23         if ($rel) {
24             $args->{entry}->link($rel->href);
25             $context->log(info => "Link rewritten to " . $rel->href);
26         }
27     }
28 }
29
30 1;
31
32 __END__
33
34 =head1 NAME
35
36 Plagger::Plugin::Filter::AtomLinkRelated - Use link rel="related" as entry link
37
38 =head1 SYNOPSIS
39
40   - module: Filter::AtomLinkRelated
41
42 =head1 DESCRIPTION
43
44 This plugin looks for Atom link elements with C<< rel="related" >>
45 relationship set. This way you can use original link defined in Social
46 Bookmark atom feeds like L<http://b.hatena.ne.jp/miyagawa/atomfeed>.
47
48 Note that this plugin only works with Plagger's own aggregator like
49 I<Aggregator::Simple> plugin, since Bloglines API doesn't return
50 related links in its response data.
51
52 =head1 AUTHOR
53
54 Tatsuhiko Miyagawa
55
56 =head1 SEE ALSO
57
58 L<Plagger>
59
60 =cut
Note: See TracBrowser for help on using the browser.