App-madeye
view release on metacpan or search on metacpan
lib/App/MadEye.pm view on Meta::CPAN
package App::MadEye;
use strict;
use warnings;
use 5.00800;
our $VERSION = '0.13';
use Class::Component;
use Params::Validate;
use UNIVERSAL::require;
use Log::Dispatch;
__PACKAGE__->load_components(qw/Plaggerize Autocall::InjectMethod/);
my $context;
sub context { $context }
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{results} = {};
$context = $self;
$self->_setup_logger;
$self;
}
sub run {
my $self = shift;
$self->log(debug => 'run');
unless (defined $self->class_component_methods->{'run_job'}) {
$self->log(debug => 'use Worker::Simple');
$self->load_plugins(
{
module => 'Worker::Simple',
config => { config => { task_timeout => 10 } }
}
);
}
$self->run_hook('check');
$self->run_hook('before_run_jobs');
$self->run_hook('run_jobs');
$self->run_hook('after_run_jobs');
if (%{$self->{results}}) {
for my $obj ( @{ $self->class_component_hooks->{notify} } ) {
my ( $plugin, $method ) = ( $obj->{plugin}, $obj->{method} );
if ($self->_should_run( plugin => $plugin )) {
$plugin->$method($self, $self->{results});
}
}
}
$self->log(debug => 'finished');
}
sub add_result {
my $self = shift;
validate(
@_ => +{
plugin => 1,
target => 1,
message => 1,
}
);
my $args = {@_};
return unless $self->_should_add_result(target => $args->{target}, plugin => $args->{plugin});
push @{$self->{results}->{ref $args->{plugin}}}, +{
target => $args->{target},
message => $args->{message},
};
( run in 0.973 second using v1.01-cache-2.11-cpan-5b529ec07f3 )