The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Wheel::FollowTail - follow the tail of an ever-growing file

SYNOPSIS

  $wheel = POE::Wheel::FollowTail->new(
    Handle       => $file_handle,                  # File to tail
    Driver       => POE::Driver::Something->new(), # How to read it
    Filter       => POE::Filter::Something->new(), # How to parse it
    PollInterval => 1,                  # How often to check it
    InputEvent   => $input_event_name,  # Event to emit upon input
    ErrorEvent   => $error_event_name,  # Event to emit upon error
    SeekBack     => $offset,            # How far from EOF to start
  );

DESCRIPTION

FollowTail follows the end of an ever-growing file, such as a log of system events. It generates events for each new record that is appended to its file.

This is a read-only wheel so it does not include a put() method.

PUBLIC METHODS

event EVENT_TYPE => EVENT_NAME, ...

event() is covered in the POE::Wheel manpage.

FollowTail's event types are InputEvent and ErrorEvent.

ID

The ID method returns a FollowTail wheel's unique ID. This ID will be included in every event the wheel generates, and it can be used to match events with the wheels which generated them.

EVENTS AND PARAMETERS

PollInterval

PollInterval is the amount of time, in seconds, the wheel will wait before retrying after it has reached the end of the file. This delay prevents the wheel from going into a CPU-sucking loop.

SeekBack

The SeekBack parameter tells FollowTail how far before EOF to start reading before following the file. Its value is specified in bytes, and values greater than the file's current size will quietly cause FollowTail to start from the file's beginning.

When SeekBack isn't specified, the wheel seeks 4096 bytes before the end of the file and discards everything it reads up until EOF. It does this to frame records within the file.

When SeekBack is used, the wheel assumes that records have already been framed, and the seek position is the beginning of one. It will return everything it reads up until EOF.

InputEvent

InputEvent contains the name of an event which is emitted for every complete record read. Every InputEvent event is accompanied by two parameters. ARG0 contains the record which was read. ARG1 contains the wheel's unique ID.

A sample InputEvent event handler:

  sub input_state {
    my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1];
    print "Wheel $wheel_id received input: $input\n";
  }
ErrorEvent

ErrorEvent contains the event which is emitted whenever an error occurs. Every ErrorEvent comes with four parameters:

ARG0 contains the name of the operation that failed. This usually is 'read'. Note: This is not necessarily a function name. The wheel doesn't know which function its Driver is using.

ARG1 and ARG2 hold numeric and string values for $!, respectively. Note: FollowTail knows how to handle EAGAIN, so it will never return that error.

ARG3 contains the wheel's unique ID.

A sample ErrorEvent event handler:

  sub error_state {
    my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3];
    warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
  }

SEE ALSO

POE::Wheel.

The SEE ALSO section in POE contains a table of contents covering the entire POE distribution.

BUGS

This wheel can't tail pipes and consoles on some systems.

AUTHORS & COPYRIGHTS

Please see POE for more information about authors and contributors.