our
$VERSION
=
'0.3.3'
;
has
'path'
=> (
is
=>
'rw'
,
isa
=>
'Str'
,
default
=>
''
,
);
has
'tail'
=> (
is
=>
'ro'
,
isa
=>
'App::Wubot::Util::Tail'
,
lazy
=> 1,
default
=>
sub
{
my
(
$self
) =
@_
;
return
App::Wubot::Util::Tail->new( {
path
=>
$self
->path } );
},
);
has
'logger'
=> (
is
=>
'ro'
,
isa
=>
'Log::Log4perl::Logger'
,
lazy
=> 1,
default
=>
sub
{
return
Log::Log4perl::get_logger( __PACKAGE__ );
},
);
sub
init {
my
(
$self
,
$inputs
) =
@_
;
$self
->path(
$inputs
->{config}->{path} );
my
$callback
=
sub
{
my
$line
=
shift
;
for
my
$regexp_name
(
keys
%{
$inputs
->{config}->{regexp} } ) {
my
$regexp
=
$inputs
->{config}->{regexp}->{
$regexp_name
};
if
(
$line
=~ m|
$regexp
| ) {
$self
->{react}->{
$regexp_name
}++;
}
}
};
$self
->tail->callback(
$callback
);
$self
->tail->reset_callback(
sub
{
print
YAML::Dump
@_
} );
if
(
$inputs
->{cache}->{position} ) {
$self
->tail->position(
$inputs
->{cache}->{position} );
}
return
;
}
sub
check {
my
(
$self
,
$inputs
) =
@_
;
$self
->{react} = {};
$self
->tail->get_lines();
if
(
$self
->{react} ) {
return
{
react
=> { %{
$self
->{react} } },
cache
=> {
position
=>
$self
->tail->position },
};
}
return
{
cache
=> {
position
=>
$self
->tail->position } };
}
__PACKAGE__->meta->make_immutable;
1;