All the files
This commit is contained in:
45
lib/exim.pm
Normal file
45
lib/exim.pm
Normal file
@@ -0,0 +1,45 @@
|
||||
package My::parser::exim;
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Tail 0.91;
|
||||
use My::parser::exim_parser;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $config = shift;
|
||||
my $self = {};
|
||||
bless ($self, $class);
|
||||
|
||||
$self->{'config'} = $config;
|
||||
$self->{'parser'} = My::parser::exim_parser->new();
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub parse {
|
||||
my $self = shift;
|
||||
my @result;
|
||||
while(my $string = $self->fetch) {
|
||||
last unless($string);
|
||||
if (my $line = $self->{'parser'}->parser($string)) {
|
||||
push(@result,$line);
|
||||
}
|
||||
}
|
||||
return { retval => 0 } unless(scalar(@result)); # nothing to say, nothing to report
|
||||
return { retval => 1, retmsg => 'Here comes the results', lines => \@result };
|
||||
}
|
||||
|
||||
sub fetch {
|
||||
my $self = shift;
|
||||
my $fetcher = $self->{'config'}->get_fetcher('exim');
|
||||
die "Fetcher for exim went away?" unless($fetcher);
|
||||
my $line;
|
||||
my ($nfound,$timeleft,@pending) = File::Tail::select(undef,undef,undef,1,$fetcher);
|
||||
foreach (@pending) {
|
||||
$line = $_->read;
|
||||
chomp($line);
|
||||
}
|
||||
return 0 unless($line);
|
||||
return $line;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user