schwern/test-more — Issue #186: Add a config event?
Author: schwern
Created: 2011-11-08 22:16:40+00:00
State: open
Labels: Discuss, Events, Test-Builder2

Currently, Test::Builder configures the TAP formatter directly. Things like whether it should use test numbers, whether it should show the TAP version or the header and so on.

This is dicey for several reasons...

* The formatter may not be a TAP formatter and it doesn't always check.
* Some changes are relevant to multiple types of formatters... some are not.
* It's calling non-standard methods.
* History and other event watchers do not see these changes which constitute special state changes.

It might make sense to instead have a Config event which contains key/value pairs to be configured.

# Signal not to use test numbers
my $config = Test::Builder2::Event::Config->new( use_test_numbers => 0 );

Each watcher can decide what to do with that information in `accept_config`. We can build up what various keys and values mean.

In addition, a Config event can contain special instructions for certain types of watchers. For example, this would indicate information only of interest to formatters.

my $config = Test::Builder2::Event::Config->for_class( "Test::Builder2::Formatter" => { use_test_numbers => 0 });

Passing stuff into `new` is equivalent to calling `for_class( "UNIVERSAL" => \%args )`.

EventWatchers would ask the Config event for what is of interest to it.

my $args = $config->for_me($self);