Changeset 409

Show
Ignore:
Timestamp:
03/24/06 16:19:33
Author:
miyagawa
Message:
  • Move Filter::TTP under new Filter::Base
  • Updated Makefile.PL
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/Makefile.PL

    r408 r409  
    176176        recommends('SVN::Client'), 
    177177    ], 
     178    'Filter::TTP' => [ 
     179        -default => 0, 
     180        recommends('URI::Find'), 
     181    ], 
    178182); 
    179183 
     
    186190    ); 
    187191 
    188 install_script('bin/spotlight_comment.scpt'); 
     192    install_script('bin/spotlight_comment.scpt'); 
    189193 
    190194} elsif ($^O eq 'MSWin32') { 
  • trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm

    r244 r409  
    11package Plagger::Plugin::Filter::TTP; 
    22use strict; 
    3 use base qw( Plagger::Plugin ); 
     3use base qw( Plagger::Plugin::Filter::Base ); 
    44 
    55use URI::Find; 
     6use URI::http; 
    67 
    7 sub register { 
    8     my($self, $context) = @_; 
    9     $context->register_hook( 
    10         $self, 
    11         'update.entry.fixup' => \&update, 
    12     ); 
    13 
    14  
    15 sub update { 
    16     my($self, $context, $args) = @_; 
    17     my $body = $args->{entry}->body; 
    18  
    19     my $count; 
    20     if ($self->conf->{text_only}) { 
    21         ($count, $body) = $self->paranoia_rewrite($body); 
    22     } else { 
    23         ($count, $body) = $self->rewrite_ttp($body); 
    24     } 
    25  
    26     if ($count) { 
    27         $context->log(info => "Rewrite $count ttp:// link(s) to http://"); 
    28     } 
    29  
    30     $args->{entry}->body($body); 
    31 
    32  
    33 sub rewrite_ttp { 
     8sub filter { 
    349    my($self, $body) = @_; 
    3510 
     
    4924    $finder->find(\$body); 
    5025    ($count, $body); 
    51 } 
    52  
    53 sub paranoia_rewrite { 
    54     my($self, $body) = @_; 
    55     require HTML::Parser; 
    56  
    57     my($count, $output); 
    58  
    59     my $p = HTML::Parser->new(api_version => 3); 
    60     $p->handler( default => sub { $output .= $_[0] }, "text" ); 
    61     $p->handler( text => sub { 
    62         my($c, $body) = $self->rewrite_ttp($_[0]); 
    63         $count  += $c; 
    64         $output .= $body; 
    65     }, "text"); 
    66  
    67     $p->parse($body); 
    68     $p->eof; 
    69  
    70     ($count, $output); 
    7126} 
    7227