Changeset 1592

Show
Ignore:
Timestamp:
08/24/06 21:09:53
Author:
miyagawa
Message:

refactored Filter::StripRSSAd to use load_assets. Accept qr// in load_assets 1st parameter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin.pm

    r1591 r1592  
    1313use File::Find::Rule (); 
    1414use File::Spec; 
     15use Scalar::Util qw(blessed); 
    1516 
    1617sub new { 
     
    149150    my($self, $rule, $callback) = @_; 
    150151 
    151     unless (ref($rule)) { 
     152    unless (blessed($rule) && $rule->isa('File::Find::Rule')) { 
    152153        $rule = File::Find::Rule->name($rule); 
    153154    } 
  • trunk/plagger/lib/Plagger/Plugin/Filter/StripRSSAd.pm

    r1588 r1592  
    99    $self->SUPER::init(@_); 
    1010    Plagger->context->autoload_plugin('Filter::BloglinesContentNormalize'); 
    11     $self->load_patterns(); 
    12 } 
    1311 
    14 sub load_patterns { 
    15     my $self = shift; 
    16  
    17     my $dir = $self->assets_dir; 
    18     my $dh = DirHandle->new($dir) or Plagger->context->error("$dir: $!"); 
    19     for my $file (grep -f $_->[0] && $_->[1] =~ /^[\w\-\.]+$/, 
    20                   map [ File::Spec->catfile($dir, $_), $_ ], sort $dh->read) { 
    21         $self->load_pattern(@$file); 
    22     } 
    23 
    24  
    25 sub load_pattern { 
    26     my($self, $file, $base) = @_; 
    27  
    28     Plagger->context->log(debug => "loading $file"); 
    29  
    30     if ($file =~ /\.yaml$/) { 
    31         $self->load_yaml($file, $base); 
    32     } else { 
    33         $self->load_regexp($file, $base); 
    34     } 
     12    $self->load_assets('*.yaml',      sub { $self->load_yaml(@_) }); 
     13    $self->load_assets(qr/^[\w\-]+$/, sub { $self->load_regexp(@_)}); 
    3514} 
    3615 
    3716sub load_regexp { 
    3817    my($self, $file, $base) = @_; 
     18    Plagger->context->log(debug => "Load regexp $file"); 
    3919 
    4020    open my $fh, '<', $file or Plagger->context->error("$file: $!"); 
     
    4727sub load_yaml { 
    4828    my($self, $file, $base) = @_; 
     29    Plagger->context->log(debug => "Load YAML $file"); 
    4930 
    5031    my $pattern = eval { YAML::LoadFile($file) }