NAME

Test::Builder2::Formatter - Base class for formating test results

SYNOPSIS

package Test::Builder2::Formatter::SomeFormat;

use Test::Builder2::Mouse;
extends "Test::Builder2::Formatter;

DESCRIPTION

Test::Builder2 delegates the actual formating of test results to a Test::Builder2::Formatter object. This can then decide if it's going to formatter TAP or XML or send email or whatever.

METHODS

Attributes

streamer_class

Contains the class to use to make a Streamer.

Defaults to $formatter->default_streamer_class

streamer

Contains the Streamer object to write to. One will be created for you using $formatter->streamer_class.

new

my $formatter = Test::Builder2::Formatter->new(%args);

Sets up a new formatter object to feed results.

begin

$formatter->begin;
$formatter->begin(%plan);

Indicates that testing is going to begin. Gives $formatter the opportunity to formatter a plan, do setup or formatter opening tags and headers.

A %plan can be given, but there are currently no common attributes.

begin() will only happen once per formatter instance. Subsequent calls will be ignored. This helps coordinating multiple clients all using the same formatter, they can all call begin().

Do not override begin(). Override INNER_begin().

has_begun

my $has_begun = $formatter->has_begun;

Returns whether begin() has been called.

result

$formatter->result($result);

Formats a $result (an instance of Test::Builder2::Result).

It is an error to call result() after end().

Do not override result(). Override INNER_result().

end

$formatter->end;
$formatter->end(%plan);

Indicates that testing is done. Gives $formatter the opportunity to clean up, output closing tags, save the results or whatever.

No further results should be formatted after end().

Do not override end(). Override INNER_end().

has_ended

my $has_ended = $formatter->has_ended;

Returns whether end() has been called.

write

$output->write($destination, @text);

Outputs @text to the named $destination.

@text is treated like print, so it is simply concatenated.

In reality, this is a hand off to $formatter->streamer->write.

Virtual Methods

These methods must be defined by the subclasser.

Do not override begin, result and end. Override these instead.

INNER_begin

INNER_result

INNER_end

These implement the guts of begin, result and end.