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