File Coverage

blib/lib/Rex/JobControl/Mojolicious/Plugin/Audit.pm
Criterion Covered Total %
statement 23 32 71.8
branch 0 2 0.0
condition 0 3 0.0
subroutine 7 8 87.5
pod 1 1 100.0
total 31 46 67.3


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4             # vim: set ts=3 sw=3 tw=0:
5             # vim: set expandtab:
6              
7             package Rex::JobControl::Mojolicious::Plugin::Audit;
8             $Rex::JobControl::Mojolicious::Plugin::Audit::VERSION = '0.18.0';
9 1     1   727 use strict;
  1         2  
  1         30  
10 1     1   3 use warnings;
  1         2  
  1         19  
11              
12 1     1   4 use Mojolicious::Plugin;
  1         1  
  1         5  
13              
14 1     1   17 use base 'Mojolicious::Plugin';
  1         1  
  1         76  
15 1     1   354 use Rex::JobControl::Helper::AuditLog;
  1         3  
  1         19  
16 1     1   31 use Data::Dumper;
  1         1  
  1         224  
17              
18             sub register {
19 1     1 1 48 my ( $plugin, $app ) = @_;
20              
21 1         8 my $log = Rex::JobControl::Helper::AuditLog->new(
22             path => $app->config->{log}->{audit_log},
23             level => 'info'
24             );
25              
26 1         2 my %audit_calls = %{ $app->config->{audit} };
  1         3  
27              
28             $app->hook(
29             around_action => sub {
30 0     0     my ( $next, $c, $action, $last ) = @_;
31              
32 0           my $ctrl_name = $c->stash('controller');
33 0           my $action_name = $c->stash('action');
34              
35 0 0 0       if ( exists $audit_calls{$ctrl_name}
36             && exists $audit_calls{$ctrl_name}->{$action_name} )
37             {
38 0           my %params;
39 0           @params{ @{ $audit_calls{$ctrl_name}->{$action_name}->{params} } } =
  0            
40             $c->param( $audit_calls{$ctrl_name}->{$action_name}->{params} );
41              
42 0           $log->audit(
43             {
44             controller => $ctrl_name,
45             action => $action_name,
46             data => \%params,
47             }
48             );
49             }
50              
51 0           return $next->();
52             },
53 1         17 );
54              
55             }
56              
57             1;