Show
Ignore:
Timestamp:
09/10/08 10:32:15 (6 years ago)
Author:
lopnor
Message:

lang/perl/App-Hachero: plugin_path support thanks to id:yappo's Module::Collect

Location:
lang/perl/App-Hachero/trunk
Files:
5 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Hachero/trunk/Makefile.PL

    r18891 r19113  
    2121requires 'File::Find::Rule'; 
    2222requires 'UNIVERSAL::require'; 
     23requires 'IO::All'; 
     24requires 'Module::Collect'; 
    2325 
    2426build_requires 'Test::More'; 
  • lang/perl/App-Hachero/trunk/lib/App/Hachero.pm

    r18806 r19113  
    66use Class::Component; 
    77use base qw(Class::Accessor::Fast); 
    8 #use Params::Validate; 
    98use UNIVERSAL::require; 
    109use File::Spec; 
    11 #use Log::Dispatch; 
     10use Module::Collect; 
     11 
    1212__PACKAGE__->load_components(qw/Plaggerize Autocall::InjectMethod/); 
    13 __PACKAGE__->mk_accessors(qw/currentline currentlog currentinfo result work_path/); 
     13__PACKAGE__->mk_accessors(qw/currentline currentlog currentinfo result work_path packages_from_plugin_path/); 
    1414 
    1515my $context; 
     
    1818sub new { 
    1919    my $class = shift; 
     20 
    2021    my $self = $class->SUPER::new(@_); 
    2122    $self->result({}); 
     
    6061} 
    6162 
     63sub setup_plugins { 
     64    my ($self, @args) = @_; 
     65 
     66    my $class_component_plugins = $self->class_component_plugins; 
     67 
     68    $self->packages_from_plugin_path([]); 
     69 
     70    if (my $path = $self->conf->{global}{plugin_path}) { 
     71        my $collect = Module::Collect->new( 
     72            path => $path, 
     73            pattern => '*.pm', 
     74            prefix => 'App::Hachero::Plugin', 
     75        ); 
     76        my $packages = $collect->modules; 
     77 
     78        $self->packages_from_plugin_path($packages); 
     79    } 
     80    $self->NEXT( setup_plugins => @args ); 
     81} 
     82 
     83sub class_component_load_plugin_resolver { 
     84    my ($self, $package) = @_; 
     85    $package = "App::Hachero::Plugin::$package"; 
     86    for my $pkg (@{ $self->packages_from_plugin_path }) { 
     87        return $pkg if $pkg->{package} eq $package; 
     88    } 
     89    return undef; 
     90} 
     91 
    62921; 
  • lang/perl/App-Hachero/trunk/t/plugin/input/03_file.t

    r18891 r19113  
    11use strict; 
    22use warnings; 
    3 use Test::More tests => 4; 
     3use Test::More tests => 3; 
    44use App::Hachero; 
    55use IO::All; 
     
    3030} 
    3131 
     32my @result; 
    3233for (@expected) { 
    3334    $app->run_hook('input'); 
    34     is $app->currentline, $_; 
     35    push @result, $app->currentline; 
    3536} 
     37is_deeply [sort @result], \@expected; 
    3638 
    3739END {