Index: lib/Plagger/Plugin.pm =================================================================== --- lib/Plagger/Plugin.pm (revision 1676) +++ lib/Plagger/Plugin.pm (working copy) @@ -13,6 +13,7 @@ use File::Find::Rule (); use File::Spec; use Scalar::Util qw(blessed); +use List::Util qw(first); sub new { my($class, $opt) = @_; @@ -104,18 +105,42 @@ sub assets_dir { my $self = shift; my $context = Plagger->context; + return first {$_ } $self->assets_dir_multiple; +} +sub assets_dir_multiple { + my $self = shift; + my $context = Plagger->context; + + my @ret; + if ($self->conf->{assets_path}) { - return $self->conf->{assets_path}; # look at config:assets_path first + if (ref($self->conf->{assets_path}) eq 'ARRAY') { + push(@ret, $_) for @{$self->conf->{assets_path}}; + } else { + push(@ret, $self->conf->{assets_path}) + } } - my $assets_base = - $context->conf->{assets_path} || # or global:assets_path - File::Spec->catfile($FindBin::Bin, "assets"); # or "assets" under plagger script + my @assets_dir_bases; + if ($context->conf->{assets_path}) { + if (ref($context->conf->{assets_path}) eq 'ARRAY') { + push(@assets_dir_bases, $_) for @{$context->conf->{assets_path}}; + } else { + push(@assets_dir_bases, $context->conf->{assets_path}) + } + } + push(@assets_dir_bases, + File::Spec->catfile($FindBin::Bin, "assets"), + "/usr/share/plagger/assets", + ); - return File::Spec->catfile( - $assets_base, "plugins", $self->class_id, - ); + for my $one (@assets_dir_bases) { + my $onepath = File::Spec->catfile($one, "plugins", $self->class_id); + push(@ret, $onepath) if -d $onepath; + } + + return @ret; } sub log { @@ -153,9 +178,13 @@ $rule = File::Find::Rule->name($rule); } - # $rule isa File::Find::Rule - for my $file ($rule->in($self->assets_dir)) { + Plagger::context->log(info => "load assets from $_") + for $self->assets_dir_multiple; + + my %loaded; + for my $file ($rule->in($self->assets_dir_multiple)) { my $base = File::Basename::basename($file); + next if $loaded{$base}++; $callback->($file, $base); } }