Agent-TCLI

 view release on metacpan or  search on metacpan

lib/Agent/TCLI/Package/Tail.pm  view on Meta::CPAN


	$self->Verbose('PruneLineCache: cache dump ('.$lines.') ',3,$self->line_cache);

	if ( $self->depth_line_cache > 0 )
	{
		# Set time here so that all pruning uses same time
		my $time = time();

		my $line_index = 0;
		foreach my $line ( @{$self->line_cache} )
		{
			# The line ttl is set at line creation. This allows the ttl
			# to be modified along the way.
			if ( $line->ttl < $time )
			{
				splice( @{$self->line_cache}, $line_index, 1 );
				$self->Verbose('PruneLineCache: removed line('.$line->count.') ',2);
			}
			$line_index++;
		}
	}
	# 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 ('.$@.') ');



( run in 1.989 second using v1.01-cache-2.11-cpan-39bf76dae61 )