Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Package/Tail.pm view on Meta::CPAN
}
# schedule the next check
$kernel->delay('PruneLineCache',10)
unless ( $self->tests_complete >= $self->depth_test_queue );
}
=item SetFollowTailWheel
This POE event handler sets up the POE::Wheel::FollowTail to send
events to our Append handler for each new File. I suppose at some point
I ought to write the corresponding DeleteFollowTailWheel.
=cut
sub SetFollowTailWheel {
my ($kernel, $self, $params ) =
@_[KERNEL, OBJECT, ARG0 ];
my $filter = defined( $params->{'filter'} ) && ( $params->{'filter'} ne '' )
? $params->{'filter'} : POE::Filter::Line->new();
my $interval = defined( $params->{'interval'} ) && ( $params->{'interval'} ne '' )
? $params->{'interval'} : 5;
my %seek;
if ( defined($params->{'seekback'}) && $params->{'seekback'} ne '' )
{
$seek{'SeekBack'} = $params->{'seekback'}
}
elsif ( defined($params->{'seek'}) && $params->{'seek'} ne '' )
{
$seek{'Seek'} = $params->{'seek'}
}
my $wheel = POE::Wheel::FollowTail->new(
Filename => $params->{'file'}, # File to tail
Filter => $filter, # How to parse it
PollInterval => $interval, # How often to check it
InputEvent => 'Append', # Event to emit upon input
ErrorEvent => 'RunError', # Event to emit upon error
ResetEvent => 'FileReset', # Event to emit on file reset
%seek, # Can't have both seek & seekback
);
# TODO error checking
$self->Verbose('File ('.$params->{'file'}.') being watched by wheel ID('.$wheel->ID.') ' );
$self->SetWheel($wheel);
$self->SetWheelKey($wheel, 'source' => $params->{'file'} );
$files[$$self]{ $params->{'file'} } = { 'wheel' => $wheel->ID };
return (1);
}
=item Wally
This POE event handler doesn't do anything, because sometimes
we must have a state that doesn't respond to work requests.
For one never knows when we just throw some event out there if someone
else might pick it up by _default and do something with it.
This way we KNOW it won't get done.
=cut
sub Wally {
return 0;
# This way we KNOW it won't get done.
}
=item test
This POE event handler executes the test/watch commands. It is called by the
Control and takes a Request as an argument.
=cut
sub test {
my ($kernel, $self, $sender, $request, ) =
@_[KERNEL, OBJECT, SENDER, ARG0, ];
$self->Verbose("test: request ".$request->id." input(".$request->input.") ",1);
my $txt = '';
my $opt;
my $sub_command = $request->command->[0];
my $command = $request->command->[1];
# break down args
eval { $opt = Getopt::Lucid->getopt( [
Param("like"),
Param("unlike"),
Param("ok"),
Param("name"),
Param("max_lines|l"),
Param("match_times|t"),
Param("ttl"),
Switch('ordered'),
Switch('cache')->default(1),
Switch("verbose|v"),
Switch("feedback|f"),
], $request->args )};
if( $@ )
{
$self->Verbose('set: getopt lucid got ('.$@.') ');
$request->Respond($kernel, "Invalid Args: $@ !", 400);
return;
}
# Validate args
# Need to evolve this into being more automated code but not sure how yet.
# Probably should check that like and unlike and ok are not all set at once.
# someday....
$txt .= $self->NotRegex(qr($opt->get_like), "like" );
$txt .= $self->NotRegex(qr($opt->get_unlike), "unlike");
$txt .= $self->NotType($opt->get_ok, "ok", qr(code)i);
$txt .= $self->NotScalar($opt->get_name, "name" );
$txt .= $self->NotPosInt($opt->get_max_lines, "max_lines");
$txt .= $self->NotPosInt($opt->get_match_times, "match_times");
$txt .= $self->NotPosInt($opt->get_ttl, "ttl" );
( run in 1.430 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )