Plugin::Widget::CPAN
entryのbodyにPerlのモジュールらしきものがあったらCPANへの検索リンクをつけたすWidget。
package Plagger::Plugin::Widget::CPAN; use strict; use base qw( Plagger::Plugin ); use Encode; use HTML::Entities; use URI; sub register { my($self, $context) = @_; $context->register_hook( $self, 'publish.entry.fixup' => \&add, ); } sub add { my($self, $context, $args) = @_; $args->{entry}->add_widget($self); } sub html { my($self, $entry) = @_; return unless ( $entry->body =~ /([a-z]+?::[a-z]+)/i ); my $module = $1; my $uri = URI->new('http://search.cpan.org/search'); $uri->query_form( query => $module, mode => $self->conf->{mode} || 'all', ); my $url = HTML::Entities::encode($uri->as_string); return qq(<a href="$url"><img src="http://search.cpan.org/favicon.ico" alt="$module" style="border:0;vertical-align:middle" /></a>); } 1;
- module: Widget::CPAN config: mode: all, module, dist or author # default all