Changeset 1591

Show
Ignore:
Timestamp:
08/24/06 20:59:50
Author:
miyagawa
Message:

refacored EntryFullText? to use load_assets. Plugin->load_assets can take filename as its 1st argument to make it easier. Callback function now takes base filename as 2nd parameter

Files:

Legend:

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

    r1412 r1591  
    149149    my($self, $rule, $callback) = @_; 
    150150 
    151     my $context = Plagger->context; 
    152  
    153     my $dir = $self->assets_dir; 
     151    unless (ref($rule)) { 
     152        $rule = File::Find::Rule->name($rule); 
     153    } 
    154154 
    155155    # $rule isa File::Find::Rule 
    156     for my $file ($rule->in($dir)) { 
    157         $callback->($file); 
     156    for my $file ($rule->in($self->assets_dir)) { 
     157        my $base = File::Basename::basename($file); 
     158        $callback->($file, $base); 
    158159    } 
    159160} 
  • trunk/plagger/lib/Plagger/Plugin/Filter/EntryFullText.pm

    r1588 r1591  
    3737    my $context = Plagger->context; 
    3838 
    39     my $dir = $self->assets_dir; 
    40     my $dh = DirHandle->new($dir) or $context->error("$dir: $!"); 
    41     for my $file (grep -f $_->[0] && $_->[0] =~ /\.(?:pl|yaml)$/, 
    42                   map [ File::Spec->catfile($dir, $_), $_ ], sort $dh->read) { 
    43         $self->load_plugin(@$file); 
    44     } 
    45 
    46  
    47 sub load_plugin { 
    48     my($self, $file, $base) = @_; 
    49  
    50     Plagger->context->log(debug => "loading $file"); 
    51  
    52     my $load_method = $file =~ /\.pl$/ ? 'load_plugin_perl' : 'load_plugin_yaml'; 
    53     push @{ $self->{plugins} }, $self->$load_method($file, $base); 
     39    $self->load_assets('*.yaml', sub { $self->load_plugin_yaml(@_) }); 
     40    $self->load_assets('*.pl',   sub { $self->load_plugin_perl(@_) }); 
    5441} 
    5542 
    5643sub load_plugin_perl { 
    5744    my($self, $file, $base) = @_; 
     45 
     46    Plagger->context->log(debug => "Load plugin $file"); 
    5847 
    5948    open my $fh, '<', $file or Plagger->context->error("$file: $!"); 
     
    8069    Plagger->context->error($@) if $@; 
    8170 
    82     return $plugin_class->new; 
     71    push @{ $self->{plugins} }, return $plugin_class->new; 
    8372} 
    8473 
    8574sub load_plugin_yaml { 
    8675    my($self, $file, $base) = @_; 
     76 
     77    Plagger->context->log(debug => "Load YAML $file"); 
    8778    my @data = YAML::LoadFile($file); 
    8879 
    89     return map { Plagger::Plugin::Filter::EntryFullText::YAML->new($_, $base) } 
    90         @data; 
     80    push @{ $self->{plugins} }, 
     81        map { Plagger::Plugin::Filter::EntryFullText::YAML->new($_, $base) } @data; 
    9182} 
    9283 
  • trunk/plagger/lib/Plagger/Plugin/Filter/TruePermalink.pm

    r1590 r1591  
    2020 
    2121    $self->load_assets( 
    22         File::Find::Rule->name('*.yaml')
     22        '*.yaml'
    2323        sub { 
    2424            my $file = shift; 
  • trunk/plagger/lib/Plagger/Plugin/Widget/Simple.pm

    r1339 r1591  
    2222        my $found; 
    2323        $self->load_assets( 
    24             File::Find::Rule->name("$name.yaml")
     24            "$name.yaml"
    2525            sub { 
    2626                my $data = YAML::LoadFile(shift); 
  • trunk/plagger/t/plugins/Filter-EntryFullText/kojiinet.t

    r1383 r1591  
    2424  - module: Filter::EntryFullText 
    2525--- expected 
     26ok $context->update->feeds->[0]->entries->[0]->body; 
    2627unlike $context->update->feeds->[0]->entries->[0]->body, qr/&#\d+;/; 
    2728