Formatters and Streamers are largely disconnected from the rest of
Test::Builder2 and have very narrow interfaces. So they're easy to wrap your
head around.
Formatters are easy. They need three methods:
INNER_begin()
Called when the test begins. Gives you a chance to output headers. Gets a
hash of options.
INNER_result()
Called whenever there's a result to be formatted. Gets a
Test::Builder2::Result object.
INNER_end()
Called when the test ends. Gives you a change to output a footer. Gets a
hash of options.
Here's a dirt simple HTML formatter.
http://github.com/schwern/test-more/blob/Test-Builder2/examples/TB2/lib/TB2/Formatter/SimpleHTML.pm
Jeff Lavalee is working on a JUnit formatter. The POSIX formatter needs love
if anyone's interested. I was serious about a GUI formatter, something that
showed a green bar. notbenh is working on improving the TAP formatter,
there's two branches open for that. There's already a formatter that does
nothing.
Also, I mentioned the possibility of TB2 using multiple formatters at once via
a multiplexer. It seems I wrote that multiplexer at some point.
http://github.com/schwern/test-more/blob/Test-Builder2/lib/Test/Builder2/Formatter/Multi.pm
Streamers are even easier. They implement one method, write().
Another possibility is a Streamer that captures all output to a file as well
as printing it off to its destination. That would probably best be
implemented as a Streamer class which takes two arguments, a real Streamer
object and place to write to. It delegates everything to the real Streamer
and puts a shim into write() to write everything to a file before handing it
off the real Streamer.
--
The mind is a terrible thing,
and it must be stopped.