Changeset 1046
- Timestamp:
- 07/03/06 11:31:00
- Files:
-
- branches/refactoring-planet/plagger/Makefile.PL (modified) (2 diffs)
- branches/refactoring-planet/plagger/assets/plugins/Subscription-Planet (added)
- branches/refactoring-planet/plagger/assets/plugins/Subscription-Planet/default.yaml (added)
- branches/refactoring-planet/plagger/assets/plugins/Subscription-Planet/ja.yaml (added)
- branches/refactoring-planet/plagger/lib/Plagger.pm (modified) (2 diffs)
- branches/refactoring-planet/plagger/lib/Plagger/Plugin.pm (modified) (2 diffs)
- branches/refactoring-planet/plagger/lib/Plagger/Plugin/Aggregator/Null.pm (modified) (1 diff)
- branches/refactoring-planet/plagger/lib/Plagger/Plugin/Subscription/Planet.pm (modified) (4 diffs)
- branches/refactoring-planet/plagger/t/TestPlagger.pm (added)
- branches/refactoring-planet/plagger/t/plugins/Subscription-Planet/planet.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/refactoring-planet/plagger/Makefile.PL
r1006 r1046 31 31 32 32 build_requires(Test::More => 0.42); 33 build_requires(Test::Base => 0.52); 33 34 34 35 features( … … 277 278 tests 't/*.t t/*/*.t t/*/*/*.t'; 278 279 280 use_test_base; 281 279 282 auto_include; 280 283 auto_install; branches/refactoring-planet/plagger/lib/Plagger.pm
r1037 r1046 8 8 use File::Copy; 9 9 use File::Basename; 10 use File::Find::Rule ;10 use File::Find::Rule (); # don't import rule()! 11 11 use YAML; 12 12 use Storable; … … 63 63 $self->rewrite_config if @{ $self->{rewrite_tasks} }; 64 64 $self->run(); 65 66 $self; 65 67 } 66 68 branches/refactoring-planet/plagger/lib/Plagger/Plugin.pm
r1037 r1046 11 11 12 12 use FindBin; 13 use File::Find::Rule (); 13 14 use File::Spec; 14 15 … … 138 139 } 139 140 141 sub load_assets { 142 my($self, $rule, $callback) = @_; 143 144 my $context = Plagger->context; 145 146 my $dir = $self->assets_dir; 147 148 # $rule isa File::Find::Rule 149 for my $file ($rule->in($dir)) { 150 $callback->($file); 151 } 152 } 153 140 154 1; branches/refactoring-planet/plagger/lib/Plagger/Plugin/Aggregator/Null.pm
r921 r1046 14 14 my($self, $context, $args) = @_; 15 15 $context->update->add($args->{feed}); 16 return 1; 16 17 } 17 18 branches/refactoring-planet/plagger/lib/Plagger/Plugin/Subscription/Planet.pm
r1038 r1046 6 6 use URI::Escape; 7 7 8 my @sites = (9 'http://www.blogpulse.com/rss?query=%s&sort=date&operator=and',10 'http://www.feedster.jp/search/lang/all/%s',11 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=%s&scoring=d&ie=utf-8&num=100&output=rss',12 'http://blog-search.yahoo.co.jp/rss?p=%s:euc-jp',13 'http://blog.goo.ne.jp/search/search.php?status=select&tg=all&st=time&dc=10&dp=all&bu=&ts=all&MT=%s:euc-jp&da=all&rss=1',14 'http://www.namaan.net/rss?namaan=NAMA&ty=5&query=%s',15 'http://bulkfeeds.net/app/search2.rdf?q=%s',16 'http://rss.sf.livedoor.com/search?q=%s&sf=update_date&start=0',17 'http://b.hatena.ne.jp/t/%s?mode=rss&sort=eid&threshold=1',18 'http://d.hatena.ne.jp/keyworddiary/%s?mode=rss',19 'http://feeds.technorati.com/feed/posts/tag/%s',20 'http://bloglines.com/search?q=%s&ql=any&s=f&pop=l&news=m&n=100&format=rss',21 );22 23 8 sub load { 24 9 my($self, $context) = @_; … … 27 12 $keyword = [ $keyword ] unless ref $keyword; 28 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 29 26 for my $kw (@$keyword) { 30 for my $site (@sites) { 31 my $site_url = $site; 32 $site_url =~ s{%s(?::([\w\-]+))?}{ 33 my $query = $kw; 34 if ($1) { 35 Encode::from_to($query, "utf-8" => $1); 36 } 37 URI::Escape::uri_escape($query); 38 }eg; 39 push @{$self->conf->{feed}}, { url => $site_url } 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 }; 40 46 } 41 47 } … … 57 63 config: 58 64 keyword: Plagger 65 lang: en 59 66 60 67 =head1 DESCRIPTION … … 69 76 =item keyword 70 77 71 The keyword to use as a query in web search engines. 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. 72 88 73 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/ 74 109 75 110 =head1 AUTHOR branches/refactoring-planet/plagger/t/plugins/Subscription-Planet/planet.t
r1044 r1046 2 2 use FindBin; 3 3 use File::Spec; 4 use Test::More tests => 1;5 4 6 use Plagger; 7 Plagger->bootstrap(config => \<<CONFIG); 5 use t::TestPlagger; 6 7 plan tests => 1 * blocks; 8 9 run { 10 my $block = shift; 11 my $context = $block->input; 12 eval $block->expected; 13 fail $@ if $@; 14 }; 15 16 17 __END__ 18 19 === Test simple keyword 20 --- input config 8 21 global: 9 22 log: 10 23 level: error 24 assets_path: $FindBin::Bin/../../../assets 11 25 plugins: 12 26 - module: Subscription::Planet 13 27 config: 14 28 keyword: foo 15 - module: Aggregator::Test 16 CONFIG 29 - module: Aggregator::Null 30 --- expected 31 is $context->subscription->feeds->[0]->url, 'http://feeds.technorati.com/feed/posts/tag/foo', $block->name 17 32 18 package Plagger::Plugin::Aggregator::Test; 19 use base qw( Plagger::Plugin ); 33 === Test keyword with space in it 34 --- input config 35 global: 36 log: 37 level: error 38 assets_path: $FindBin::Bin/../../../assets 39 plugins: 40 - module: Subscription::Planet 41 config: 42 keyword: foo bar 43 - module: Aggregator::Null 44 --- expected 45 is $context->subscription->feeds->[0]->url, 'http://feeds.technorati.com/feed/posts/tag/foo+bar', $block->name; 20 46 21 sub register { 22 my($self, $context) = @_; 23 $context->register_hook( 24 $self, 25 'customfeed.handle' => \&load, 26 'aggregator.finalize' => \&test, 27 ); 28 } 47 === Test multibyte keyword 48 --- input config 49 global: 50 log: 51 level: error 52 assets_path: $FindBin::Bin/../../../assets 53 plugins: 54 - module: Subscription::Planet 55 config: 56 keyword: ぷらがー 57 - module: Aggregator::Null 58 --- expected 59 is $context->subscription->feeds->[0]->url, 'http://feeds.technorati.com/feed/posts/tag/%E3%81%B7%E3%82%89%E3%81%8C%E3%83%BC', $block->name; 29 60 30 sub load { 31 my($self, $context, $args) = @_; 32 push @{$self->{feeds}}, $args->{feed}->url; 33 return 1; 34 } 61 === Test keyword and URL 62 --- input config 63 global: 64 log: 65 level: error 66 assets_path: $FindBin::Bin/../../../assets 67 plugins: 68 - module: Subscription::Planet 69 config: 70 keyword: Plagger 71 url: http://plagger.org/ 72 - module: Aggregator::Null 73 --- expected 74 is $context->subscription->feeds->[-1]->url, "http://www.bloglines.com/search?q=bcite:http%3A%2F%2Fplagger.org%2F&ql=any&s=f&pop=n&news=m&n=100&format=rss", $block->name; 35 75 36 sub test { 37 my $self = shift; 38 ::is $self->{feeds}[0], 'http://www.blogpulse.com/rss?query=foo&sort=date&operator=and'; 39 } 76 === Test lang=ja 77 --- input config 78 global: 79 log: 80 level: error 81 assets_path: $FindBin::Bin/../../../assets 82 plugins: 83 - module: Subscription::Planet 84 config: 85 keyword: Plagger 86 lang: ja 87 - module: Aggregator::Null 88 --- expected 89 is $context->subscription->feeds->[0]->url, "http://www.feedster.jp/search/type/rss/Plagger", $block->name; 90 91 === Test lang=ja with euc-jp 92 --- input config 93 global: 94 log: 95 level: error 96 assets_path: $FindBin::Bin/../../../assets 97 plugins: 98 - module: Subscription::Planet 99 config: 100 keyword: しょこたん 101 lang: ja 102 - module: Aggregator::Null 103 --- expected 104 is $context->subscription->feeds->[1]->url, "http://blog-search.yahoo.co.jp/rss?p=%A4%B7%A4%E7%A4%B3%A4%BF%A4%F3", $block->name; 105
