Changeset 1391

Show
Ignore:
Timestamp:
08/19/06 15:55:27
Author:
miyagawa
Message:

merge from hackathon-mt

Files:

Legend:

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

    r1370 r1391  
    2727use Plagger::Update; 
    2828 
    29 sub context { undef } 
    30  
    31 sub bootstrap { 
     29my $context; 
     30sub context     { $context } 
     31sub set_context { $context = $_[1] } 
     32 
     33sub new { 
    3234    my($class, %opt) = @_; 
    3335 
     
    5254    } 
    5355 
    54     no warnings 'redefine'; 
    55     local *Plagger::context = sub { $self }; 
     56    Plagger->set_context($self); 
    5657 
    5758    $loader->load_recipes($config); 
     
    5960    $self->load_plugins(@{ $config->{plugins} || [] }); 
    6061    $self->rewrite_config if @{ $self->{rewrite_tasks} }; 
     62 
     63    $self; 
     64} 
     65 
     66sub bootstrap { 
     67    my $class = shift; 
     68    my $self = $class->new(@_); 
    6169    $self->run(); 
    62  
    6370    $self; 
     71} 
     72 
     73sub clear_session { 
     74    my $self = shift; 
     75    $self->{update}       = Plagger::Update->new; 
     76    $self->{subscription} = Plagger::Subscription->new; 
    6477} 
    6578 
     
    291304 
    292305    $self->run_hook('aggregator.finalize'); 
     306    $self->do_run_with_feeds; 
     307    $self->run_hook('plugin.finalize'); 
     308 
     309    Plagger->set_context(undef); 
     310    $self; 
     311} 
     312 
     313sub run_with_feeds { 
     314    my $self = shift; 
     315    $self->run_hook('plugin.init'); 
     316    $self->do_run_with_feeds; 
     317    $self->run_hook('plugin.finalize'); 
     318 
     319    Plagger->set_context(undef); 
     320    $self; 
     321} 
     322 
     323sub do_run_with_feeds { 
     324    my $self = shift; 
    293325 
    294326    for my $feed ($self->update->feeds) { 
     
    324356 
    325357    $self->run_hook('publish.finalize'); 
     358} 
     359 
     360sub search { 
     361    my($self, $query) = @_; 
     362 
     363    Plagger->set_context($self); 
     364    $self->run_hook('plugin.init'); 
     365 
     366    my @feeds; 
     367    $context->run_hook('searcher.search', { query => $query }, 0, sub { push @feeds, $_[0] }); 
     368 
     369    Plagger->set_context(undef); 
     370    return @feeds; 
    326371} 
    327372 
  • trunk/plagger/lib/Plagger/ConfigLoader.pm

    r1327 r1391  
    2929    my($self, $config) = @_; 
    3030 
    31     return unless $config->{include}; 
    32     for (@{ $config->{include} }) { 
    33         my $include = YAML::LoadFile($_); 
     31    my $includes = $config->{include} or return; 
     32    $includes = [ $includes ] unless ref $includes; 
     33 
     34    for my $file (@$includes) { 
     35        my $include = YAML::LoadFile($file); 
    3436 
    3537        for my $key (keys %{ $include }) { 
  • trunk/plagger/lib/Plagger/Plugin/Search/Estraier.pm

    r1366 r1391  
    8080    } 
    8181 
    82  
    8382    return $feed; 
    8483} 
  • trunk/plagger/lib/Plagger/Plugin/Search/KinoSearch.pm

    r1185 r1391  
    99use KinoSearch::Analysis::PolyAnalyzer; 
    1010 
    11 sub init { 
    12     my $self = shift; 
    13     $self->SUPER::init(@_); 
     11sub register { 
     12    my($self, $context) = @_; 
     13    $context->register_hook( 
     14        $self, 
     15        'publish.entry'    => \&entry, 
     16        'plugin.init'      => \&initialize, 
     17        'plugin.finalize'  => \&finalize, 
     18        'searcher.search'  => \&search, 
     19    ); 
     20
     21 
     22sub initialize { 
     23    my($self, $context, $args) = @_; 
    1424 
    1525    $self->conf->{invindex} ||= $self->cache->path_to('invindex'); 
     
    3444    $self->{indexer}->spec_field( name => 'date' ); 
    3545    $self->{indexer}->spec_field( name => 'author' ); 
    36 } 
    37  
    38 sub register { 
    39     my($self, $context) = @_; 
    40     $context->register_hook( 
    41         $self, 
    42         'publish.entry'    => \&entry, 
    43         'publish.finalize' => \&finalize, 
    44         'searcher.search'  => \&search, 
    45     ); 
    4646} 
    4747 
  • trunk/plagger/t/plugins/Search-Estraier/search.t

    r1388 r1391  
    9494      url: http://localhost:$main::port/node/plagger 
    9595--- expected 
    96 # xxx this is clumsy 
    97 no warnings 'redefine'; 
    98 *Plagger::context = sub { $context }; 
    99  
     96Plagger->set_context($context); 
    10097my $feed; 
    10198$context->run_hook('searcher.search', { query => "murakami" }, 0, sub { $feed = $_[0] }); 
     
    118115      url: http://localhost:$main::port/node/plagger 
    119116--- expected 
     117Plagger->set_context($context); 
    120118ok -e $main::dir, 'invindex exists'; 
    121  
    122 # xxx this is clumsy 
    123 no warnings 'redefine'; 
    124 *Plagger::context = sub { $context }; 
    125119 
    126120my $feed; 
  • trunk/plagger/t/plugins/Search-KinoSearch/search.t

    r1328 r1391  
    3030--- expected 
    3131ok -e $main::dir, 'invindex exists'; 
    32  
    33 # xxx this is clumsy 
    34 no warnings 'redefine'; 
    35 *Plagger::context = sub { $context }; 
     32Plagger->set_context($context); 
    3633 
    3734my $feed; 
     
    5653--- expected 
    5754ok -e $main::dir, 'invindex exists'; 
    58  
    59 # xxx this is clumsy 
    60 no warnings 'redefine'; 
    61 *Plagger::context = sub { $context }; 
     55Plagger->set_context($context); 
    6256 
    6357my $feed;