Test::Builder2::EventCoordinator - Coordinate events amongst the builders
# A builder gets and stores a copy of the singleton use Test::Builder2::EventCoordinator; my $ec = Test::Builder2::EventCoordinator->singleton; # The builder sends it events like assert results and the beginning # and end of test streams. $ec->post_result($result); # special case for results $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 watchers of # your own devising. $events->add_formatters($formatter); $events->add_watcher($watcher);
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 watch 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 watchers provided so you can distinguish between formatters and other watchers.
watchers
Defaults to [ Test::Builder2::History->new ].
[ Test::Builder2::History->new ]
Unlike other watchers, there is only one history.
An array ref of Formatter objects which are listening to events.
Defaults to [ Test::Builder2::Formatter::TAP->new ].
[ Test::Builder2::Formatter::TAP->new ]
An array ref of any additional objects which are listening to events. They all must do the Test::Builder2::EventWatcher role (or have equivalent methods).
early_watchers are called first before any other watchers. This lets them manipulate the result before a formatter can act on it.
By default there are no early_watchers.
late_watchers are called last after all other watchers. This lets them see the result after any manipulations.
By default there are no late_watchers.
These are methods which create or retrieve EventCoordinator objects.
my $ec = Test::Builder2::EventCoordinator->singleton;
Returns the default EventCoordinator. If you want to be hooked into the state of the globally active test, use this.
It will contain the History and Formatter singletons.
my $ec = Test::Builder2::EventCoordinator->create(%args);
Creates a new EventCoordinator.
%args corresponds to the Attributes.
$ec->post_result($result);
This is a special case of post_event for assert results.
$ec->post_event($event);
The $ec will hand the $event around to all its watchers, along with itself. See all_watchers for ordering information.
$ec
$event
my @watchers = $ec->all_watchers;
Returns a list of all watchers in the order they will be passed events.
The order is early_watchers, history, formatters, late_watchers.
$ec->add_early_watchers($watcher1, $watcher2, ...);
Adds new watchers to their respective types.
Use this instead of manipulating the list of watchers directly.
$ec->clear_early_watchers;
Removes all watchers of their respective types.
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/
Test::Builder2::EventWatcher, Test::Builder2::Event, Test::Builder2::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.