| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::MadEye; |
|
2
|
3
|
|
|
3
|
|
44888
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
101
|
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
72
|
|
|
4
|
3
|
|
|
3
|
|
64
|
use 5.00800; |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
160
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
|
6
|
3
|
|
|
3
|
|
2884
|
use Class::Component; |
|
|
3
|
|
|
|
|
66258
|
|
|
|
3
|
|
|
|
|
22
|
|
|
7
|
3
|
|
|
3
|
|
4227
|
use Params::Validate; |
|
|
3
|
|
|
|
|
41448
|
|
|
|
3
|
|
|
|
|
228
|
|
|
8
|
3
|
|
|
3
|
|
28
|
use UNIVERSAL::require; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
25
|
|
|
9
|
3
|
|
|
3
|
|
3305
|
use Log::Dispatch; |
|
|
3
|
|
|
|
|
11407
|
|
|
|
3
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw/Plaggerize Autocall::InjectMethod/); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $context; |
|
13
|
0
|
|
|
0
|
0
|
0
|
sub context { $context } |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
2
|
|
|
2
|
1
|
30
|
my $class = shift; |
|
17
|
2
|
|
|
|
|
47
|
my $self = $class->SUPER::new(@_); |
|
18
|
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
2179
|
$self->{results} = {}; |
|
20
|
2
|
|
|
|
|
5
|
$context = $self; |
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
10
|
$self->_setup_logger; |
|
23
|
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
7
|
$self; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub run { |
|
28
|
2
|
|
|
2
|
0
|
13
|
my $self = shift; |
|
29
|
2
|
|
|
|
|
8
|
$self->log(debug => 'run'); |
|
30
|
|
|
|
|
|
|
|
|
31
|
2
|
50
|
|
|
|
111
|
unless (defined $self->class_component_methods->{'run_job'}) { |
|
32
|
2
|
|
|
|
|
25
|
$self->log(debug => 'use Worker::Simple'); |
|
33
|
2
|
|
|
|
|
46
|
$self->load_plugins( |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
module => 'Worker::Simple', |
|
36
|
|
|
|
|
|
|
config => { config => { task_timeout => 10 } } |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
11650
|
$self->run_hook('check'); |
|
42
|
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
70
|
$self->run_hook('before_run_jobs'); |
|
44
|
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
23
|
$self->run_hook('run_jobs'); |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
22
|
$self->run_hook('after_run_jobs'); |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
100
|
|
|
|
20
|
if (%{$self->{results}}) { |
|
|
2
|
|
|
|
|
15
|
|
|
50
|
1
|
|
|
|
|
2
|
for my $obj ( @{ $self->class_component_hooks->{notify} } ) { |
|
|
1
|
|
|
|
|
8
|
|
|
51
|
4
|
|
|
|
|
48
|
my ( $plugin, $method ) = ( $obj->{plugin}, $obj->{method} ); |
|
52
|
4
|
50
|
|
|
|
11
|
if ($self->_should_run( plugin => $plugin )) { |
|
53
|
4
|
|
|
|
|
13
|
$plugin->$method($self, $self->{results}); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
20
|
$self->log(debug => 'finished'); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub add_result { |
|
62
|
6
|
|
|
6
|
0
|
140
|
my $self = shift; |
|
63
|
6
|
|
|
|
|
75
|
validate( |
|
64
|
|
|
|
|
|
|
@_ => +{ |
|
65
|
|
|
|
|
|
|
plugin => 1, |
|
66
|
|
|
|
|
|
|
target => 1, |
|
67
|
|
|
|
|
|
|
message => 1, |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
); |
|
70
|
6
|
|
|
|
|
31
|
my $args = {@_}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
6
|
50
|
|
|
|
21
|
return unless $self->_should_add_result(target => $args->{target}, plugin => $args->{plugin}); |
|
73
|
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
9
|
push @{$self->{results}->{ref $args->{plugin}}}, +{ |
|
|
6
|
|
|
|
|
37
|
|
|
75
|
|
|
|
|
|
|
target => $args->{target}, |
|
76
|
|
|
|
|
|
|
message => $args->{message}, |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _should_add_result { |
|
81
|
10
|
|
|
10
|
|
14
|
my $self = shift; |
|
82
|
10
|
|
|
|
|
111
|
validate( |
|
83
|
|
|
|
|
|
|
@_ => +{ |
|
84
|
|
|
|
|
|
|
plugin => 1, |
|
85
|
|
|
|
|
|
|
target => 0, |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
); |
|
88
|
10
|
|
|
|
|
42
|
my $args = {@_}; |
|
89
|
|
|
|
|
|
|
|
|
90
|
10
|
50
|
|
|
|
35
|
if ($args->{plugin}->config->{rule}) { |
|
91
|
0
|
|
|
|
|
0
|
for my $rule_conf ( @{ $args->{plugin}->config->{rule} } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
92
|
0
|
|
|
|
|
0
|
my $rule = $self->_load_rule($rule_conf); |
|
93
|
0
|
0
|
|
|
|
0
|
my $ret = $rule->dispatch( |
|
94
|
|
|
|
|
|
|
$self, |
|
95
|
|
|
|
|
|
|
+{ |
|
96
|
|
|
|
|
|
|
plugin => $args->{plugin}, |
|
97
|
|
|
|
|
|
|
($args->{target} ? ( target => $args->{target}) : () ), |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
); |
|
100
|
0
|
0
|
|
|
|
0
|
return 0 if $ret; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
10
|
|
|
|
|
70
|
return 1; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
*_should_run = *_should_add_result; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _load_rule { |
|
108
|
0
|
|
|
0
|
|
0
|
my ($self, $rule) = @_; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
my $class = $rule->{module}; |
|
111
|
0
|
0
|
|
|
|
0
|
if ($class =~ /^\+/) { |
|
112
|
0
|
|
|
|
|
0
|
$class =~ s/^\+//; |
|
113
|
|
|
|
|
|
|
} else { |
|
114
|
0
|
|
|
|
|
0
|
$class = __PACKAGE__ . '::Rule::' . $class; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
0
|
|
|
|
0
|
$class->use or die $@; |
|
117
|
0
|
|
|
|
|
0
|
return $class->new($rule->{config}); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _setup_logger { |
|
121
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
122
|
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
18
|
my $logger = Log::Dispatch->new; |
|
124
|
2
|
50
|
|
|
|
139
|
for my $conf (@{ $self->conf->{global}->{logger} || [] }) { |
|
|
2
|
|
|
|
|
8
|
|
|
125
|
0
|
|
|
|
|
0
|
my $class = "Log::Dispatch::$conf->{class}"; |
|
126
|
0
|
0
|
|
|
|
0
|
$class->use or die $@; |
|
127
|
0
|
|
|
|
|
0
|
$logger->add( $class->new( %{ $conf->{config} } ) ); |
|
|
0
|
|
|
|
|
0
|
|
|
128
|
|
|
|
|
|
|
} |
|
129
|
2
|
|
|
|
|
30
|
$self->{logger} = $logger; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub log { |
|
133
|
6
|
|
|
6
|
1
|
15
|
my ($self, $level, $msg) = @_; |
|
134
|
6
|
50
|
|
|
|
19
|
die "missing level" unless $level; |
|
135
|
6
|
50
|
|
|
|
17
|
die "missing msg" unless $msg; |
|
136
|
|
|
|
|
|
|
|
|
137
|
6
|
|
|
|
|
46
|
$self->{logger}->log( level => $level, message => "[$level] $msg\n" ); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
|
141
|
|
|
|
|
|
|
__END__ |