<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package TAP::Parser;

use strict;
use warnings;

use TAP::Parser::Grammar                   ();
use TAP::Parser::Result                    ();
use TAP::Parser::ResultFactory             ();
use TAP::Parser::Source                    ();
use TAP::Parser::Iterator                  ();
use TAP::Parser::IteratorFactory           ();
use TAP::Parser::SourceHandler::Executable ();
use TAP::Parser::SourceHandler::Perl       ();
use TAP::Parser::SourceHandler::File       ();
use TAP::Parser::SourceHandler::RawTAP     ();
use TAP::Parser::SourceHandler::Handle     ();

use Carp qw( confess );

use base 'TAP::Base';

=encoding utf8

=head1 NAME

TAP::Parser - Parse L&lt;TAP|Test::Harness::TAP&gt; output

=head1 VERSION

Version 3.42

=cut

our $VERSION = '3.42';

my $DEFAULT_TAP_VERSION = 12;
my $MAX_TAP_VERSION     = 13;

$ENV{TAP_VERSION} = $MAX_TAP_VERSION;

END {

    # For VMS.
    delete $ENV{TAP_VERSION};
}

BEGIN {    # making accessors
    __PACKAGE__-&gt;mk_methods(
        qw(
          _iterator
          _spool
          exec
          exit
          is_good_plan
          plan
          tests_planned
          tests_run
          wait
          version
          in_todo
          start_time
          end_time
          start_times
          end_times
          skip_all
          grammar_class
          result_factory_class
          iterator_factory_class
          )
    );

    sub _stream {    # deprecated
        my $self = shift;
        $self-&gt;_iterator(@_);
    }
}    # done making accessors

=head1 SYNOPSIS

    use TAP::Parser;

    my $parser = TAP::Parser-&gt;new( { source =&gt; $source } );

    while ( my $result = $parser-&gt;next ) {
        print $result-&gt;as_string;
    }

=head1 DESCRIPTION

C&lt;TAP::Parser&gt; is designed to produce a proper parse of TAP output. For
an example of how to run tests through this module, see the simple
harnesses C&lt;examples/&gt;.

There's a wiki dedicated to the Test Anything Protocol:

L&lt;http://testanything.org&gt;

It includes the TAP::Parser Cookbook:

L&lt;http://testanything.org/testing-with-tap/perl/tap::parser-cookbook.html&gt;

=head1 METHODS

=head2 Class Methods

=head3 C&lt;new&gt;

 my $parser = TAP::Parser-&gt;new(\%args);

Returns a new C&lt;TAP::Parser&gt; object.

The arguments should be a hashref with I&lt;one&gt; of the following keys:

=over 4

=item * C&lt;source&gt;

I&lt;CHANGED in 3.18&gt;

This is the preferred method of passing input to the constructor.

The C&lt;source&gt; is used to create a L&lt;TAP::Parser::Source&gt; that is passed to the
L&lt;/iterator_factory_class&gt; which in turn figures out how to handle the source and
creates a &lt;TAP::Parser::Iterator&gt; for it.  The iterator is used by the parser to
read in the TAP stream.

To configure the I&lt;IteratorFactory&gt; use the C&lt;sources&gt; parameter below.

Note that C&lt;source&gt;, C&lt;tap&gt; and C&lt;exec&gt; are I&lt;mutually exclusive&gt;.

=item * C&lt;tap&gt;

I&lt;CHANGED in 3.18&gt;

The value should be the complete TAP output.

The I&lt;tap&gt; is used to create a L&lt;TAP::Parser::Source&gt; that is passed to the
L&lt;/iterator_factory_class&gt; which in turn figures out how to handle the source and
creates a &lt;TAP::Parser::Iterator&gt; for it.  The iterator is used by the parser to
read in the TAP stream.

To configure the I&lt;IteratorFactory&gt; use the C&lt;sources&gt; parameter below.

Note that C&lt;source&gt;, C&lt;tap&gt; and C&lt;exec&gt; are I&lt;mutually exclusive&gt;.

=item * C&lt;exec&gt;

Must be passed an array reference.

The I&lt;exec&gt; array ref is used to create a L&lt;TAP::Parser::Source&gt; that is passed
to the L&lt;/iterator_factory_class&gt; which in turn figures out how to handle the
source and creates a &lt;TAP::Parser::Iterator&gt; for it.  The iterator is used by
the parser to read in the TAP stream.

By default the L&lt;TAP::Parser::SourceHandler::Executable&gt; class will create a
L&lt;TAP::Parser::Iterator::Process&gt; object to handle the source.  This passes the
array reference strings as command arguments to L&lt;IPC::Open3::open3|IPC::Open3&gt;:

 exec =&gt; [ '/usr/bin/ruby', 't/my_test.rb' ]

If any C&lt;test_args&gt; are given they will be appended to the end of the command
argument list.

To configure the I&lt;IteratorFactory&gt; use the C&lt;sources&gt; parameter below.

Note that C&lt;source&gt;, C&lt;tap&gt; and C&lt;exec&gt; are I&lt;mutually exclusive&gt;.

=back

The following keys are optional.

=over 4

=item * C&lt;sources&gt;

I&lt;NEW to 3.18&gt;.

If set, C&lt;sources&gt; must be a hashref containing the names of the
L&lt;TAP::Parser::SourceHandler&gt;s to load and/or configure.  The values are a
hash of configuration that will be accessible to the source handlers via
L&lt;TAP::Parser::Source/config_for&gt;.

For example:

  sources =&gt; {
    Perl =&gt; { exec =&gt; '/path/to/custom/perl' },
    File =&gt; { extensions =&gt; [ '.tap', '.txt' ] },
    MyCustom =&gt; { some =&gt; 'config' },
  }

This will cause C&lt;TAP::Parser&gt; to pass custom configuration to two of the built-
in source handlers - L&lt;TAP::Parser::SourceHandler::Perl&gt;,
L&lt;TAP::Parser::SourceHandler::File&gt; - and attempt to load the C&lt;MyCustom&gt;
class.  See L&lt;TAP::Parser::IteratorFactory/load_handlers&gt; for more detail.

The C&lt;sources&gt; parameter affects how C&lt;source&gt;, C&lt;tap&gt; and C&lt;exec&gt; parameters
are handled.

See L&lt;TAP::Parser::IteratorFactory&gt;, L&lt;TAP::Parser::SourceHandler&gt; and subclasses for
more details.

=item * C&lt;callback&gt;

If present, each callback corresponding to a given result type will be called
with the result as the argument if the C&lt;run&gt; method is used:

 my %callbacks = (
     test    =&gt; \&amp;test_callback,
     plan    =&gt; \&amp;plan_callback,
     comment =&gt; \&amp;comment_callback,
     bailout =&gt; \&amp;bailout_callback,
     unknown =&gt; \&amp;unknown_callback,
 );

 my $aggregator = TAP::Parser::Aggregator-&gt;new;
 for my $file ( @test_files ) {
     my $parser = TAP::Parser-&gt;new(
         {
             source    =&gt; $file,
             callbacks =&gt; \%callbacks,
         }
     );
     $parser-&gt;run;
     $aggregator-&gt;add( $file, $parser );
 }

