line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Slurp; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: class to read log file inputs |
6
|
|
|
|
|
|
|
our $VERSION = '1.4'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::PluginContainer'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3865
|
use Log::Saftpresse::Log4perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
475
|
use IO::Select; |
|
1
|
|
|
|
|
1079
|
|
|
1
|
|
|
|
|
42
|
|
13
|
1
|
|
|
1
|
|
5
|
use Time::HiRes qw( sleep gettimeofday tv_interval ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'plugin_prefix' => ( is => 'ro', isa => 'Str', |
16
|
|
|
|
|
|
|
default => 'Log::Saftpresse::Input::', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'io_select' => ( is => 'rw', isa => 'Maybe[IO::Select]' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub update_io_select { |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $s = IO::Select->new; |
24
|
0
|
|
|
|
|
|
foreach my $plugin ( @{$self->plugins} ) { |
|
0
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$s->add( $plugin->io_handles ); |
26
|
|
|
|
|
|
|
} |
27
|
0
|
|
|
|
|
|
$self->io_select( $s ); |
28
|
0
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has '_last_run' => ( is => 'rw', isa => 'Maybe[ArrayRef]' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub can_read { |
34
|
0
|
|
|
0
|
0
|
|
my ( $self, $timeout ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# do we known when we did run last time? |
37
|
0
|
|
|
|
|
|
my $sleep; |
38
|
0
|
0
|
|
|
|
|
if( defined $self->_last_run ) { |
39
|
0
|
|
|
|
|
|
my $next = [ @{$self->_last_run} ]; $next->[0] += $timeout; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if( $self->io_select->count ) { |
|
|
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
|
|
|
0
|
0
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
my @events; |
62
|
0
|
|
|
|
|
|
my $eof = 1; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $plugin ( @{$self->plugins} ) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if( $plugin->can_read ) { |
66
|
0
|
0
|
|
|
|
|
if( $plugin->eof ) { next; } |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
eval { |
68
|
0
|
|
|
|
|
|
push( @events, $plugin->read_events ); |
69
|
|
|
|
|
|
|
}; |
70
|
0
|
0
|
|
|
|
|
if( $@ ) { |
71
|
0
|
|
|
|
|
|
$log->error('error while reading from plugin '.$plugin->name.': '.$@); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
$eof = 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if( $eof ) { |
78
|
0
|
|
|
|
|
|
die('all inputs at EOF'); |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
|
|
|
|
if( scalar @events ) { return \@events; } |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
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.4 |
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 |