NAME

TB2::Event - A test event role

SYNOPSIS

package My::Event;

use TB2::Mouse;
with 'TB2::Event';

sub as_hash    { ... }
sub build_event_type { "my_thingy" }

DESCRIPTION

Test::Builder2 is a federated system where multiple builders can define their own way to do asserts. They communicate and coordinate with each other by way of events. These events can include:

start of a test
end of a test
the result of an assert

The basic Event doesn't do a whole lot. It contains data and that's about it. Subclasses are expected to extend the interface quite a bit, but they will all be able to dump out their relevant data.

METHODS

Attributes

line

The line on which this event occurred.

The event issuer should fill this in. It should be from the user's perspective, not literally where the event was created inside the builder.

file

The file on which this event occurred.

The event issuer should fill this in. It should be from the user's perspective, not literally where the event was created inside the builder.

event_type

Returns the type of event this is. For example, "result" or "test_start".

Use this to identify events rather than $event->isa($class).

See build_event_type for how to set the event_type if you're writing a new event.

Required Methods

You must implement these methods.

build_event_type

my $type = $event->build_event_type;

Returns the type of event this is.

For example, "result".

$type must be lowercase and only contain alphanumeric characters and underscores.

Used to build event_type

Provided Methods

as_hash

my $data = $event->as_hash;

Returns all the attributes and data associated with this $event as a hash of attributes and values.

The intent is to provide a way to dump all the information in an Event without having to call methods which may or may not exist.

keys_for_hash

my $keys = $event->keys_for_hash;

Returns an array ref of keys for as_hash to use as keys and methods to call on the object for the key's value.

By default it uses the object's non-private attributes. That should be sufficient for most events.

object_id

my $id = $thing->object_id;

Returns an identifier for this object unique to the running process. The identifier is fairly simple and easily predictable.

See TB2::HasObjectID

SEE ALSO

TB2::Result