=item * C&lt;switches&gt;

If using a Perl file as a source, optional switches may be passed which will
be used when invoking the perl executable.

 my $parser = TAP::Parser-&gt;new( {
     source   =&gt; $test_file,
     switches =&gt; [ '-Ilib' ],
 } );

=item * C&lt;test_args&gt;

Used in conjunction with the C&lt;source&gt; and C&lt;exec&gt; option to supply a reference
to an C&lt;@ARGV&gt; style array of arguments to pass to the test program.

=item * C&lt;spool&gt;

If passed a filehandle will write a copy of all parsed TAP to that handle.

=item * C&lt;merge&gt;

If false, STDERR is not captured (though it is 'relayed' to keep it
somewhat synchronized with STDOUT.)

If true, STDERR and STDOUT are the same filehandle.  This may cause
breakage if STDERR contains anything resembling TAP format, but does
allow exact synchronization.

Subtleties of this behavior may be platform-dependent and may change in
the future.

=item * C&lt;grammar_class&gt;

This option was introduced to let you easily customize which I&lt;grammar&gt; class
the parser should use.  It defaults to L&lt;TAP::Parser::Grammar&gt;.

See also L&lt;/make_grammar&gt;.

=item * C&lt;result_factory_class&gt;

This option was introduced to let you easily customize which I&lt;result&gt;
factory class the parser should use.  It defaults to
L&lt;TAP::Parser::ResultFactory&gt;.

See also L&lt;/make_result&gt;.

=item * C&lt;iterator_factory_class&gt;

I&lt;CHANGED in 3.18&gt;

This option was introduced to let you easily customize which I&lt;iterator&gt;
factory class the parser should use.  It defaults to
L&lt;TAP::Parser::IteratorFactory&gt;.

=back

=cut

# new() implementation supplied by TAP::Base

# This should make overriding behaviour of the Parser in subclasses easier:
sub _default_grammar_class          {'TAP::Parser::Grammar'}
sub _default_result_factory_class   {'TAP::Parser::ResultFactory'}
sub _default_iterator_factory_class {'TAP::Parser::IteratorFactory'}

##############################################################################

=head2 Instance Methods

=head3 C&lt;next&gt;

  my $parser = TAP::Parser-&gt;new( { source =&gt; $file } );
  while ( my $result = $parser-&gt;next ) {
      print $result-&gt;as_string, "\n";
  }

This method returns the results of the parsing, one result at a time.  Note
that it is destructive.  You can't rewind and examine previous results.

If callbacks are used, they will be issued before this call returns.

Each result returned is a subclass of L&lt;TAP::Parser::Result&gt;.  See that
module and related classes for more information on how to use them.

=cut

sub next {
    my $self = shift;
    return ( $self-&gt;{_iter} ||= $self-&gt;_iter )-&gt;();
}

##############################################################################

=head3 C&lt;run&gt;

  $parser-&gt;run;

This method merely runs the parser and parses all of the TAP.

=cut

sub run {
    my $self = shift;
    while ( defined( my $result = $self-&gt;next ) ) {

        # do nothing
    }
}

##############################################################################

=head3 C&lt;make_grammar&gt;

Make a new L&lt;TAP::Parser::Grammar&gt; object and return it.  Passes through any
arguments given.

The C&lt;grammar_class&gt; can be customized, as described in L&lt;/new&gt;.

=head3 C&lt;make_result&gt;

Make a new L&lt;TAP::Parser::Result&gt; object using the parser's
L&lt;TAP::Parser::ResultFactory&gt;, and return it.  Passes through any arguments
given.

The C&lt;result_factory_class&gt; can be customized, as described in L&lt;/new&gt;.

=head3 C&lt;make_iterator_factory&gt;

I&lt;NEW to 3.18&gt;.

Make a new L&lt;TAP::Parser::IteratorFactory&gt; object and return it.  Passes through
any arguments given.

C&lt;iterator_factory_class&gt; can be customized, as described in L&lt;/new&gt;.

=cut

# This should make overriding behaviour of the Parser in subclasses easier:
sub make_iterator_factory { shift-&gt;iterator_factory_class-&gt;new(@_); }
sub make_grammar          { shift-&gt;grammar_class-&gt;new(@_); }
sub make_result           { shift-&gt;result_factory_class-&gt;make_result(@_); }

{

    # of the following, anything beginning with an underscore is strictly
    # internal and should not be exposed.
    my %initialize = (
        version       =&gt; $DEFAULT_TAP_VERSION,
        plan          =&gt; '',                    # the test plan (e.g., 1..3)
        tests_run     =&gt; 0,                     # actual current test numbers
        skipped       =&gt; [],                    #
        todo          =&gt; [],                    #
        passed        =&gt; [],                    #
        failed        =&gt; [],                    #
        actual_failed =&gt; [],                    # how many tests really failed
        actual_passed =&gt; [],                    # how many tests really passed
        todo_passed  =&gt; [],    # tests which unexpectedly succeed
        parse_errors =&gt; [],    # perfect TAP should have none
    );

    # We seem to have this list hanging around all over the place. We could
    #Â&nbsp;probably get it from somewhere else to avoid the repetition.
    my @legal_callback = qw(
      test
      version
      plan
      comment
      bailout
      unknown
      yaml
      ALL
      ELSE
      EOF
    );

    my @class_overrides = qw(
      grammar_class
      result_factory_class
      iterator_factory_class
    );

    sub _initialize {
        my ( $self, $arg_for ) = @_;

        # everything here is basically designed to convert any TAP source to a
        # TAP::Parser::Iterator.

        # Shallow copy
        my %args = %{ $arg_for || {} };

        $self-&gt;SUPER::_initialize( \%args, \@legal_callback );

        # get any class overrides out first:
        for my $key (@class_overrides) {
            my $default_method = "_default_$key";
            my $val = delete $args{$key} || $self-&gt;$default_method();
            $self-&gt;$key($val);
        }

        my $iterator = delete $args{iterator};
        $iterator ||= delete $args{stream};    # deprecated
        my $tap         = delete $args{tap};
        my $version     = delete $args{version};
        my $raw_source  = delete $args{source};
        my $sources     = delete $args{sources};
        my $exec        = delete $args{exec};
        my $merge       = delete $args{merge};
        my $spool       = delete $args{spool};
        my $switches    = delete $args{switches};
        my $ignore_exit = delete $args{ignore_exit};
        my $test_args   = delete $args{test_args} || [];

        if ( 1 &lt; grep {defined} $iterator, $tap, $raw_source, $exec ) {
            $self-&gt;_croak(
                "You may only choose one of 'exec', 'tap', 'source' or 'iterator'"
            );
        }

        if ( my @excess = sort keys %args ) {
            $self-&gt;_croak("Unknown options: @excess");
        }

        # convert $tap &amp; $exec to $raw_source equiv.
        my $type   = '';
        my $source = TAP::Parser::Source-&gt;new;
        if ($tap) {
            $type = 'raw TAP';
            $source-&gt;raw( \$tap );
        }
        elsif ($exec) {
            $type = 'exec ' . $exec-&gt;[0];
            $source-&gt;raw( { exec =&gt; $exec } );
        }
        elsif ($raw_source) {
            $type = 'source ' . ref($raw_source) || $raw_source;
            $source-&gt;raw( ref($raw_source) ? $raw_source : \$raw_source );
        }
        elsif ($iterator) {
            $type = 'iterator ' . ref($iterator);
        }

        if ( $source-&gt;raw ) {
            my $src_factory = $self-&gt;make_iterator_factory($sources);
            $source-&gt;merge($merge)-&gt;switches($switches)
              -&gt;test_args($test_args);
            $iterator = $src_factory-&gt;make_iterator($source);
        }

        unless ($iterator) {
            $self-&gt;_croak(
                "PANIC: could not determine iterator for input $type");
        }

        while ( my ( $k, $v ) = each %initialize ) {
            $self-&gt;{$k} = 'ARRAY' eq ref $v ? [] : $v;
        }

        $self-&gt;version($version) if $version;
        $self-&gt;_iterator($iterator);
        $self-&gt;_spool($spool);
        $self-&gt;ignore_exit($ignore_exit);

        return $self;
    }
}

