Changeset 77
- Timestamp:
- 02/17/06 15:55:16
- Files:
-
- trunk/plagger/lib/Plagger.pm (modified) (5 diffs)
- trunk/plagger/plugins (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger.pm
r73 r77 11 11 12 12 use base qw( Class::Accessor::Fast ); 13 __PACKAGE__->mk_accessors( qw(conf stash update subscription ) );13 __PACKAGE__->mk_accessors( qw(conf stash update subscription plugins_path) ); 14 14 15 15 use Plagger::Date; … … 36 36 update => Plagger::Update->new, 37 37 subscription => Plagger::Subscription->new, 38 plugins_path => {}, 38 39 }, $class; 39 40 … … 56 57 57 58 if ($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 $@; 59 for my $path (@{ $self->conf->{plugin_path} }) { 60 my $rule = File::Find::Rule->new; 61 $rule->file; 62 $rule->name( qr/^\w[\w\.]*$/ ); 63 my @files = $rule->in($path); 64 65 for my $file (@files) { 66 next if $file =~ /\W(?:\.svn|CVS)\b/; 67 my $pkg = $self->extract_package($file) 68 or die "Can't find package from $file"; 69 70 (my $base = $file) =~ s!^$path/!!; 71 $self->plugins_path->{$pkg} = $file; 72 } 67 73 } 68 74 } … … 71 77 $self->load_plugin($plugin) unless $plugin->{disable}; 72 78 } 79 } 80 81 sub extract_package { 82 my($self, $file) = @_; 83 84 open my $fh, $file or die "$file: $!"; 85 while (<$fh>) { 86 /^package (Plagger::Plugin::.*?);/ and return $1; 87 } 88 89 return; 73 90 } 74 91 … … 80 97 $module = "Plagger::Plugin::$module"; 81 98 82 unless ($module->isa('Plagger::Plugin')) { 99 if (my $path = $self->plugins_path->{$module}) { 100 eval { require $path } or die $@; 101 } else { 83 102 $module->require or die $@; 84 103 }
