| 1 | package App::MadEye::Plugin::Agent::Base; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base qw/App::MadEye::Plugin::Base/; | ||
| 5 | |||
| 6 | sub import { | ||
| 7 | my $class = shift; | ||
| 8 | my $pkg = caller; | ||
| 9 | |||
| 10 | no strict 'refs'; | ||
| 11 | push @{"$pkg\::ISA"}, $class; | ||
| 12 | |||
| 13 | *{"$pkg\::run_jobs"} = sub :Hook('run_jobs') { | ||
| 14 | my ($self, $context, $args) = @_; | ||
| 15 | |||
| 16 | $context->log( info => "run " . ref $self ); | ||
| 17 | |||
| 18 | my $target = $self->config->{config}->{target}; | ||
| 19 | $target = [$target] unless ref $target eq 'ARRAY'; | ||
| 20 | |||
| 21 | for my $t (@$target) { | ||
| 22 | $context->log('debug', "register job: $self, $t"); | ||
| 23 | $context->run_job( +{ target => $t, plugin => $self, } ); | ||
| 24 | } | ||
| 25 | }; | ||
| 26 | } | ||
| 27 | |||
| 28 | 1; | ||
| 29 |