=head1 INDIVIDUAL RESULTS

If you've read this far in the docs, you've seen this:

    while ( my $result = $parser-&gt;next ) {
        print $result-&gt;as_string;
    }

Each result returned is a L&lt;TAP::Parser::Result&gt; subclass, referred to as
I&lt;result types&gt;.

=head2 Result types

Basically, you fetch individual results from the TAP.  The six types, with
examples of each, are as follows:

=over 4

=item * Version

 TAP version 12

=item * Plan

 1..42

=item * Pragma

 pragma +strict

=item * Test

 ok 3 - We should start with some foobar!

=item * Comment

 # Hope we don't use up the foobar.

=item * Bailout

 Bail out!  We ran out of foobar!

=item * Unknown

 ... yo, this ain't TAP! ...

=back

Each result fetched is a result object of a different type.  There are common
methods to each result object and different types may have methods unique to
their type.  Sometimes a type method may be overridden in a subclass, but its
use is guaranteed to be identical.

=head2 Common type methods

=head3 C&lt;type&gt;

Returns the type of result, such as C&lt;comment&gt; or C&lt;test&gt;.

=head3 C&lt;as_string&gt;

Prints a string representation of the token.  This might not be the exact
output, however.  Tests will have test numbers added if not present, TODO and
SKIP directives will be capitalized and, in general, things will be cleaned
up.  If you need the original text for the token, see the C&lt;raw&gt; method.

=head3  C&lt;raw&gt;

Returns the original line of text which was parsed.

=head3 C&lt;is_plan&gt;

Indicates whether or not this is the test plan line.

=head3 C&lt;is_test&gt;

Indicates whether or not this is a test line.

=head3 C&lt;is_comment&gt;

Indicates whether or not this is a comment. Comments will generally only
appear in the TAP stream if STDERR is merged to STDOUT. See the
C&lt;merge&gt; option.

=head3 C&lt;is_bailout&gt;

Indicates whether or not this is bailout line.

=head3 C&lt;is_yaml&gt;

Indicates whether or not the current item is a YAML block.

=head3 C&lt;is_unknown&gt;

Indicates whether or not the current line could be parsed.

=head3 C&lt;is_ok&gt;

  if ( $result-&gt;is_ok ) { ... }

Reports whether or not a given result has passed.  Anything which is B&lt;not&gt; a
test result returns true.  This is merely provided as a convenient shortcut
which allows you to do this:

 my $parser = TAP::Parser-&gt;new( { source =&gt; $source } );
 while ( my $result = $parser-&gt;next ) {
     # only print failing results
     print $result-&gt;as_string unless $result-&gt;is_ok;
 }

=head2 C&lt;plan&gt; methods

 if ( $result-&gt;is_plan ) { ... }

If the above evaluates as true, the following methods will be available on the
C&lt;$result&gt; object.

=head3 C&lt;plan&gt;

  if ( $result-&gt;is_plan ) {
     print $result-&gt;plan;
  }

This is merely a synonym for C&lt;as_string&gt;.

=head3 C&lt;directive&gt;

 my $directive = $result-&gt;directive;

If a SKIP directive is included with the plan, this method will return it.

 1..0 # SKIP: why bother?

=head3 C&lt;explanation&gt;

 my $explanation = $result-&gt;explanation;

If a SKIP directive was included with the plan, this method will return the
explanation, if any.

=head2 C&lt;pragma&gt; methods

 if ( $result-&gt;is_pragma ) { ... }

If the above evaluates as true, the following methods will be available on the
C&lt;$result&gt; object.

=head3 C&lt;pragmas&gt;

Returns a list of pragmas each of which is a + or - followed by the
pragma name.

=head2 C&lt;comment&gt; methods

 if ( $result-&gt;is_comment ) { ... }

If the above evaluates as true, the following methods will be available on the
C&lt;$result&gt; object.

=head3 C&lt;comment&gt;

  if ( $result-&gt;is_comment ) {
      my $comment = $result-&gt;comment;
      print "I have something to say:  $comment";
  }

=head2 C&lt;bailout&gt; methods

 if ( $result-&gt;is_bailout ) { ... }

If the above evaluates as true, the following methods will be available on the
C&lt;$result&gt; object.

=head3 C&lt;explanation&gt;

  if ( $result-&gt;is_bailout ) {
      my $explanation = $result-&gt;explanation;
      print "We bailed out because ($explanation)";
  }

If, and only if, a token is a bailout token, you can get an "explanation" via
this method.  The explanation is the text after the mystical "Bail out!" words
which appear in the tap output.

=head2 C&lt;unknown&gt; methods

 if ( $result-&gt;is_unknown ) { ... }

There are no unique methods for unknown results.

=head2 C&lt;test&gt; methods

 if ( $result-&gt;is_test ) { ... }

If the above evaluates as true, the following methods will be available on the
C&lt;$result&gt; object.

=head3 C&lt;ok&gt;

  my $ok = $result-&gt;ok;

Returns the literal text of the C&lt;ok&gt; or C&lt;not ok&gt; status.

=head3 C&lt;number&gt;

  my $test_number = $result-&gt;number;

Returns the number of the test, even if the original TAP output did not supply
that number.

=head3 C&lt;description&gt;

  my $description = $result-&gt;description;

Returns the description of the test, if any.  This is the portion after the
test number but before the directive.

=head3 C&lt;directive&gt;

  my $directive = $result-&gt;directive;

Returns either C&lt;TODO&gt; or C&lt;SKIP&gt; if either directive was present for a test
line.

=head3 C&lt;explanation&gt;

  my $explanation = $result-&gt;explanation;

If a test had either a C&lt;TODO&gt; or C&lt;SKIP&gt; directive, this method will return
the accompanying explanation, if present.

  not ok 17 - 'Pigs can fly' # TODO not enough acid

For the above line, the explanation is I&lt;not enough acid&gt;.

=head3 C&lt;is_ok&gt;

  if ( $result-&gt;is_ok ) { ... }

Returns a boolean value indicating whether or not the test passed.  Remember
that for TODO tests, the test always passes.

B&lt;Note:&gt;  this was formerly C&lt;passed&gt;.  The latter method is deprecated and
will issue a warning.

