NAME

Runops::Recorder::Reader - A class which can read the recording files

DESCRIPTION

Instances of this class reads a recording. It can work both as a stream-based reader where you ask for the next entry or as a event generator that calls your handlers for each type of item it reads.

SYNOPSIS

# main script
use Runops::Recorder::Reader;

my $reader = Runops::Recorder::Reader->read("my-recording", { 
  handler => "MyRecordingHandler",
});

$reader->read();

# MyRecordingHandler.pm
package MyRecordingHandler;

sub on_switch_file {
  my ($self, $id, $path) = @_;
  print "Now in file: $path\n";
}

sub on_next_statement {
  my ($self, $line_no) = @_;
  print "Executing line: $line_no\n";
}

1;

INTERFACE

CLASS METHODS

new ( $path [, \%opts ] )

Creates a new instance of this class. Takes $path which must be a path to a recording and an optional hashref with options. Valid options are

handler

An package name or instance of a class which on which methods will be called when events occur. See "EVENTS"

handlers

A hashref with event/callback pairs that are called when events occur. See "EVENTS"

skip_keyframes

An boolean that indicates wheter keyframes should be skipped or not - ie, not generate an event or be returned from read_next

INSTANCE METHODS

read_next

Reads the next entry in the recording and returns a list with the numeric event and its decoded contents. See "EVENTS"

read_all

Reads thru the recording generating events.

read_identifiers

Reads the identifiers, files etc that we saw during recording

skip_until ( $event )

Reads all events until the next of of type $event occurs.

get_identifier ( $id )

Returns the identifier with the given $id.

find_next_keyframe

Searches for the next keyframe. This is to be used in the future when one can tail recordings being generated.

decode ( $event, $data )

Decodes the blob $data according to the rules for the specific event and returns a list of values.

EVENTS

The following events may occur in the recording. They can be returned by read_next or cause a callback/method to be invoked.

The kind of events that can happen. Numeric code, constant and callback name within parenthesis for each item.

Keyframe (0, KEYFRAME, on_keyframe)

A keyframe is an entry that we can wait for in tailing mode to know where we can start reading. These are inserted every 1024 events or so. No data/arguments.

Switch file (1, SWITCH_FILE, on_switch_file)

Happens when we execute a statement in another source file than the current one. No arguments.

Next statment (2, NEXT_STATEMENT, on_next_statement)

A statement has been executed. Data/argument is line number.

Die (3, DIE, on_die)

The program threw an exception using die. No data/arguments.

Enter subroutine (4, ENTER_SUB, on_enter_sub)

A subroutine was called. Data/arguments are identifier id and identifier.

EXPORT

Nothing is exported by default. The tag events export the event constants listed about in "EVENTS".