Changeset 57

Show
Ignore:
Timestamp:
02/08/06 21:17:11
Author:
miyagawa
Message:

Allows new plugin loading system ala MT: just have a plain perl module file in plugin_path. Fixes #8

Files:

Legend:

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

    r54 r57  
    66use Carp; 
    77use Data::Dumper; 
     8use File::Find::Rule; 
    89use YAML; 
    910use UNIVERSAL::require; 
     
    5556 
    5657    if ($self->conf->{plugin_path}) { 
    57         unshift @INC, @{ $self->conf->{plugin_path} }; 
     58        my $rule = File::Find::Rule->new; 
     59           $rule->file; 
     60           $rule->name( qr/^\w[\w\.]*$/ ); 
     61        my @files = $rule->in(@{ $self->conf->{plugin_path} }); 
     62 
     63        for my $file (@files) { 
     64            next if $file =~ /\W(?:\.svn|CVS)\b/; 
     65            eval { require $file }; 
     66            die "loading plugin $file failed: $@" if $@; 
     67        } 
    5868    } 
    5969 
     
    6979    $module =~ s/^Plagger::Plugin:://; 
    7080    $module = "Plagger::Plugin::$module"; 
    71     $module->require or die $@; 
     81 
     82    unless ($module->isa('Plagger::Plugin')) { 
     83        $module->require or die $@; 
     84    } 
    7285 
    7386    $self->log(info => "plugin $module loaded.");