Dear Home Owner, このページをアンテナに追加 RSSフィード

 | 

2006-04-17

P::P::Filter::Permalink  P::P::Filter::Permalink - Dear Home Owner, を含むブックマーク はてなブックマーク -  P::P::Filter::Permalink - Dear Home Owner,  P::P::Filter::Permalink - Dear Home Owner, のブックマークコメント

package Plagger::Plugin::Filter::Permalink;
use strict;
use base qw( Plagger::Plugin );

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'update.entry.fixup' => \&filter,
    );
}

sub filter {
    my($self, $context, $args) = @_;

    my $match = $self->conf->{match};

    if($args->{entry}->permalink =~ m/$match/) {
	local $_ = $args->{entry}->permalink;
	
	my $rewrites = ref($self->conf->{rewrite}) ? $self->conf->{rewrite} : [ $self->conf->{rewrite} ];
	my $count = 0;
	for my $rewrite (@$rewrites) {
	    $count += eval $rewrite;
	}
	
	if ($count) {
	    my $permalink_orig = $args->{entry}->permalink;
	    $args->{entry}->link($_);
	    $context->log(info => "Permalink $permalink_orig rewritten to $_");
	}
    }
}

1;

__END__

=head1 NAME

Plagger::Plugin::Filter::Permalink - Rewrite permalink using Regexp

=head1 SYNOPSIS

  - module: Filter::Permalink
    config:
      match: rikunabi\-next\.yahoo\.co\.jp
      rewrite:
        - s/;jsessionid=\w+//
        - s/&__m=\d+//
        - s/&f=\w+//
        - s/&vos=\w+//
        - s/&Try=\w+//

=head1 DESCRIPTION

This plugin rewrites permalink using Regexp.

=head1 AUTHOR

youpy

=head1 SEE ALSO

L<Plagger>

=cut
トラックバック - http://subtech.g.hatena.ne.jp/youpy/20060417
 |