<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::Formatter;
use strict;
use warnings;

our $VERSION = '1.302190';


my %ADDED;
sub import {
    my $class = shift;
    return if $class eq __PACKAGE__;
    return if $ADDED{$class}++;
    require Test2::API;
    Test2::API::test2_formatter_add($class);
}

sub new_root {
    my $class = shift;
    return $class-&gt;new(@_);
}

sub supports_tables { 0 }

sub hide_buffered { 1 }

sub terminate { }

sub finalize { }

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Formatter - Namespace for formatters.

=head1 DESCRIPTION

This is the namespace for formatters. This is an empty package.

=head1 CREATING FORMATTERS

A formatter is any package or object with a C&lt;write($event, $num)&gt; method.

    package Test2::Formatter::Foo;
    use strict;
    use warnings;

    sub write {
        my $self_or_class = shift;
        my ($event, $assert_num) = @_;
        ...
    }

    sub hide_buffered { 1 }

    sub terminate { }

    sub finalize { }

    sub supports_tables { return $BOOL }

    sub new_root {
        my $class = shift;
        ...
        $class-&gt;new(@_);
    }

    1;

The C&lt;write&gt; method is a method, so it either gets a class or instance. The two
arguments are the C&lt;$event&gt; object it should record, and the C&lt;$assert_num&gt;
which is the number of the current assertion (ok), or the last assertion if
this event is not itself an assertion. The assertion number may be any integer 0
or greater, and may be undefined in some cases.

The C&lt;hide_buffered()&gt; method must return a boolean. This is used to tell
buffered subtests whether or not to send it events as they are being buffered.
See L&lt;Test2::API/"run_subtest(...)"&gt; for more information.

The C&lt;terminate&gt; and C&lt;finalize&gt; methods are optional methods called that you
can implement if the format you're generating needs to handle these cases, for
example if you are generating XML and need close open tags.

The C&lt;terminate&gt; method is called when an event's C&lt;terminate&gt; method returns
true, for example when a L&lt;Test2::Event::Plan&gt; has a C&lt;'skip_all'&gt; plan, or
when a L&lt;Test2::Event::Bail&gt; event is sent. The C&lt;terminate&gt; method is passed
a single argument, the L&lt;Test2::Event&gt; object which triggered the terminate.

The C&lt;finalize&gt; method is always the last thing called on the formatter, I&lt;&lt;
except when C&lt;terminate&gt; is called for a Bail event &gt;&gt;. It is passed the
following arguments:

The C&lt;supports_tables&gt; method should be true if the formatter supports directly
rendering table data from the C&lt;info&gt; facets. This is a newer feature and many
older formatters may not support it. When not supported the formatter falls
back to rendering C&lt;detail&gt; instead of the C&lt;table&gt; data.

The C&lt;new_root&gt; method is used when constructing a root formatter. The default
is to just delegate to the regular C&lt;new()&gt; method, most formatters can ignore
this.

=over 4

=item * The number of tests that were planned

=item * The number of tests actually seen

=item * The number of tests which failed

=item * A boolean indicating whether or not the test suite passed

=item * A boolean indicating whether or not this call is for a subtest

=back

The C&lt;new_root&gt; method is called when C&lt;Test2::API::Stack&gt; Initializes the root
hub for the first time. Most formatters will simply have this call C&lt;&lt;
$class-&gt;new &gt;&gt;, which is the default behavior. Some formatters however may want
to take extra action during construction of the root formatter, this is where
they can do that.

=head1 SOURCE

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

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2020 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

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

See F&lt;http://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>