=head3 C&lt;is_actual_ok&gt;

  if ( $result-&gt;is_actual_ok ) { ... }

Returns a boolean value indicating whether or not the test passed, regardless
of its TODO status.

B&lt;Note:&gt;  this was formerly C&lt;actual_passed&gt;.  The latter method is deprecated
and will issue a warning.

=head3 C&lt;is_unplanned&gt;

  if ( $test-&gt;is_unplanned ) { ... }

If a test number is greater than the number of planned tests, this method will
return true.  Unplanned tests will I&lt;always&gt; return false for C&lt;is_ok&gt;,
regardless of whether or not the test C&lt;has_todo&gt; (see
L&lt;TAP::Parser::Result::Test&gt; for more information about this).

=head3 C&lt;has_skip&gt;

  if ( $result-&gt;has_skip ) { ... }

Returns a boolean value indicating whether or not this test had a SKIP
directive.

=head3 C&lt;has_todo&gt;

  if ( $result-&gt;has_todo ) { ... }

Returns a boolean value indicating whether or not this test had a TODO
directive.

Note that TODO tests I&lt;always&gt; pass.  If you need to know whether or not
they really passed, check the C&lt;is_actual_ok&gt; method.

=head3 C&lt;in_todo&gt;

  if ( $parser-&gt;in_todo ) { ... }

True while the most recent result was a TODO. Becomes true before the
TODO result is returned and stays true until just before the next non-
TODO test is returned.

=head1 TOTAL RESULTS

After parsing the TAP, there are many methods available to let you dig through
the results and determine what is meaningful to you.

=head2 Individual Results

These results refer to individual tests which are run.

=head3 C&lt;passed&gt;

 my @passed = $parser-&gt;passed; # the test numbers which passed
 my $passed = $parser-&gt;passed; # the number of tests which passed

This method lets you know which (or how many) tests passed.  If a test failed
but had a TODO directive, it will be counted as a passed test.

=cut

sub passed {
    return @{ $_[0]-&gt;{passed} }
      if ref $_[0]-&gt;{passed};
    return wantarray ? 1 .. $_[0]-&gt;{passed} : $_[0]-&gt;{passed};
}

=head3 C&lt;failed&gt;

 my @failed = $parser-&gt;failed; # the test numbers which failed
 my $failed = $parser-&gt;failed; # the number of tests which failed

This method lets you know which (or how many) tests failed.  If a test passed
but had a TODO directive, it will B&lt;NOT&gt; be counted as a failed test.

=cut

sub failed { @{ shift-&gt;{failed} } }

=head3 C&lt;actual_passed&gt;

 # the test numbers which actually passed
 my @actual_passed = $parser-&gt;actual_passed;

 # the number of tests which actually passed
 my $actual_passed = $parser-&gt;actual_passed;

This method lets you know which (or how many) tests actually passed,
regardless of whether or not a TODO directive was found.

=cut

sub actual_passed {
    return @{ $_[0]-&gt;{actual_passed} }
      if ref $_[0]-&gt;{actual_passed};
    return wantarray ? 1 .. $_[0]-&gt;{actual_passed} : $_[0]-&gt;{actual_passed};
}
*actual_ok = \&amp;actual_passed;

=head3 C&lt;actual_ok&gt;

This method is a synonym for C&lt;actual_passed&gt;.

=head3 C&lt;actual_failed&gt;

 # the test numbers which actually failed
 my @actual_failed = $parser-&gt;actual_failed;

 # the number of tests which actually failed
 my $actual_failed = $parser-&gt;actual_failed;

This method lets you know which (or how many) tests actually failed,
regardless of whether or not a TODO directive was found.

=cut

sub actual_failed { @{ shift-&gt;{actual_failed} } }

##############################################################################

=head3 C&lt;todo&gt;

 my @todo = $parser-&gt;todo; # the test numbers with todo directives
 my $todo = $parser-&gt;todo; # the number of tests with todo directives

This method lets you know which (or how many) tests had TODO directives.

=cut

sub todo { @{ shift-&gt;{todo} } }

=head3 C&lt;todo_passed&gt;

 # the test numbers which unexpectedly succeeded
 my @todo_passed = $parser-&gt;todo_passed;

 # the number of tests which unexpectedly succeeded
 my $todo_passed = $parser-&gt;todo_passed;

This method lets you know which (or how many) tests actually passed but were
declared as "TODO" tests.

=cut

sub todo_passed { @{ shift-&gt;{todo_passed} } }

##############################################################################

=head3 C&lt;todo_failed&gt;

  # deprecated in favor of 'todo_passed'.  This method was horribly misnamed.

This was a badly misnamed method.  It indicates which TODO tests unexpectedly
succeeded.  Will now issue a warning and call C&lt;todo_passed&gt;.

=cut

sub todo_failed {
    warn
      '"todo_failed" is deprecated.  Please use "todo_passed".  See the docs.';
    goto &amp;todo_passed;
}

=head3 C&lt;skipped&gt;

 my @skipped = $parser-&gt;skipped; # the test numbers with SKIP directives
 my $skipped = $parser-&gt;skipped; # the number of tests with SKIP directives

This method lets you know which (or how many) tests had SKIP directives.

=cut

sub skipped { @{ shift-&gt;{skipped} } }

=head2 Pragmas

=head3 C&lt;pragma&gt;

Get or set a pragma. To get the state of a pragma:

  if ( $p-&gt;pragma('strict') ) {
      # be strict
  }

To set the state of a pragma:

  $p-&gt;pragma('strict', 1); # enable strict mode

=cut

sub pragma {
    my ( $self, $pragma ) = splice @_, 0, 2;

    return $self-&gt;{pragma}-&gt;{$pragma} unless @_;

    if ( my $state = shift ) {
        $self-&gt;{pragma}-&gt;{$pragma} = 1;
    }
    else {
        delete $self-&gt;{pragma}-&gt;{$pragma};
    }

    return;
}

=head3 C&lt;pragmas&gt;

Get a list of all the currently enabled pragmas:

  my @pragmas_enabled = $p-&gt;pragmas;

=cut

sub pragmas { sort keys %{ shift-&gt;{pragma} || {} } }

=head2 Summary Results

These results are "meta" information about the total results of an individual
test program.

=head3 C&lt;plan&gt;

 my $plan = $parser-&gt;plan;

Returns the test plan, if found.

=head3 C&lt;good_plan&gt;

Deprecated.  Use C&lt;is_good_plan&gt; instead.

=cut

sub good_plan {
    warn 'good_plan() is deprecated.  Please use "is_good_plan()"';
    goto &amp;is_good_plan;
}

##############################################################################

=head3 C&lt;is_good_plan&gt;

  if ( $parser-&gt;is_good_plan ) { ... }

Returns a boolean value indicating whether or not the number of tests planned
matches the number of tests run.

B&lt;Note:&gt;  this was formerly C&lt;good_plan&gt;.  The latter method is deprecated and
will issue a warning.

And since we're on that subject ...

=head3 C&lt;tests_planned&gt;

  print $parser-&gt;tests_planned;

Returns the number of tests planned, according to the plan.  For example, a
plan of '1..17' will mean that 17 tests were planned.

