root/trunk/plagger/lib/Plagger/Plugin/Subscription/Planet.pm

Revision 1173 (checked in by miyagawa, 14 years ago)

Merge from refactoring-planet. YAY!

Line 
1 package Plagger::Plugin::Subscription::Planet;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::Config );
4
5 use Encode;
6 use URI::Escape;
7
8 sub load {
9     my($self, $context) = @_;
10
11     my $keyword = $self->conf->{keyword};
12        $keyword = [ $keyword ] unless ref $keyword;
13
14     my $lang = $self->conf->{lang} || 'default';
15     $lang = [ $lang ] unless ref $lang;
16
17     $self->load_assets(
18         File::Find::Rule->file->name([ map "$_.yaml", @$lang ]),
19         sub {
20             my($file) = @_;
21             my $data = YAML::LoadFile($file);
22             push @{ $self->{engines} }, @{ $data->{engines} };
23         },
24     );
25
26     for my $kw (@$keyword) {
27         for my $site (@{ $self->{engines} }) {
28             my $site_url = $site; # copy
29
30             # use eval ... die to skip if there's no url/keyword
31             eval {
32                 $site_url =~ s{{([\w\-\:]+)}}{
33                     my($key, $encoding) = split /:/, $1;
34
35                     my $data = $self->conf->{$key} or die "$key is not there";
36                     if ($encoding && $encoding ne 'utf-8') {
37                         Encode::from_to($data, "utf-8" => $encoding);
38                     }
39
40                     my $chunk = URI::Escape::uri_escape($data);
41                     $chunk =~ s/%20/+/g; # hack
42                     $chunk;
43                 }eg;
44                 push @{$self->conf->{feed}}, { url => $site_url }
45             };
46         }
47     }
48
49     $self->SUPER::load($context);
50 }
51
52 1;
53
54 __END__
55
56 =head1 NAME
57
58 Plagger::Plugin::Subscription::Planet - Ego search subscription
59
60 =head1 SYNOPSIS
61
62   - module: Subscription::Planet
63     config:
64       keyword: Plagger
65       lang: en
66
67 =head1 DESCRIPTION
68
69 This plugin gives a handy way to subscribe to dozens of feed / web
70 search engine results by just supplying keywords.
71
72 =head1 CONFIG
73
74 =over 4
75
76 =item keyword
77
78 The keyword to use as a query in web search engines. Required.
79
80 =item lang
81
82 Language code to either 1) specify list of search engines or 2) pass
83 to search query.  Optional.
84
85 For example, technorati.jp will be added if you use I<ja>, while
86 technorati.com will be if you use I<en>. Default is to search
87 everything.
88
89 =back
90
91 =head1 EXAMPLES
92
93   # search "Plagger" on default engines
94   - module: Subscription::Planet
95     config:
96       keyword: Plagger
97
98   # search "Pokemon" on Japanese search engines
99   - module: Subscription::Planet
100     config:
101       keyword: Pokemon
102       lang: ja
103
104   # search "Plagger" and pages linking to "http://plagger.org/"
105   - module: Subscription::Planet
106     config:
107       keyword: Plagger
108       url: http://plagger.org/
109
110 =head1 AUTHOR
111
112 youpy
113
114 Tatsuhiko Miyagawa
115
116 =head1 SEE ALSO
117
118 L<Plagger>
119
120 =cut
Note: See TracBrowser for help on using the browser.