The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Builder::Formatter - Base class for formatters

DESCRIPTION

Results go to Test::Builder::Stream which then forwards them on to one or more formatters. This module is a base class for formatters. You do not NEED to use this module to write a formatter, but it can help.

TEST COMPONENT MAP

  [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Result Formatter]
                                                                                   ^
                                                                             You are here

A test script uses a test tool such as Test::More, which uses Test::Builder to produce results. The results are sent to Test::Builder::Stream which then forwards them on to one or more formatters. The default formatter is Test::Builder::Fromatter::TAP which produces TAP output.

SYNOPSYS

    package My::Formatter;
    use base 'Test::Builder::Formatter';

    sub ok {
        my $self = shift;
        my ($result) = @_;

        ...
    }

    ...

    1;

TO USE IT

    use Test::More;
    use My::Formatter;

    # Creates a new instance of your listener. Any params you pass in will be
    # passed into the constructor. Exceptions: 'id', 'stream' and 'tb' which
    # are used directly by 'listen' if present.
    my $unlisten = My::Formatter->listen(...);

    # To stop listening:
    $unlisten->();

METHODS

PROVIDED

$L = $class->new(%params)

Create a new instance. Arguments must be key => value pairs where the key is a method name on the object.

$unlisten = $class->listen(%params)
$unlisten = $class->listen(id => 'foo', %params)
$unlisten = $class->listen(stream => $STREAM, %params)
$unlisten = $class->listen(tb => $BUILDER, %params)

Construct an instance using %params, and add it as a listener on the stream. 'id', 'stream', and 'tb' are special arguments that can be used to specify the id of the listener, the stream to which the instance will listen, or the Test::Builder instance from which to find the stream.

$L->handle($result)

Forward the resutl on to the correct method.

$subref = $L->to_handler()

Returns an anonymous sub that accepts results as arguments and passes them into handle() on this instance.

FOR YOU TO WRITE

$self->ok($result)
$self->note($result)
$self->diag($result)
$self->plan($result)
$self->finish($result)
$self->bail($result)
$self->child($result)

Any results given to the handle() method will be passed into the associated sub. If the sub is not defined then results of that type will be ignored.

AUTHORS

Chad Granum <exodist@cpan.org>

SOURCE

The source code repository for Test::More can be found at http://github.com/Test-More/test-more/.

COPYRIGHT

Copyright 2014 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html