Saftpresse/Slurp.pm

filter: Statementstmt 31.5% 18 / 57 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 26.5% 22 / 83 SCAR 41.4
CC
11
Cov
25%
read_events
56.0
can_read
20.0
update_io_select
6.0
CRAP 62.7
« Saftpresse/Plugin/Amavis.pm ↑ Summary Saftpresse/Plugin/Postfix/Utils.pm »
1 package Log::Saftpresse::Slurp;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: class to read log file inputs
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 extends 'Log::Saftpresse::PluginContainer';
9  
10 1 ▶use Log::Saftpresse::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Time::HiRes qw( sleep gettimeofday tv_interval );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 has 'plugin_prefix' => ( is => 'ro', isa => 'Str',
16 default => 'Log::Saftpresse::Input::',
17 );
18  
19 1 has 'io_select' => ( is => 'rw', isa => 'Maybe[IO::Select]' );
20  
21 sub update_io_select {
22 0 ▶ my $self = shift;
Subroutine update_io_select: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my $s = IO::Select->new;
24 0 foreach my $plugin ( @{$self->plugins} ) {
25 0 $s->add( $plugin->io_handles );
26 }
27 0 $self->io_select( $s );
28 0 return;
29 };
30  
31 1 has '_last_run' => ( is => 'rw', isa => 'Maybe[ArrayRef]' );
32  
33 sub can_read {
34 0 ▶ my ( $self, $timeout ) = @_;
Subroutine can_read: not called CC=4 SCAR=30.0
Pod undocumented
35  
36 # do we known when we did run last time?
37 0 my $sleep;
38 0 ▶ if( defined $self->_last_run ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_last_run) { } 0 0 0
39 0 my $next = [ @{$self->_last_run} ]; $next->[0] += $timeout;
40 0 $sleep = tv_interval( [gettimeofday], $next );
41 } else {
42 # just sleep for timeout
43 0 $sleep = $timeout;
44 }
45  
46 0 $self->update_io_select;
47  
48 # use select() when possible
49 0 ▶ if( $self->io_select->count ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->io_select->count) { } 0 0 0
elsif ($sleep > 0) { } 0 0 0
50 0 $self->io_select->can_read( $sleep );
51 } elsif( $sleep > 0 ) { # may be negative if clock is drifting
52 0 sleep( $sleep );
53 }
54  
55 0 $self->_last_run( [gettimeofday] );
56 0 return( 1 ); # always signal read
57 }
58  
59 sub read_events {
60 0 ▶ my $self = shift;
Subroutine read_events: not called CC=7 SCAR=40.3
Pod undocumented
61 0 my @events;
62 0 my $eof = 1;
63  
64 0 foreach my $plugin ( @{$self->plugins} ) {
65 0 ▶ if( $plugin->can_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->can_read) 0 0 0
66 0 ▶ if( $plugin->eof ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->eof) 0 0 0
67 0 eval {
68 0 push( @events, $plugin->read_events );
69 };
70 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
71 0 $log->error('error while reading from plugin '.$plugin->name.': '.$@);
72 }
73 }
74 0 $eof = 0;
75 }
76  
77 0 ▶ if( $eof ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eof) 0 0 0
78 0 die('all inputs at EOF');
79 }
80 0 ▶ if( scalar @events ) { return \@events; }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @events) 0 0 0
81 0 return;
82 }
83  
84 1 1;
85  
86 __END__
87  
88 =pod
89  
90 =encoding UTF-8
91  
92 =head1 NAME
93  
94 Log::Saftpresse::Slurp - class to read log file inputs
95  
96 =head1 VERSION
97  
98 version 1.5
99  
100 =head1 AUTHOR
101  
102 Markus Benning <ich@markusbenning.de>
103  
104 =head1 COPYRIGHT AND LICENSE
105  
106 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
107  
108 This is free software, licensed under:
109  
110 The GNU General Public License, Version 2, June 1991
111  
112 =cut
« Saftpresse/Plugin/Amavis.pm ↑ Summary Saftpresse/Plugin/Postfix/Utils.pm »