| 1 | package Tapper::Action; | ||||||||||||||||||||||||||||
| 2 | # git description: v4.1.1-14-g65e3f23 | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Tapper - Daemon and plugins to handle MCP actions | ||||||||||||||||||||||||||||
| 6 | 9 | $Tapper::Action::VERSION = '5.0.0'; | |||||||||||||||||||||||||||
| 7 | 9 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Tapper::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use YAML::Syck 'Load'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Class::Load ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | extends 'Tapper::Base'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | has cfg => (is => 'rw', default => sub { Tapper::Config->subconfig} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub get_messages | ||||||||||||||||||||||||||||
| 24 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_messages: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | my $messages; | |||||||||||||||||||||||||||
| 28 | 3 | while () { | |||||||||||||||||||||||||||
| 29 | 23 | $messages = model('TestrunDB')->resultset('Message')->search({type => 'action'}); | |||||||||||||||||||||||||||
| 30 | 23 | ▶ | last if ($messages and $messages->count); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$messages and $messages->count
MC/DC50%1/2
$messages and $messages->count
$messages
$messages->count
Truth table66%2/3
A and B
A= $messagesB= $messages->count
| |||||||||||||||||||||||||||||
| 31 | 21 | ▶ | sleep $self->cfg->{times}{action_poll_intervall} || 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 2 | return $messages; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub loop | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
loop: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # my $x=model('TestrunDB')->resultset('Host'); | ||||||||||||||||||||||||||||
| 42 | 2 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||
| 43 | ACTION: | ||||||||||||||||||||||||||||
| 44 | 2 | ▶ | while (my $messages = $self->get_messages) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | while (my $message = $messages->next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | if (my $action = $message->message->{action}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 2 | my $plugin = $self->cfg->{action}{$action}{plugin}; | |||||||||||||||||||||||||||
| 48 | 2 | my $plugin_options = $self->cfg->{action}{$action}{plugin_options}; | |||||||||||||||||||||||||||
| 49 | 2 | my $plugin_class = "Tapper::Action::Plugin::${action}::${plugin}"; | |||||||||||||||||||||||||||
| 50 | 2 | load_class($plugin_class); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->log->error( "Could not load $plugin_class: $@" ); | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 2 | ▶ | try{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 9 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | $self->log->info("Call ${plugin_class}::execute()"); | |||||||||||||||||||||||||||
| 58 | 2 | &{"${plugin_class}::execute"}($self, $message->message, $plugin_options); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 0 | $self->log->error("Error occured: $_"); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 2 | } | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 1 | $message->delete; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 68 | 0 | say STDERR "Caught exception $_"; | |||||||||||||||||||||||||||
| 69 | 0 | $self->log->error("Caugth exception: $_"); | |||||||||||||||||||||||||||
| 70 | 2 | }; | |||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 9 | 1; # End of Tapper::Action | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||