TB2::EventCoordinator - Coordinate events amongst the builders
use TB2::EventCoordinator; my $ec = TB2::EventCoordinator->new; # The builder sends it events like assert results and the beginning # and end of tests. $ec->post_event($event); # The EventCoordinator comes with History and the default Formatter, # but they can be replaced or added to. You can also add handlers of # your own devising. $events->add_formatters($formatter); $events->add_late_handlers($handler);
Test::Builder2 is a federated system of test formatters and assert generators. This lets people make new and interesting ways to write tests and format the results while keeping them coordianted. The EventCoordiantor is responsible for that coordination.
Each thing that generates events, usually something that causes asserts, will report them to the EventCoordinator. This in turn reports them to things like History and result Formatters and whatever else you want to handle events.
These are attributes which can be set and gotten through a method of the same name. They can also be passed into new.
new
The History object which is listening to events.
This is a special case of handlers provided so you can distinguish between formatters and other handlers.
handlers
Defaults to [ TB2::History->new ].
[ TB2::History->new ]
Unlike other handlers, there is only one history.
An array ref of Formatter objects which are listening to events.
Defaults to [ $class->default_formatters ].
[ $class->default_formatters ]
The default can be altered by overriding default_formatter_class and/or default_formatters.
An array ref of any additional objects which are listening to events. They all must do the TB2::EventHandler role (or have equivalent methods).
early_handlers are called first before any other handlers. This lets them manipulate the result before a formatter can act on it.
By default there are no early_handlers.
late_handlers are called last after all other handlers. This lets them see the result after any manipulations.
By default there are no late_handlers.
These are methods which create or retrieve EventCoordinator objects.
my $ec = TB2::EventCoordinator->new( %args );
Creates a new event coordinator.
%args are the Attributes defined above.
For example, to create an EventCoordinator without a formatter...
my $ec = TB2::EventCoordinator->new( formatters => [] );
my $formatter_class = $class->default_formatter_class;
Returns the TB2::Formatter subclass to be used for formatting by default.
Defaults to the TB2_FORMATTER_CLASS environment variable, if set, or TB2::Formatter::TAP if not.
my $formatters = $class->default_formatters;
Returns the list of formatters to be used by default.
Defaults to a single instance of the default_formatter_class.
$ec->post_event($event);
The $ec will hand the $event around to all its handlers, along with itself. See all_handlers for ordering information.
$ec
$event
my @handlers = $ec->all_handlers;
Returns a list of all handlers in the order they will be passed events.
The order is early_handlers, history, formatters, late_handlers.
$ec->add_early_handlers($handler1, $handler2, ...);
Adds new handlers to their respective types.
Use this instead of manipulating the list of handlers directly.
$ec->clear_early_handlers;
Removes all handlers of their respective types.
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
Thanks to hdp and rjbs who convinced me that an event coordinator was necessary. Here is documentation of the historic moment: http://www.flickr.com/photos/xwrn/5334766071/
TB2::EventHandler, TB2::Event, TB2::Result
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.