root/trunk/plagger/lib/Plagger/Plugin/Aggregator/Gungho.pm

Revision 1939 (checked in by daisuke, 13 years ago)

I'm going gungho

  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 #
4 #
5
6 package Plagger::Plugin::Aggregator::Gungho::Handler;
7 use strict;
8 use base qw(Gungho::Handler::Null);
9
10 __PACKAGE__->mk_accessors($_) for qw(gungho_plugin);
11
12 sub handle_response
13 {
14     my $self = shift;
15     my $c    = shift;
16     my $res  = shift;
17
18     $self->next::method($c, $res);
19     $self->gungho_plugin->handle_feed($res->request->uri, $res->content_ref);
20 }
21
22 package Plagger::Plugin::Aggregator::Gungho;
23 use strict;
24 use base qw(Plagger::Plugin::Aggregator::Simple);
25 use Gungho;
26 use Gungho::Request;
27
28 __PACKAGE__->mk_accessors($_) for qw(requests);
29
30 sub register
31 {
32     my ($self, $context) = @_;
33     $context->register_hook(
34         $self,
35         'customfeed.handle'   => \&accumulate,
36         'aggregator.finalize' => \&aggregate,
37     );
38     $self->requests([]);
39 }
40
41 sub accumulate
42 {
43     my($self, $context, $args) = @_;
44    
45     my $url = $args->{feed}->url;
46     return unless $url =~ m!^https?://!i;
47
48     $context->log(info => "Fetch $url");
49     push @{ $self->requests }, Gungho::Request->new(GET => $url);
50 }
51
52 sub aggregate
53 {
54     my ($self, $context) = @_;
55     my $g = Gungho->new({
56         provider => {
57             module => 'Simple'
58         },
59         handler  => {
60             module => '+Plagger::Plugin::Aggregator::Gungho::Handler'
61         }
62     });
63     $g->provider()->requests( $self->requests );
64     $g->provider()->has_requests( 1 );
65     $self->requests([]);
66     $g->handler()->gungho_plugin( $self );
67     $g->run;
68 }
69
70 1;
71
72 __END__
73
74 =head1 NAME
75
76 Plagger::Plugin::Aggregator::Gungho - Go Gungho!
77
78 =head1 SYNOPSIS
79
80   - module: Aggregator::Gungho
81
82 =head1 DESCRIPTION
83
84 [06 Apr 2007] Gungho is, as of this writing, extremely new crawler framework.
85 Beware of bugs! Please report them to the author. I'll be happy to apply
86 patches or fix problems.
87
88 =head1 AUTHOR
89
90 Copyright (c) 2007 Daisuke Maki E<lt>daisuke@endeworks.jpE<gt>
91
92 =head1
93
Note: See TracBrowser for help on using the browser.