=head3 C&lt;tests_run&gt;

  print $parser-&gt;tests_run;

Returns the number of tests which actually were run.  Hopefully this will
match the number of C&lt;&lt; $parser-&gt;tests_planned &gt;&gt;.

=head3 C&lt;skip_all&gt;

Returns a true value (actually the reason for skipping) if all tests
were skipped.

=head3 C&lt;start_time&gt;

Returns the wall-clock time when the Parser was created.

=head3 C&lt;end_time&gt;

Returns the wall-clock time when the end of TAP input was seen.

=head3 C&lt;start_times&gt;

Returns the CPU times (like L&lt;perlfunc/times&gt; when the Parser was created.

=head3 C&lt;end_times&gt;

Returns the CPU times (like L&lt;perlfunc/times&gt; when the end of TAP
input was seen.

=head3 C&lt;has_problems&gt;

  if ( $parser-&gt;has_problems ) {
      ...
  }

This is a 'catch-all' method which returns true if any tests have currently
failed, any TODO tests unexpectedly succeeded, or any parse errors occurred.

=cut

sub has_problems {
    my $self = shift;
    return
         $self-&gt;failed
      || $self-&gt;parse_errors
      || ( !$self-&gt;ignore_exit &amp;&amp; ( $self-&gt;wait || $self-&gt;exit ) );
}

=head3 C&lt;version&gt;

  $parser-&gt;version;

Once the parser is done, this will return the version number for the
parsed TAP. Version numbers were introduced with TAP version 13 so if no
version number is found version 12 is assumed.

=head3 C&lt;exit&gt;

  $parser-&gt;exit;

Once the parser is done, this will return the exit status.  If the parser ran
an executable, it returns the exit status of the executable.

=head3 C&lt;wait&gt;

  $parser-&gt;wait;

Once the parser is done, this will return the wait status.  If the parser ran
an executable, it returns the wait status of the executable.  Otherwise, this
merely returns the C&lt;exit&gt; status.

=head2 C&lt;ignore_exit&gt;

  $parser-&gt;ignore_exit(1);

Tell the parser to ignore the exit status from the test when determining
whether the test passed. Normally tests with non-zero exit status are
considered to have failed even if all individual tests passed. In cases
where it is not possible to control the exit value of the test script
use this option to ignore it.

=cut

sub ignore_exit { shift-&gt;pragma( 'ignore_exit', @_ ) }

=head3 C&lt;parse_errors&gt;

 my @errors = $parser-&gt;parse_errors; # the parser errors
 my $errors = $parser-&gt;parse_errors; # the number of parser_errors

Fortunately, all TAP output is perfect.  In the event that it is not, this
method will return parser errors.  Note that a junk line which the parser does
not recognize is C&lt;not&gt; an error.  This allows this parser to handle future
versions of TAP.  The following are all TAP errors reported by the parser:

=over 4

=item * Misplaced plan

The plan (for example, '1..5'), must only come at the beginning or end of the
TAP output.

=item * No plan

Gotta have a plan!

=item * More than one plan

 1..3
 ok 1 - input file opened
 not ok 2 - first line of the input valid # todo some data
 ok 3 read the rest of the file
 1..3

Right.  Very funny.  Don't do that.

=item * Test numbers out of sequence

 1..3
 ok 1 - input file opened
 not ok 2 - first line of the input valid # todo some data
 ok 2 read the rest of the file

That last test line above should have the number '3' instead of '2'.

Note that it's perfectly acceptable for some lines to have test numbers and
others to not have them.  However, when a test number is found, it must be in
sequence.  The following is also an error:

 1..3
 ok 1 - input file opened
 not ok - first line of the input valid # todo some data
 ok 2 read the rest of the file

But this is not:

 1..3
 ok  - input file opened
 not ok - first line of the input valid # todo some data
 ok 3 read the rest of the file

=back

=cut

sub parse_errors { @{ shift-&gt;{parse_errors} } }

sub _add_error {
    my ( $self, $error ) = @_;
    push @{ $self-&gt;{parse_errors} } =&gt; $error;
    return $self;
}

sub _make_state_table {
    my $self = shift;
    my %states;
    my %planned_todo = ();

    #Â&nbsp;These transitions are defaults for all states
    my %state_globals = (
        comment =&gt; {},
        bailout =&gt; {},
        yaml    =&gt; {},
        version =&gt; {
            act =&gt; sub {
                $self-&gt;_add_error(
                    'If TAP version is present it must be the first line of output'
                );
            },
        },
        unknown =&gt; {
            act =&gt; sub {
                my $unk = shift;
                if ( $self-&gt;pragma('strict') ) {
                    $self-&gt;_add_error(
                        'Unknown TAP token: "' . $unk-&gt;raw . '"' );
                }
            },
        },
        pragma =&gt; {
            act =&gt; sub {
                my ($pragma) = @_;
                for my $pr ( $pragma-&gt;pragmas ) {
                    if ( $pr =~ /^ ([-+])(\w+) $/x ) {
                        $self-&gt;pragma( $2, $1 eq '+' );
                    }
                }
            },
        },
    );

    # Provides default elements for transitions
    my %state_defaults = (
        plan =&gt; {
            act =&gt; sub {
                my ($plan) = @_;
                $self-&gt;tests_planned( $plan-&gt;tests_planned );
                $self-&gt;plan( $plan-&gt;plan );
                if ( $plan-&gt;has_skip ) {
                    $self-&gt;skip_all( $plan-&gt;explanation
                          || '(no reason given)' );
                }

                $planned_todo{$_}++ for @{ $plan-&gt;todo_list };
            },
        },
        test =&gt; {
            act =&gt; sub {
                my ($test) = @_;

                my ( $number, $tests_run )
                  = ( $test-&gt;number, ++$self-&gt;{tests_run} );

                # Fake TODO state
                if ( defined $number &amp;&amp; delete $planned_todo{$number} ) {
                    $test-&gt;set_directive('TODO');
                }

                my $has_todo = $test-&gt;has_todo;

                $self-&gt;in_todo($has_todo);
                if ( defined( my $tests_planned = $self-&gt;tests_planned ) ) {
                    if ( $tests_run &gt; $tests_planned ) {
                        $test-&gt;is_unplanned(1);
                    }
                }

                if ( defined $number ) {
                    if ( $number != $tests_run ) {
                        my $count = $tests_run;
                        $self-&gt;_add_error( "Tests out of sequence.  Found "
                              . "($number) but expected ($count)" );
                    }
                }
                else {
                    $test-&gt;_number( $number = $tests_run );
                }

                push @{ $self-&gt;{todo} } =&gt; $number if $has_todo;
                push @{ $self-&gt;{todo_passed} } =&gt; $number
                  if $test-&gt;todo_passed;
                push @{ $self-&gt;{skipped} } =&gt; $number
                  if $test-&gt;has_skip;

                push @{ $self-&gt;{ $test-&gt;is_ok ? 'passed' : 'failed' } } =&gt;
                  $number;
                push @{
                    $self-&gt;{
                        $test-&gt;is_actual_ok
                        ? 'actual_passed'
                        : 'actual_failed'
                      }
                  } =&gt; $number;
            },
        },
        yaml =&gt; { act =&gt; sub { }, },
    );

    # Each state contains a hash the keys of which match a token type. For
    # each token
    # type there may be:
    #   act      A coderef to run
    #   goto     The new state to move to. Stay in this state if
    #            missing
    #   continue Goto the new state and run the new state for the
    #            current token
    %states = (
        INIT =&gt; {
            version =&gt; {
                act =&gt; sub {
                    my ($version) = @_;
                    my $ver_num = $version-&gt;version;
                    if ( $ver_num &lt;= $DEFAULT_TAP_VERSION ) {
                        my $ver_min = $DEFAULT_TAP_VERSION + 1;
                        $self-&gt;_add_error(
                                "Explicit TAP version must be at least "
                              . "$ver_min. Got version $ver_num" );
                        $ver_num = $DEFAULT_TAP_VERSION;
                    }
                    if ( $ver_num &gt; $MAX_TAP_VERSION ) {
                        $self-&gt;_add_error(
                                "TAP specified version $ver_num but "
                              . "we don't know about versions later "
                              . "than $MAX_TAP_VERSION" );
                        $ver_num = $MAX_TAP_VERSION;
                    }
                    $self-&gt;version($ver_num);
                    $self-&gt;_grammar-&gt;set_version($ver_num);
                },
                goto =&gt; 'PLAN'
            },
            plan =&gt; { goto =&gt; 'PLANNED' },
            test =&gt; { goto =&gt; 'UNPLANNED' },
        },
        PLAN =&gt; {
            plan =&gt; { goto =&gt; 'PLANNED' },
            test =&gt; { goto =&gt; 'UNPLANNED' },
        },
        PLANNED =&gt; {
            test =&gt; { goto =&gt; 'PLANNED_AFTER_TEST' },
            plan =&gt; {
                act =&gt; sub {
                    my ($version) = @_;
                    $self-&gt;_add_error(
                        'More than one plan found in TAP output');
                },
            },
        },
        PLANNED_AFTER_TEST =&gt; {
            test =&gt; { goto =&gt; 'PLANNED_AFTER_TEST' },
            plan =&gt; { act  =&gt; sub { }, continue =&gt; 'PLANNED' },
            yaml =&gt; { goto =&gt; 'PLANNED' },
        },
        GOT_PLAN =&gt; {
            test =&gt; {
                act =&gt; sub {
                    my ($plan) = @_;
                    my $line = $self-&gt;plan;
                    $self-&gt;_add_error(
                            "Plan ($line) must be at the beginning "
                          . "or end of the TAP output" );
                    $self-&gt;is_good_plan(0);
                },
                continue =&gt; 'PLANNED'
            },
            plan =&gt; { continue =&gt; 'PLANNED' },
        },
        UNPLANNED =&gt; {
            test =&gt; { goto =&gt; 'UNPLANNED_AFTER_TEST' },
            plan =&gt; { goto =&gt; 'GOT_PLAN' },
        },
        UNPLANNED_AFTER_TEST =&gt; {
            test =&gt; { act  =&gt; sub { }, continue =&gt; 'UNPLANNED' },
            plan =&gt; { act  =&gt; sub { }, continue =&gt; 'UNPLANNED' },
            yaml =&gt; { goto =&gt; 'UNPLANNED' },
        },
    );

    # Apply globals and defaults to state table
    for my $name ( keys %states ) {

        # Merge with globals
        my $st = { %state_globals, %{ $states{$name} } };

        # Add defaults
        for my $next ( sort keys %{$st} ) {
            if ( my $default = $state_defaults{$next} ) {
                for my $def ( sort keys %{$default} ) {
                    $st-&gt;{$next}-&gt;{$def} ||= $default-&gt;{$def};
                }
            }
        }

        # Stuff back in table
        $states{$name} = $st;
    }

    return \%states;
}

=head3 C&lt;get_select_handles&gt;

Get an a list of file handles which can be passed to C&lt;select&gt; to
determine the readiness of this parser.

=cut

sub get_select_handles { shift-&gt;_iterator-&gt;get_select_handles }

sub _grammar {
    my $self = shift;
    return $self-&gt;{_grammar} = shift if @_;

    return $self-&gt;{_grammar} ||= $self-&gt;make_grammar(
        {   iterator =&gt; $self-&gt;_iterator,
            parser   =&gt; $self,
            version  =&gt; $self-&gt;version
        }
    );
}

sub _iter {
    my $self        = shift;
    my $iterator    = $self-&gt;_iterator;
    my $grammar     = $self-&gt;_grammar;
    my $spool       = $self-&gt;_spool;
    my $state       = 'INIT';
    my $state_table = $self-&gt;_make_state_table;

    $self-&gt;start_time( $self-&gt;get_time );
    $self-&gt;start_times( $self-&gt;get_times );

    # Make next_state closure
    my $next_state = sub {
        my $token = shift;
        my $type  = $token-&gt;type;
        TRANS: {
            my $state_spec = $state_table-&gt;{$state}
              or die "Illegal state: $state";

            if ( my $next = $state_spec-&gt;{$type} ) {
                if ( my $act = $next-&gt;{act} ) {
                    $act-&gt;($token);
                }
                if ( my $cont = $next-&gt;{continue} ) {
                    $state = $cont;
                    redo TRANS;
                }
                elsif ( my $goto = $next-&gt;{goto} ) {
                    $state = $goto;
                }
            }
            else {
                confess("Unhandled token type: $type\n");
            }
        }
        return $token;
    };

    # Handle end of stream - which means either pop a block or finish
    my $end_handler = sub {
        $self-&gt;exit( $iterator-&gt;exit );
        $self-&gt;wait( $iterator-&gt;wait );
        $self-&gt;_finish;
        return;
    };

    # Finally make the closure that we return. For performance reasons
    # there are two versions of the returned function: one that handles
    # callbacks and one that does not.
    if ( $self-&gt;_has_callbacks ) {
        return sub {
            my $result = eval { $grammar-&gt;tokenize };
            $self-&gt;_add_error($@) if $@;

            if ( defined $result ) {
                $result = $next_state-&gt;($result);

                if ( my $code = $self-&gt;_callback_for( $result-&gt;type ) ) {
                    $_-&gt;($result) for @{$code};
                }
                else {
                    $self-&gt;_make_callback( 'ELSE', $result );
                }

                $self-&gt;_make_callback( 'ALL', $result );

                # Echo TAP to spool file
                print {$spool} $result-&gt;raw, "\n" if $spool;
            }
            else {
                $result = $end_handler-&gt;();
                $self-&gt;_make_callback( 'EOF', $self )
                  unless defined $result;
            }

            return $result;
        };
    }    # _has_callbacks
    else {
        return sub {
            my $result = eval { $grammar-&gt;tokenize };
            $self-&gt;_add_error($@) if $@;

            if ( defined $result ) {
                $result = $next_state-&gt;($result);

                # Echo TAP to spool file
                print {$spool} $result-&gt;raw, "\n" if $spool;
            }
            else {
                $result = $end_handler-&gt;();
            }

            return $result;
        };
    }    # no callbacks
}

sub _finish {
    my $self = shift;

    $self-&gt;end_time( $self-&gt;get_time );
    $self-&gt;end_times( $self-&gt;get_times );

    # Avoid leaks
    $self-&gt;_iterator(undef);
    $self-&gt;_grammar(undef);

    # If we just delete the iter we won't get a fault if it's recreated.
    # Instead we set it to a sub that returns an infinite
    # stream of undef. This segfaults on 5.5.4, presumably because
    # we're still executing the closure that gets replaced and it hasn't
    # been protected with a refcount.
    $self-&gt;{_iter} = sub {return}
      if $] &gt;= 5.006;

    # sanity checks
    if ( !$self-&gt;plan ) {
        $self-&gt;_add_error('No plan found in TAP output');
    }
    else {
        $self-&gt;is_good_plan(1) unless defined $self-&gt;is_good_plan;
    }
    if ( $self-&gt;tests_run != ( $self-&gt;tests_planned || 0 ) ) {
        $self-&gt;is_good_plan(0);
        if ( defined( my $planned = $self-&gt;tests_planned ) ) {
            my $ran = $self-&gt;tests_run;
            $self-&gt;_add_error(
                "Bad plan.  You planned $planned tests but ran $ran.");
        }
    }
    if ( $self-&gt;tests_run != ( $self-&gt;passed + $self-&gt;failed ) ) {

        # this should never happen
        my $actual = $self-&gt;tests_run;
        my $passed = $self-&gt;passed;
        my $failed = $self-&gt;failed;
        $self-&gt;_croak( "Panic: planned test count ($actual) did not equal "
              . "sum of passed ($passed) and failed ($failed) tests!" );
    }

    $self-&gt;is_good_plan(0) unless defined $self-&gt;is_good_plan;

    unless ( $self-&gt;parse_errors ) {
        # Optimise storage where possible
        if ( $self-&gt;tests_run == @{$self-&gt;{passed}} ) {
            $self-&gt;{passed} = $self-&gt;tests_run;
        }
        if ( $self-&gt;tests_run == @{$self-&gt;{actual_passed}} ) {
            $self-&gt;{actual_passed} = $self-&gt;tests_run;
        }
    }

    return $self;
}

=head3 C&lt;delete_spool&gt;

Delete and return the spool.

  my $fh = $parser-&gt;delete_spool;

=cut

sub delete_spool {
    my $self = shift;

    return delete $self-&gt;{_spool};
}

##############################################################################

=head1 CALLBACKS

As mentioned earlier, a "callback" key may be added to the
C&lt;TAP::Parser&gt; constructor. If present, each callback corresponding to a
given result type will be called with the result as the argument if the
C&lt;run&gt; method is used. The callback is expected to be a subroutine
reference (or anonymous subroutine) which is invoked with the parser
result as its argument.

 my %callbacks = (
     test    =&gt; \&amp;test_callback,
     plan    =&gt; \&amp;plan_callback,
     comment =&gt; \&amp;comment_callback,
     bailout =&gt; \&amp;bailout_callback,
     unknown =&gt; \&amp;unknown_callback,
 );

 my $aggregator = TAP::Parser::Aggregator-&gt;new;
 for my $file ( @test_files ) {
     my $parser = TAP::Parser-&gt;new(
         {
             source    =&gt; $file,
             callbacks =&gt; \%callbacks,
         }
     );
     $parser-&gt;run;
     $aggregator-&gt;add( $file, $parser );
 }

Callbacks may also be added like this:

 $parser-&gt;callback( test =&gt; \&amp;test_callback );
 $parser-&gt;callback( plan =&gt; \&amp;plan_callback );

The following keys allowed for callbacks. These keys are case-sensitive.

=over 4

=item * C&lt;test&gt;

Invoked if C&lt;&lt; $result-&gt;is_test &gt;&gt; returns true.

=item * C&lt;version&gt;

Invoked if C&lt;&lt; $result-&gt;is_version &gt;&gt; returns true.

=item * C&lt;plan&gt;

Invoked if C&lt;&lt; $result-&gt;is_plan &gt;&gt; returns true.

=item * C&lt;comment&gt;

Invoked if C&lt;&lt; $result-&gt;is_comment &gt;&gt; returns true.

=item * C&lt;bailout&gt;

Invoked if C&lt;&lt; $result-&gt;is_unknown &gt;&gt; returns true.

=item * C&lt;yaml&gt;

Invoked if C&lt;&lt; $result-&gt;is_yaml &gt;&gt; returns true.

=item * C&lt;unknown&gt;

Invoked if C&lt;&lt; $result-&gt;is_unknown &gt;&gt; returns true.

=item * C&lt;ELSE&gt;

If a result does not have a callback defined for it, this callback will
be invoked. Thus, if all of the previous result types are specified as
callbacks, this callback will I&lt;never&gt; be invoked.

=item * C&lt;ALL&gt;

This callback will always be invoked and this will happen for each
result after one of the above callbacks is invoked.  For example, if
L&lt;Term::ANSIColor&gt; is loaded, you could use the following to color your
test output:

 my %callbacks = (
     test =&gt; sub {
         my $test = shift;
         if ( $test-&gt;is_ok &amp;&amp; not $test-&gt;directive ) {
             # normal passing test
             print color 'green';
         }
         elsif ( !$test-&gt;is_ok ) {    # even if it's TODO
             print color 'white on_red';
         }
         elsif ( $test-&gt;has_skip ) {
             print color 'white on_blue';

         }
         elsif ( $test-&gt;has_todo ) {
             print color 'white';
         }
     },
     ELSE =&gt; sub {
         # plan, comment, and so on (anything which isn't a test line)
         print color 'black on_white';
     },
     ALL =&gt; sub {
         # now print them
         print shift-&gt;as_string;
         print color 'reset';
         print "\n";
     },
 );

=item * C&lt;EOF&gt;

Invoked when there are no more lines to be parsed. Since there is no
accompanying L&lt;TAP::Parser::Result&gt; object the C&lt;TAP::Parser&gt; object is
passed instead.

=back

=head1 TAP GRAMMAR

If you're looking for an EBNF grammar, see L&lt;TAP::Parser::Grammar&gt;.

=head1 BACKWARDS COMPATIBILITY

The Perl-QA list attempted to ensure backwards compatibility with
L&lt;Test::Harness&gt;.  However, there are some minor differences.

=head2 Differences

=over 4

=item * TODO plans

A little-known feature of L&lt;Test::Harness&gt; is that it supported TODO
lists in the plan:

 1..2 todo 2
 ok 1 - We have liftoff
 not ok 2 - Anti-gravity device activated

Under L&lt;Test::Harness&gt;, test number 2 would I&lt;pass&gt; because it was
listed as a TODO test on the plan line. However, we are not aware of
anyone actually using this feature and hard-coding test numbers is
discouraged because it's very easy to add a test and break the test
number sequence. This makes test suites very fragile. Instead, the
following should be used:

 1..2
 ok 1 - We have liftoff
 not ok 2 - Anti-gravity device activated # TODO

=item * 'Missing' tests

It rarely happens, but sometimes a harness might encounter
'missing tests:

 ok 1
 ok 2
 ok 15
 ok 16
 ok 17

L&lt;Test::Harness&gt; would report tests 3-14 as having failed. For the
C&lt;TAP::Parser&gt;, these tests are not considered failed because they've
never run. They're reported as parse failures (tests out of sequence).

=back

=head1 SUBCLASSING

If you find you need to provide custom functionality (as you would have using
L&lt;Test::Harness::Straps&gt;), you're in luck: C&lt;TAP::Parser&gt; and friends are
designed to be easily plugged-into and/or subclassed.

Before you start, it's important to know a few things:

=over 2

=item 1

All C&lt;TAP::*&gt; objects inherit from L&lt;TAP::Object&gt;.

=item 2

Many C&lt;TAP::*&gt; classes have a I&lt;SUBCLASSING&gt; section to guide you.

=item 3

Note that C&lt;TAP::Parser&gt; is designed to be the central "maker" - ie: it is
responsible for creating most new objects in the C&lt;TAP::Parser::*&gt; namespace.

This makes it possible for you to have a single point of configuring what
subclasses should be used, which means that in many cases you'll find
you only need to sub-class one of the parser's components.

The exception to this rule are I&lt;SourceHandlers&gt; &amp; I&lt;Iterators&gt;, but those are
both created with customizable I&lt;IteratorFactory&gt;.

=item 4

By subclassing, you may end up overriding undocumented methods.  That's not
a bad thing per se, but be forewarned that undocumented methods may change
without warning from one release to the next - we cannot guarantee backwards
compatibility.  If any I&lt;documented&gt; method needs changing, it will be
deprecated first, and changed in a later release.

=back

=head2 Parser Components

=head3 Sources

A TAP parser consumes input from a single I&lt;raw source&gt; of TAP, which could come
from anywhere (a file, an executable, a database, an IO handle, a URI, etc..).
The source gets bundled up in a L&lt;TAP::Parser::Source&gt; object which gathers some
meta data about it.  The parser then uses a L&lt;TAP::Parser::IteratorFactory&gt; to
determine which L&lt;TAP::Parser::SourceHandler&gt; to use to turn the raw source
into a stream of TAP by way of L&lt;/Iterators&gt;.

If you simply want C&lt;TAP::Parser&gt; to handle a new source of TAP you probably
don't need to subclass C&lt;TAP::Parser&gt; itself.  Rather, you'll need to create a
new L&lt;TAP::Parser::SourceHandler&gt; class, and just plug it into the parser using
the I&lt;sources&gt; param to L&lt;/new&gt;.  Before you start writing one, read through
L&lt;TAP::Parser::IteratorFactory&gt; to get a feel for how the system works first.

If you find you really need to use your own iterator factory you can still do
so without sub-classing C&lt;TAP::Parser&gt; by setting L&lt;/iterator_factory_class&gt;.

If you just need to customize the objects on creation, subclass L&lt;TAP::Parser&gt;
and override L&lt;/make_iterator_factory&gt;.

Note that C&lt;make_source&gt; &amp; C&lt;make_perl_source&gt; have been I&lt;DEPRECATED&gt; and
are now removed.

=head3 Iterators

A TAP parser uses I&lt;iterators&gt; to loop through the I&lt;stream&gt; of TAP read in
from the I&lt;source&gt; it was given.  There are a few types of Iterators available
by default, all sub-classes of L&lt;TAP::Parser::Iterator&gt;.  Choosing which
iterator to use is the responsibility of the I&lt;iterator factory&gt;, though it
simply delegates to the I&lt;Source Handler&gt; it uses.

If you're writing your own L&lt;TAP::Parser::SourceHandler&gt;, you may need to
create your own iterators too.  If so you'll need to subclass
L&lt;TAP::Parser::Iterator&gt;.

Note that L&lt;/make_iterator&gt; has been I&lt;DEPRECATED&gt; and is now removed.

=head3 Results

A TAP parser creates L&lt;TAP::Parser::Result&gt;s as it iterates through the
input I&lt;stream&gt;.  There are quite a few result types available; choosing
which class to use is the responsibility of the I&lt;result factory&gt;.

To create your own result types you have two options:

=over 2

=item option 1

Subclass L&lt;TAP::Parser::Result&gt; and register your new result type/class with
the default L&lt;TAP::Parser::ResultFactory&gt;.

=item option 2

Subclass L&lt;TAP::Parser::ResultFactory&gt; itself and implement your own
L&lt;TAP::Parser::Result&gt; creation logic.  Then you'll need to customize the
class used by your parser by setting the C&lt;result_factory_class&gt; parameter.
See L&lt;/new&gt; for more details.

=back

If you need to customize the objects on creation, subclass L&lt;TAP::Parser&gt; and
override L&lt;/make_result&gt;.

=head3 Grammar

L&lt;TAP::Parser::Grammar&gt; is the heart of the parser.  It tokenizes the TAP
input I&lt;stream&gt; and produces results.  If you need to customize its behaviour
you should probably familiarize yourself with the source first.  Enough
lecturing.

Subclass L&lt;TAP::Parser::Grammar&gt; and customize your parser by setting the
C&lt;grammar_class&gt; parameter.  See L&lt;/new&gt; for more details.

If you need to customize the objects on creation, subclass L&lt;TAP::Parser&gt; and
override L&lt;/make_grammar&gt;

=head1 ACKNOWLEDGMENTS

All of the following have helped. Bug reports, patches, (im)moral
support, or just words of encouragement have all been forthcoming.

=over 4

=item * Michael Schwern

=item * Andy Lester

=item * chromatic

=item * GEOFFR

=item * Shlomi Fish

=item * Torsten Schoenfeld

=item * Jerry Gay

=item * Aristotle

=item * Adam Kennedy

=item * Yves Orton

=item * Adrian Howard

=item * Sean &amp; Lil

=item * Andreas J. Koenig

=item * Florian Ragwitz

=item * Corion

=item * Mark Stosberg

=item * Matt Kraai

=item * David Wheeler

=item * Alex Vandiver

=item * Cosimo Streppone

=item * Ville SkyttÃ¤

=back

=head1 AUTHORS

Curtis "Ovid" Poe &lt;ovid@cpan.org&gt;

Andy Armstong &lt;andy@hexten.net&gt;

Eric Wilhelm @ &lt;ewilhelm at cpan dot org&gt;

Michael Peters &lt;mpeters at plusthree dot com&gt;

Leif Eriksen &lt;leif dot eriksen at bigpond dot com&gt;

Steve Purkis &lt;spurkis@cpan.org&gt;

Nicholas Clark &lt;nick@ccl4.org&gt;

Lee Johnson &lt;notfadeaway at btinternet dot com&gt;

Philippe Bruhat &lt;book@cpan.org&gt;

=head1 BUGS

Please report any bugs or feature requests to
C&lt;bug-test-harness@rt.cpan.org&gt;, or through the web interface at
L&lt;http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Harness&gt;.
We will be notified, and then you'll automatically be notified of
progress on your bug as we make changes.

Obviously, bugs which include patches are best. If you prefer, you can
patch against bleed by via anonymous checkout of the latest version:

 git clone git://github.com/Perl-Toolchain-Gang/Test-Harness.git

=head1 COPYRIGHT &amp; LICENSE

Copyright 2006-2008 Curtis "Ovid" Poe, all rights reserved.

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

=cut

1;
</pre></body></html>