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.

singleton

my $default_formatter = Test::Builder2::Formatter->singleton;

Returns the default shared formatter object.

The default Formatter is a Test::Builder2::Formatter::TAP object.

create

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

Creates a new formatter object to feed results to.

You want to call this on a subclass.

stream_depth

my $stream_depth = $formatter->stream_depth;

Returns how many stream start events without stream end events have been seen.

For example...

stream start

Would indicate a level of 1.

stream start
  stream start
  stream end
  stream start

Would indicate a level of 2.

A value of 0 indiciates the Formatter is not in a stream.

A negative value will throw an exception.

stream_depth_inc

stream_depth_dec

Increment and decrement the stream_depth.

accept_event

$formatter->accept_event($event);

Accept Events as they happen.

It will increment and decrement stream_depth as stream start and stream end events are seen.

Do not override accept_event(). Override INNER_accept_event().

accept_result

$formatter->accept_result($result);

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

It is an error to call accept_result() outside a stream.

Do not override accept_result(). Override INNER_accept_result().

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.