line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/gungho/lib/Gungho/Component/Setup.pm 41086 2008-02-01T16:49:41.285355Z lestrrat $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Gungho::Component::Setup; |
7
|
2
|
|
|
2
|
|
1274
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
8
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
9
|
2
|
|
|
2
|
|
5
|
use base qw(Gungho::Component); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
567
|
|
10
|
2
|
|
|
2
|
|
724
|
use Config::Any; |
|
2
|
|
|
|
|
16040
|
|
|
2
|
|
|
|
|
787
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @INTERNAL_PARAMS = qw(bootstrap_finished setup_finished config); |
13
|
|
|
|
|
|
|
my @CONFIGURABLE_PARAMS = qw(user_agent); |
14
|
|
|
|
|
|
|
my %CONFIGURABLE_PARAM_DEFAULTS = ( |
15
|
|
|
|
|
|
|
map { ($_ => 0) } @CONFIGURABLE_PARAMS |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata($_) for ( |
19
|
|
|
|
|
|
|
qw(log provider handler engine is_running features observer), |
20
|
|
|
|
|
|
|
@INTERNAL_PARAMS, |
21
|
|
|
|
|
|
|
@CONFIGURABLE_PARAMS, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
0
|
1
|
0
|
warn "Gungho::new() has been deprecated in favor of Gungho->run()"; |
27
|
0
|
|
|
|
|
0
|
my $class = shift; |
28
|
0
|
|
|
|
|
0
|
$class->bootstrap(@_); |
29
|
0
|
|
|
|
|
0
|
return $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub run |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
0
|
1
|
0
|
my $c = shift; |
35
|
0
|
|
|
|
|
0
|
$c->bootstrap(@_); |
36
|
0
|
|
|
|
|
0
|
$c->is_running(1); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
my $banner = sprintf(<<EOBANNER, eval('$Gungho' . '::VERSION'), join(', ', map { my $name = $_; $name =~ s/Gungho::Component:://; $name } @Gungho::ISA ) ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
Starting $c |
40
|
|
|
|
|
|
|
Gungho Version: %s |
41
|
|
|
|
|
|
|
Components: %s |
42
|
|
|
|
|
|
|
EOBANNER |
43
|
0
|
|
|
|
|
0
|
$c->log->info($_) for split(/\n/, $banner); |
44
|
0
|
|
|
|
|
0
|
$c->engine->run($c); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub bootstrap |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
0
|
|
0
|
my $c = shift; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
0
|
return $c if $c->bootstrap_finished(); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $config = $c->load_config($_[0]); |
54
|
0
|
0
|
|
|
|
0
|
if (exists $ENV{GUNGHO_DEBUG}) { |
55
|
0
|
|
|
|
|
0
|
$config->{debug} = $ENV{GUNGHO_DEBUG}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
$c->config($config); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
for my $key (@CONFIGURABLE_PARAMS) { |
61
|
0
|
|
0
|
|
|
0
|
$c->$key( $config->{$key} || $CONFIGURABLE_PARAM_DEFAULTS{$key} ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
if (! $config->{user_agent}) { |
65
|
0
|
|
|
|
|
0
|
warn "No user agent specified. You should specify one today!"; |
66
|
0
|
|
|
|
|
0
|
$c->user_agent( "Gungho/$Gungho::VERSION (http://code.google.com/p/gungho-crawler/wiki/Index)"); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
0
|
$c->features({}); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
0
|
my $components = $c->config->{components} || []; |
71
|
0
|
|
|
|
|
0
|
push @$components, 'Core'; |
72
|
0
|
|
|
|
|
0
|
Gungho->load_components(@$components); |
73
|
0
|
|
|
|
|
0
|
$c->bootstrap_finished(1); |
74
|
0
|
|
|
|
|
0
|
$c->setup; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
return $c; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub load_config |
80
|
|
|
|
|
|
|
{ |
81
|
1
|
|
|
1
|
1
|
71
|
my $c = shift; |
82
|
1
|
|
|
|
|
2
|
my $config = shift; |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
33
|
|
|
6
|
if ($config && ! ref $config) { |
85
|
1
|
|
|
|
|
2
|
my $filename = $config; |
86
|
|
|
|
|
|
|
# In the future, we may support multiple configs, but for now |
87
|
|
|
|
|
|
|
# just load a single file via Config::Any |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
19
|
my $list = Config::Any->load_files( { |
90
|
|
|
|
|
|
|
files => [ $filename ], |
91
|
|
|
|
|
|
|
use_ext => 1, |
92
|
|
|
|
|
|
|
} ); |
93
|
1
|
|
|
|
|
22913
|
($config) = $list->[0]->{$filename}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
5
|
if (! $config) { |
97
|
0
|
|
|
|
|
0
|
Carp::croak("Could not load config"); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
4
|
if (ref $config ne 'HASH') { |
101
|
0
|
|
|
|
|
0
|
Carp::croak("Gungho expectes config that can be decoded to a HASH"); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
2
|
return $config; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Gungho::Component::Setup - Routines To Setup Gungho |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 SYNOPSIS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Internal Use only |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 METHODS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 new |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Only here to announce its deprecation. Don't use. Use run() |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 bootstrap |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Bootstraps Gungho. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 run |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Sets up, configures, and starts Gungho |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 load_config |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Loads the given config |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |