- NAME
- DESCRIPTION
- SYNOPSIS
- METHODS
  - EVENT METHODS
- SOURCE
- MAINTAINERS
- AUTHORS
- COPYRIGHT

# NAME

Test2::Formatter::TAP - Standard TAP formatter

# DESCRIPTION

This is what takes events and turns them into TAP.

# SYNOPSIS

        use Test2::Formatter::TAP;
        my $tap = Test2::Formatter::TAP->new();

        # Switch to utf8
        $tap->encoding('utf8');

        $tap->write($event, $number); # Output an event

# METHODS

$bool = $tap->no_numbers
$tap->set_no_numbers($bool)

  Use to turn numbers on and off.

$arrayref = $tap->handles
$tap->set_handles(\@handles);

  Can be used to get/set the filehandles. Indexes are identified by the `OUT_STD` and `OUT_ERR` constants.

$encoding = $tap->encoding
$tap->encoding($encoding)

  Get or set the encoding. By default no encoding is set, the original settings of STDOUT and STDERR are used.

  This directly modifies the stored filehandles, it does not create new ones.

$tap->write($e, $num)

  Write an event to the console.

Test2::Formatter::TAP->register_event($pkg, sub { ... });

  In general custom events are not supported. There are however occasions where you might want to write a custom event type that results in TAP output. In order to do this you use the `register_event()` class method.

          package My::Event;
          use Test2::Formatter::TAP;

          use base 'Test2::Event';
          use Test2::Util::HashBase qw/pass name diag note/;

          Test2::Formatter::TAP->register_event(
              __PACKAGE__,
              sub {
                  my $self = shift;
                  my ($e, $num) = @_;
                  return (
                      [Test2::Formatter::TAP::OUT_STD, "ok $num - " . $e->name . "\n"],
                      [Test2::Formatter::TAP::OUT_ERR, "# " . $e->name . " " . $e->diag . "\n"],
                      [Test2::Formatter::TAP::OUT_STD, "# " . $e->name . " " . $e->note . "\n"],
                  );
              }
          );

          1;

## EVENT METHODS

All these methods require the event itself. Optionally they can all except a test number.

All methods return a list of array-refs. Each array-ref will have 2 items, the first is an integer identifying an output handle, the second is a string that should be written to the handle.

@out = $TAP->event_ok($e)
@out = $TAP->event_ok($e, $num)

  Process an Test2::Event::Ok event.

@out = $TAP->event_plan($e)
@out = $TAP->event_plan($e, $num)

  Process an Test2::Event::Plan event.

@out = $TAP->event_note($e)
@out = $TAP->event_note($e, $num)

  Process an Test2::Event::Note event.

@out = $TAP->event_diag($e)
@out = $TAP->event_diag($e, $num)

  Process an Test2::Event::Diag event.

@out = $TAP->event_bail($e)
@out = $TAP->event_bail($e, $num)

  Process an Test2::Event::Bail event.

@out = $TAP->event_exception($e)
@out = $TAP->event_exception($e, $num)

  Process an Test2::Event::Exception event.

@out = $TAP->event_skip($e)
@out = $TAP->event_skip($e, $num)

  Process an Test2::Event::Skip event.

@out = $TAP->event_subtest($e)
@out = $TAP->event_subtest($e, $num)

  Process an Test2::Event::Subtest event.

@out = $TAP->event_other($e, $num)

  Fallback for unregistered event types. It uses the Test2::Event API to convert the event to TAP.

# SOURCE

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

# MAINTAINERS

Chad Granum <exodist@cpan.org>

# AUTHORS

Chad Granum <exodist@cpan.org>
Kent Fredric <kentnl@cpan.org>

# COPYRIGHT

Copyright 2016 Chad Granum <exodist@cpan.org>.

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

See http://dev.perl.org/licenses/