Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libtest-harness-perl / libtest-harness-perl-3.12 / lib / TAP / Parser.pm
1 package TAP::Parser;
2
3 use strict;
4 use vars qw($VERSION @ISA);
5
6 use TAP::Base                    ();
7 use TAP::Parser::Grammar         ();
8 use TAP::Parser::Result          ();
9 use TAP::Parser::ResultFactory   ();
10 use TAP::Parser::Source          ();
11 use TAP::Parser::Source::Perl    ();
12 use TAP::Parser::Iterator        ();
13 use TAP::Parser::IteratorFactory ();
14
15 use Carp qw( confess );
16
17 @ISA = qw(TAP::Base);
18
19 =head1 NAME
20
21 TAP::Parser - Parse L<TAP|Test::Harness::TAP> output
22
23 =head1 VERSION
24
25 Version 3.12
26
27 =cut
28
29 $VERSION = '3.12';
30
31 my $DEFAULT_TAP_VERSION = 12;
32 my $MAX_TAP_VERSION     = 13;
33
34 $ENV{TAP_VERSION} = $MAX_TAP_VERSION;
35
36 END {
37
38     # For VMS.
39     delete $ENV{TAP_VERSION};
40 }
41
42 BEGIN {    # making accessors
43     foreach my $method (
44         qw(
45         _stream
46         _spool
47         exec
48         exit
49         is_good_plan
50         plan
51         tests_planned
52         tests_run
53         wait
54         version
55         in_todo
56         start_time
57         end_time
58         skip_all
59         source_class
60         perl_source_class
61         grammar_class
62         iterator_factory_class
63         result_factory_class
64         )
65       )
66     {
67         no strict 'refs';
68         *$method = sub {
69             my $self = shift;
70             return $self->{$method} unless @_;
71             $self->{$method} = shift;
72         };
73     }
74 }    # done making accessors
75
76 =head1 SYNOPSIS
77
78     use TAP::Parser;
79
80     my $parser = TAP::Parser->new( { source => $source } );
81
82     while ( my $result = $parser->next ) {
83         print $result->as_string;
84     }
85
86 =head1 DESCRIPTION
87
88 C<TAP::Parser> is designed to produce a proper parse of TAP output. For
89 an example of how to run tests through this module, see the simple
90 harnesses C<examples/>.
91
92 There's a wiki dedicated to the Test Anything Protocol:
93
94 L<http://testanything.org>
95
96 It includes the TAP::Parser Cookbook:
97
98 L<http://testanything.org/wiki/index.php/TAP::Parser_Cookbook>
99
100 =head1 METHODS
101
102 =head2 Class Methods
103
104 =head3 C<new>
105
106  my $parser = TAP::Parser->new(\%args);
107
108 Returns a new C<TAP::Parser> object.
109
110 The arguments should be a hashref with I<one> of the following keys:
111
112 =over 4
113
114 =item * C<source>
115
116 This is the preferred method of passing arguments to the constructor.  To
117 determine how to handle the source, the following steps are taken.
118
119 If the source contains a newline, it's assumed to be a string of raw TAP
120 output.
121
122 If the source is a reference, it's assumed to be something to pass to
123 the L<TAP::Parser::Iterator::Stream> constructor. This is used
124 internally and you should not use it.
125
126 Otherwise, the parser does a C<-e> check to see if the source exists.  If so,
127 it attempts to execute the source and read the output as a stream.  This is by
128 far the preferred method of using the parser.
129
130  foreach my $file ( @test_files ) {
131      my $parser = TAP::Parser->new( { source => $file } );
132      # do stuff with the parser
133  }
134
135 =item * C<tap>
136
137 The value should be the complete TAP output.
138
139 =item * C<exec>
140
141 If passed an array reference, will attempt to create the iterator by
142 passing a L<TAP::Parser::Source> object to
143 L<TAP::Parser::Iterator::Source>, using the array reference strings as
144 the command arguments to L<IPC::Open3::open3|IPC::Open3>:
145
146  exec => [ '/usr/bin/ruby', 't/my_test.rb' ]
147
148 Note that C<source> and C<exec> are mutually exclusive.
149
150 =back
151
152 The following keys are optional.
153
154 =over 4
155
156 =item * C<callback>
157
158 If present, each callback corresponding to a given result type will be called
159 with the result as the argument if the C<run> method is used:
160
161  my %callbacks = (
162      test    => \&test_callback,
163      plan    => \&plan_callback,
164      comment => \&comment_callback,
165      bailout => \&bailout_callback,
166      unknown => \&unknown_callback,
167  );
168
169  my $aggregator = TAP::Parser::Aggregator->new;
170  foreach my $file ( @test_files ) {
171      my $parser = TAP::Parser->new(
172          {
173              source    => $file,
174              callbacks => \%callbacks,
175          }
176      );
177      $parser->run;
178      $aggregator->add( $file, $parser );
179  }
180
181 =item * C<switches>
182
183 If using a Perl file as a source, optional switches may be passed which will
184 be used when invoking the perl executable.
185
186  my $parser = TAP::Parser->new( {
187      source   => $test_file,
188      switches => '-Ilib',
189  } );
190
191 =item * C<test_args>
192
193 Used in conjunction with the C<source> option to supply a reference to
194 an C<@ARGV> style array of arguments to pass to the test program.
195
196 =item * C<spool>
197
198 If passed a filehandle will write a copy of all parsed TAP to that handle.
199
200 =item * C<merge>
201
202 If false, STDERR is not captured (though it is 'relayed' to keep it
203 somewhat synchronized with STDOUT.)
204
205 If true, STDERR and STDOUT are the same filehandle.  This may cause
206 breakage if STDERR contains anything resembling TAP format, but does
207 allow exact synchronization.
208
209 Subtleties of this behavior may be platform-dependent and may change in
210 the future.
211
212 =item * C<source_class>
213
214 This option was introduced to let you easily customize which I<source> class
215 the parser should use.  It defaults to L<TAP::Parser::Source>.
216
217 See also L</make_source>.
218
219 =item * C<perl_source_class>
220
221 This option was introduced to let you easily customize which I<perl source>
222 class the parser should use.  It defaults to L<TAP::Parser::Source::Perl>.
223
224 See also L</make_perl_source>.
225
226 =item * C<grammar_class>
227
228 This option was introduced to let you easily customize which I<grammar> class
229 the parser should use.  It defaults to L<TAP::Parser::Grammar>.
230
231 See also L</make_grammar>.
232
233 =item * C<iterator_factory_class>
234
235 This option was introduced to let you easily customize which I<iterator>
236 factory class the parser should use.  It defaults to
237 L<TAP::Parser::IteratorFactory>.
238
239 See also L</make_iterator>.
240
241 =item * C<result_factory_class>
242
243 This option was introduced to let you easily customize which I<result>
244 factory class the parser should use.  It defaults to
245 L<TAP::Parser::ResultFactory>.
246
247 See also L</make_result>.
248
249 =back
250
251 =cut
252
253 # new() implementation supplied by TAP::Base
254
255 # This should make overriding behaviour of the Parser in subclasses easier:
256 sub _default_source_class           {'TAP::Parser::Source'}
257 sub _default_perl_source_class      {'TAP::Parser::Source::Perl'}
258 sub _default_grammar_class          {'TAP::Parser::Grammar'}
259 sub _default_iterator_factory_class {'TAP::Parser::IteratorFactory'}
260 sub _default_result_factory_class   {'TAP::Parser::ResultFactory'}
261
262 ##############################################################################
263
264 =head2 Instance Methods
265
266 =head3 C<next>
267
268   my $parser = TAP::Parser->new( { source => $file } );
269   while ( my $result = $parser->next ) {
270       print $result->as_string, "\n";
271   }
272
273 This method returns the results of the parsing, one result at a time.  Note
274 that it is destructive.  You can't rewind and examine previous results.
275
276 If callbacks are used, they will be issued before this call returns.
277
278 Each result returned is a subclass of L<TAP::Parser::Result>.  See that
279 module and related classes for more information on how to use them.
280
281 =cut
282
283 sub next {
284     my $self = shift;
285     return ( $self->{_iter} ||= $self->_iter )->();
286 }
287
288 ##############################################################################
289
290 =head3 C<run>
291
292   $parser->run;
293
294 This method merely runs the parser and parses all of the TAP.
295
296 =cut
297
298 sub run {
299     my $self = shift;
300     while ( defined( my $result = $self->next ) ) {
301
302         # do nothing
303     }
304 }
305
306 ##############################################################################
307
308 =head3 C<make_source>
309
310 Make a new L<TAP::Parser::Source> object and return it.  Passes through any
311 arguments given.
312
313 The C<source_class> can be customized, as described in L</new>.
314
315 =head3 C<make_perl_source>
316
317 Make a new L<TAP::Parser::Source::Perl> object and return it.  Passes through
318 any arguments given.
319
320 The C<perl_source_class> can be customized, as described in L</new>.
321
322 =head3 C<make_grammar>
323
324 Make a new L<TAP::Parser::Grammar> object and return it.  Passes through any
325 arguments given.
326
327 The C<grammar_class> can be customized, as described in L</new>.
328
329 =head3 C<make_iterator>
330
331 Make a new L<TAP::Parser::Iterator> object using the parser's
332 L<TAP::Parser::IteratorFactory>, and return it.  Passes through any arguments
333 given.
334
335 The C<iterator_factory_class> can be customized, as described in L</new>.
336
337 =head3 C<make_result>
338
339 Make a new L<TAP::Parser::Result> object using the parser's
340 L<TAP::Parser::ResultFactory>, and return it.  Passes through any arguments
341 given.
342
343 The C<result_factory_class> can be customized, as described in L</new>.
344
345 =cut
346
347 # This should make overriding behaviour of the Parser in subclasses easier:
348 sub make_source      { shift->source_class->new(@_); }
349 sub make_perl_source { shift->perl_source_class->new(@_); }
350 sub make_grammar     { shift->grammar_class->new(@_); }
351 sub make_iterator    { shift->iterator_factory_class->make_iterator(@_); }
352 sub make_result      { shift->result_factory_class->make_result(@_); }
353
354 {
355
356     # of the following, anything beginning with an underscore is strictly
357     # internal and should not be exposed.
358     my %initialize = (
359         version       => $DEFAULT_TAP_VERSION,
360         plan          => '',                    # the test plan (e.g., 1..3)
361         tap           => '',                    # the TAP
362         tests_run     => 0,                     # actual current test numbers
363         results       => [],                    # TAP parser results
364         skipped       => [],                    #
365         todo          => [],                    #
366         passed        => [],                    #
367         failed        => [],                    #
368         actual_failed => [],                    # how many tests really failed
369         actual_passed => [],                    # how many tests really passed
370         todo_passed  => [],    # tests which unexpectedly succeed
371         parse_errors => [],    # perfect TAP should have none
372     );
373
374     # We seem to have this list hanging around all over the place. We could
375     # probably get it from somewhere else to avoid the repetition.
376     my @legal_callback = qw(
377       test
378       version
379       plan
380       comment
381       bailout
382       unknown
383       yaml
384       ALL
385       ELSE
386       EOF
387     );
388
389     my @class_overrides = qw(
390       source_class
391       perl_source_class
392       grammar_class
393       iterator_factory_class
394       result_factory_class
395     );
396
397     sub _initialize {
398         my ( $self, $arg_for ) = @_;
399
400         # everything here is basically designed to convert any TAP source to a
401         # stream.
402
403         # Shallow copy
404         my %args = %{ $arg_for || {} };
405
406         $self->SUPER::_initialize( \%args, \@legal_callback );
407
408         # get any class overrides out first:
409         for my $key (@class_overrides) {
410             my $default_method = "_default_$key";
411             my $val = delete $args{$key} || $self->$default_method();
412             $self->$key($val);
413         }
414
415         my $stream      = delete $args{stream};
416         my $tap         = delete $args{tap};
417         my $source      = delete $args{source};
418         my $exec        = delete $args{exec};
419         my $merge       = delete $args{merge};
420         my $spool       = delete $args{spool};
421         my $switches    = delete $args{switches};
422         my $ignore_exit = delete $args{ignore_exit};
423         my @test_args   = @{ delete $args{test_args} || [] };
424
425         if ( 1 < grep {defined} $stream, $tap, $source, $exec ) {
426             $self->_croak(
427                 "You may only choose one of 'exec', 'stream', 'tap' or 'source'"
428             );
429         }
430
431         if ( my @excess = sort keys %args ) {
432             $self->_croak("Unknown options: @excess");
433         }
434
435         if ($tap) {
436             $stream = $self->make_iterator( [ split "\n" => $tap ] );
437         }
438         elsif ($exec) {
439             my $source = $self->make_source( { parser => $self } );
440             $source->source( [ @$exec, @test_args ] );
441             $source->merge($merge);    # XXX should just be arguments?
442             $stream = $source->get_stream;
443         }
444         elsif ($source) {
445             if ( my $ref = ref $source ) {
446                 $stream = $self->make_iterator($source);
447             }
448             elsif ( -e $source ) {
449                 my $perl = $self->make_perl_source( { parser => $self } );
450
451                 $perl->switches($switches)
452                   if $switches;
453
454                 $perl->merge($merge);    # XXX args to new()?
455                 $perl->source( [ $source, @test_args ] );
456                 $stream = $perl->get_stream;
457             }
458             else {
459                 $self->_croak("Cannot determine source for $source");
460             }
461         }
462
463         unless ($stream) {
464             $self->_croak('PANIC: could not determine stream');
465         }
466
467         while ( my ( $k, $v ) = each %initialize ) {
468             $self->{$k} = 'ARRAY' eq ref $v ? [] : $v;
469         }
470
471         $self->_stream($stream);
472         $self->_spool($spool);
473         $self->ignore_exit($ignore_exit);
474
475         return $self;
476     }
477 }
478
479 =head1 INDIVIDUAL RESULTS
480
481 If you've read this far in the docs, you've seen this:
482
483     while ( my $result = $parser->next ) {
484         print $result->as_string;
485     }
486
487 Each result returned is a L<TAP::Parser::Result> subclass, referred to as
488 I<result types>.
489
490 =head2 Result types
491
492 Basically, you fetch individual results from the TAP.  The six types, with
493 examples of each, are as follows:
494
495 =over 4
496
497 =item * Version
498
499  TAP version 12
500
501 =item * Plan
502
503  1..42
504
505 =item * Pragma
506
507  pragma +strict
508
509 =item * Test
510
511  ok 3 - We should start with some foobar!
512
513 =item * Comment
514
515  # Hope we don't use up the foobar.
516
517 =item * Bailout
518
519  Bail out!  We ran out of foobar!
520
521 =item * Unknown
522
523  ... yo, this ain't TAP! ...
524
525 =back
526
527 Each result fetched is a result object of a different type.  There are common
528 methods to each result object and different types may have methods unique to
529 their type.  Sometimes a type method may be overridden in a subclass, but its
530 use is guaranteed to be identical.
531
532 =head2 Common type methods
533
534 =head3 C<type>
535
536 Returns the type of result, such as C<comment> or C<test>.
537
538 =head3 C<as_string>
539
540 Prints a string representation of the token.  This might not be the exact
541 output, however.  Tests will have test numbers added if not present, TODO and
542 SKIP directives will be capitalized and, in general, things will be cleaned
543 up.  If you need the original text for the token, see the C<raw> method.
544
545 =head3  C<raw>
546
547 Returns the original line of text which was parsed.
548
549 =head3 C<is_plan>
550
551 Indicates whether or not this is the test plan line.
552
553 =head3 C<is_test>
554
555 Indicates whether or not this is a test line.
556
557 =head3 C<is_comment>
558
559 Indicates whether or not this is a comment. Comments will generally only
560 appear in the TAP stream if STDERR is merged to STDOUT. See the
561 C<merge> option.
562
563 =head3 C<is_bailout>
564
565 Indicates whether or not this is bailout line.
566
567 =head3 C<is_yaml>
568
569 Indicates whether or not the current item is a YAML block.
570
571 =head3 C<is_unknown>
572
573 Indicates whether or not the current line could be parsed.
574
575 =head3 C<is_ok>
576
577   if ( $result->is_ok ) { ... }
578
579 Reports whether or not a given result has passed.  Anything which is B<not> a
580 test result returns true.  This is merely provided as a convenient shortcut
581 which allows you to do this:
582
583  my $parser = TAP::Parser->new( { source => $source } );
584  while ( my $result = $parser->next ) {
585      # only print failing results
586      print $result->as_string unless $result->is_ok;
587  }
588
589 =head2 C<plan> methods
590
591  if ( $result->is_plan ) { ... }
592
593 If the above evaluates as true, the following methods will be available on the
594 C<$result> object.
595
596 =head3 C<plan>
597
598   if ( $result->is_plan ) {
599      print $result->plan;
600   }
601
602 This is merely a synonym for C<as_string>.
603
604 =head3 C<directive>
605
606  my $directive = $result->directive;
607
608 If a SKIP directive is included with the plan, this method will return it.
609
610  1..0 # SKIP: why bother?
611
612 =head3 C<explanation>
613
614  my $explanation = $result->explanation;
615
616 If a SKIP directive was included with the plan, this method will return the
617 explanation, if any.
618
619 =head2 C<pragma> methods
620
621  if ( $result->is_pragma ) { ... }
622
623 If the above evaluates as true, the following methods will be available on the
624 C<$result> object.
625
626 =head3 C<pragmas>
627
628 Returns a list of pragmas each of which is a + or - followed by the
629 pragma name.
630  
631 =head2 C<commment> methods
632
633  if ( $result->is_comment ) { ... }
634
635 If the above evaluates as true, the following methods will be available on the
636 C<$result> object.
637
638 =head3 C<comment>
639
640   if ( $result->is_comment ) {
641       my $comment = $result->comment;
642       print "I have something to say:  $comment";
643   }
644
645 =head2 C<bailout> methods
646
647  if ( $result->is_bailout ) { ... }
648
649 If the above evaluates as true, the following methods will be available on the
650 C<$result> object.
651
652 =head3 C<explanation>
653
654   if ( $result->is_bailout ) {
655       my $explanation = $result->explanation;
656       print "We bailed out because ($explanation)";
657   }
658
659 If, and only if, a token is a bailout token, you can get an "explanation" via
660 this method.  The explanation is the text after the mystical "Bail out!" words
661 which appear in the tap output.
662
663 =head2 C<unknown> methods
664
665  if ( $result->is_unknown ) { ... }
666
667 There are no unique methods for unknown results.
668
669 =head2 C<test> methods
670
671  if ( $result->is_test ) { ... }
672
673 If the above evaluates as true, the following methods will be available on the
674 C<$result> object.
675
676 =head3 C<ok>
677
678   my $ok = $result->ok;
679
680 Returns the literal text of the C<ok> or C<not ok> status.
681
682 =head3 C<number>
683
684   my $test_number = $result->number;
685
686 Returns the number of the test, even if the original TAP output did not supply
687 that number.
688
689 =head3 C<description>
690
691   my $description = $result->description;
692
693 Returns the description of the test, if any.  This is the portion after the
694 test number but before the directive.
695
696 =head3 C<directive>
697
698   my $directive = $result->directive;
699
700 Returns either C<TODO> or C<SKIP> if either directive was present for a test
701 line.
702
703 =head3 C<explanation>
704
705   my $explanation = $result->explanation;
706
707 If a test had either a C<TODO> or C<SKIP> directive, this method will return
708 the accompanying explantion, if present.
709
710   not ok 17 - 'Pigs can fly' # TODO not enough acid
711
712 For the above line, the explanation is I<not enough acid>.
713
714 =head3 C<is_ok>
715
716   if ( $result->is_ok ) { ... }
717
718 Returns a boolean value indicating whether or not the test passed.  Remember
719 that for TODO tests, the test always passes.
720
721 B<Note:>  this was formerly C<passed>.  The latter method is deprecated and
722 will issue a warning.
723
724 =head3 C<is_actual_ok>
725
726   if ( $result->is_actual_ok ) { ... }
727
728 Returns a boolean value indicating whether or not the test passed, regardless
729 of its TODO status.
730
731 B<Note:>  this was formerly C<actual_passed>.  The latter method is deprecated
732 and will issue a warning.
733
734 =head3 C<is_unplanned>
735
736   if ( $test->is_unplanned ) { ... }
737
738 If a test number is greater than the number of planned tests, this method will
739 return true.  Unplanned tests will I<always> return false for C<is_ok>,
740 regardless of whether or not the test C<has_todo> (see
741 L<TAP::Parser::Result::Test> for more information about this).
742
743 =head3 C<has_skip>
744
745   if ( $result->has_skip ) { ... }
746
747 Returns a boolean value indicating whether or not this test had a SKIP
748 directive.
749
750 =head3 C<has_todo>
751
752   if ( $result->has_todo ) { ... }
753
754 Returns a boolean value indicating whether or not this test had a TODO
755 directive.
756
757 Note that TODO tests I<always> pass.  If you need to know whether or not
758 they really passed, check the C<is_actual_ok> method.
759
760 =head3 C<in_todo>
761
762   if ( $parser->in_todo ) { ... }
763
764 True while the most recent result was a TODO. Becomes true before the
765 TODO result is returned and stays true until just before the next non-
766 TODO test is returned.
767
768 =head1 TOTAL RESULTS
769
770 After parsing the TAP, there are many methods available to let you dig through
771 the results and determine what is meaningful to you.
772
773 =head2 Individual Results
774
775 These results refer to individual tests which are run.
776
777 =head3 C<passed>
778
779  my @passed = $parser->passed; # the test numbers which passed
780  my $passed = $parser->passed; # the number of tests which passed
781
782 This method lets you know which (or how many) tests passed.  If a test failed
783 but had a TODO directive, it will be counted as a passed test.
784
785 =cut
786
787 sub passed { @{ shift->{passed} } }
788
789 =head3 C<failed>
790
791  my @failed = $parser->failed; # the test numbers which failed
792  my $failed = $parser->failed; # the number of tests which failed
793
794 This method lets you know which (or how many) tests failed.  If a test passed
795 but had a TODO directive, it will B<NOT> be counted as a failed test.
796
797 =cut
798
799 sub failed { @{ shift->{failed} } }
800
801 =head3 C<actual_passed>
802
803  # the test numbers which actually passed
804  my @actual_passed = $parser->actual_passed;
805
806  # the number of tests which actually passed
807  my $actual_passed = $parser->actual_passed;
808
809 This method lets you know which (or how many) tests actually passed,
810 regardless of whether or not a TODO directive was found.
811
812 =cut
813
814 sub actual_passed { @{ shift->{actual_passed} } }
815 *actual_ok = \&actual_passed;
816
817 =head3 C<actual_ok>
818
819 This method is a synonym for C<actual_passed>.
820
821 =head3 C<actual_failed>
822
823  # the test numbers which actually failed
824  my @actual_failed = $parser->actual_failed;
825
826  # the number of tests which actually failed
827  my $actual_failed = $parser->actual_failed;
828
829 This method lets you know which (or how many) tests actually failed,
830 regardless of whether or not a TODO directive was found.
831
832 =cut
833
834 sub actual_failed { @{ shift->{actual_failed} } }
835
836 ##############################################################################
837
838 =head3 C<todo>
839
840  my @todo = $parser->todo; # the test numbers with todo directives
841  my $todo = $parser->todo; # the number of tests with todo directives
842
843 This method lets you know which (or how many) tests had TODO directives.
844
845 =cut
846
847 sub todo { @{ shift->{todo} } }
848
849 =head3 C<todo_passed>
850
851  # the test numbers which unexpectedly succeeded
852  my @todo_passed = $parser->todo_passed;
853
854  # the number of tests which unexpectedly succeeded
855  my $todo_passed = $parser->todo_passed;
856
857 This method lets you know which (or how many) tests actually passed but were
858 declared as "TODO" tests.
859
860 =cut
861
862 sub todo_passed { @{ shift->{todo_passed} } }
863
864 ##############################################################################
865
866 =head3 C<todo_failed>
867
868   # deprecated in favor of 'todo_passed'.  This method was horribly misnamed.
869
870 This was a badly misnamed method.  It indicates which TODO tests unexpectedly
871 succeeded.  Will now issue a warning and call C<todo_passed>.
872
873 =cut
874
875 sub todo_failed {
876     warn
877       '"todo_failed" is deprecated.  Please use "todo_passed".  See the docs.';
878     goto &todo_passed;
879 }
880
881 =head3 C<skipped>
882
883  my @skipped = $parser->skipped; # the test numbers with SKIP directives
884  my $skipped = $parser->skipped; # the number of tests with SKIP directives
885
886 This method lets you know which (or how many) tests had SKIP directives.
887
888 =cut
889
890 sub skipped { @{ shift->{skipped} } }
891
892 =head2 Pragmas
893
894 =head3 C<pragma>
895
896 Get or set a pragma. To get the state of a pragma:
897
898   if ( $p->pragma('strict') ) {
899       # be strict
900   }
901
902 To set the state of a pragma:
903
904   $p->pragma('strict', 1); # enable strict mode
905
906 =cut
907
908 sub pragma {
909     my ( $self, $pragma ) = splice @_, 0, 2;
910
911     return $self->{pragma}->{$pragma} unless @_;
912
913     if ( my $state = shift ) {
914         $self->{pragma}->{$pragma} = 1;
915     }
916     else {
917         delete $self->{pragma}->{$pragma};
918     }
919
920     return;
921 }
922
923 =head3 C<pragmas>
924
925 Get a list of all the currently enabled pragmas:
926
927   my @pragmas_enabled = $p->pragmas;
928
929 =cut
930
931 sub pragmas { sort keys %{ shift->{pragma} || {} } }
932
933 =head2 Summary Results
934
935 These results are "meta" information about the total results of an individual
936 test program.
937
938 =head3 C<plan>
939
940  my $plan = $parser->plan;
941
942 Returns the test plan, if found.
943
944 =head3 C<good_plan>
945
946 Deprecated.  Use C<is_good_plan> instead.
947
948 =cut
949
950 sub good_plan {
951     warn 'good_plan() is deprecated.  Please use "is_good_plan()"';
952     goto &is_good_plan;
953 }
954
955 ##############################################################################
956
957 =head3 C<is_good_plan>
958
959   if ( $parser->is_good_plan ) { ... }
960
961 Returns a boolean value indicating whether or not the number of tests planned
962 matches the number of tests run.
963
964 B<Note:>  this was formerly C<good_plan>.  The latter method is deprecated and
965 will issue a warning.
966
967 And since we're on that subject ...
968
969 =head3 C<tests_planned>
970
971   print $parser->tests_planned;
972
973 Returns the number of tests planned, according to the plan.  For example, a
974 plan of '1..17' will mean that 17 tests were planned.
975
976 =head3 C<tests_run>
977
978   print $parser->tests_run;
979
980 Returns the number of tests which actually were run.  Hopefully this will
981 match the number of C<< $parser->tests_planned >>.
982
983 =head3 C<skip_all>
984
985 Returns a true value (actually the reason for skipping) if all tests
986 were skipped.
987
988 =head3 C<start_time>
989
990 Returns the time when the Parser was created.
991
992 =head3 C<end_time>
993
994 Returns the time when the end of TAP input was seen.
995
996 =head3 C<has_problems>
997
998   if ( $parser->has_problems ) {
999       ...
1000   }
1001
1002 This is a 'catch-all' method which returns true if any tests have currently
1003 failed, any TODO tests unexpectedly succeeded, or any parse errors occurred.
1004
1005 =cut
1006
1007 sub has_problems {
1008     my $self = shift;
1009     return
1010          $self->failed
1011       || $self->parse_errors
1012       || ( !$self->ignore_exit && ( $self->wait || $self->exit ) );
1013 }
1014
1015 =head3 C<version>
1016
1017   $parser->version;
1018
1019 Once the parser is done, this will return the version number for the
1020 parsed TAP. Version numbers were introduced with TAP version 13 so if no
1021 version number is found version 12 is assumed.
1022
1023 =head3 C<exit>
1024
1025   $parser->exit;
1026
1027 Once the parser is done, this will return the exit status.  If the parser ran
1028 an executable, it returns the exit status of the executable.
1029
1030 =head3 C<wait>
1031
1032   $parser->wait;
1033
1034 Once the parser is done, this will return the wait status.  If the parser ran
1035 an executable, it returns the wait status of the executable.  Otherwise, this
1036 mererely returns the C<exit> status.
1037
1038 =head2 C<ignore_exit>
1039
1040   $parser->ignore_exit(1);
1041
1042 Tell the parser to ignore the exit status from the test when determining
1043 whether the test passed. Normally tests with non-zero exit status are
1044 considered to have failed even if all individual tests passed. In cases
1045 where it is not possible to control the exit value of the test script
1046 use this option to ignore it.
1047
1048 =cut
1049
1050 sub ignore_exit { shift->pragma( 'ignore_exit', @_ ) }
1051
1052 =head3 C<parse_errors>
1053
1054  my @errors = $parser->parse_errors; # the parser errors
1055  my $errors = $parser->parse_errors; # the number of parser_errors
1056
1057 Fortunately, all TAP output is perfect.  In the event that it is not, this
1058 method will return parser errors.  Note that a junk line which the parser does
1059 not recognize is C<not> an error.  This allows this parser to handle future
1060 versions of TAP.  The following are all TAP errors reported by the parser:
1061
1062 =over 4
1063
1064 =item * Misplaced plan
1065
1066 The plan (for example, '1..5'), must only come at the beginning or end of the
1067 TAP output.
1068
1069 =item * No plan
1070
1071 Gotta have a plan!
1072
1073 =item * More than one plan
1074
1075  1..3
1076  ok 1 - input file opened
1077  not ok 2 - first line of the input valid # todo some data
1078  ok 3 read the rest of the file
1079  1..3
1080
1081 Right.  Very funny.  Don't do that.
1082
1083 =item * Test numbers out of sequence
1084
1085  1..3
1086  ok 1 - input file opened
1087  not ok 2 - first line of the input valid # todo some data
1088  ok 2 read the rest of the file
1089
1090 That last test line above should have the number '3' instead of '2'.
1091
1092 Note that it's perfectly acceptable for some lines to have test numbers and
1093 others to not have them.  However, when a test number is found, it must be in
1094 sequence.  The following is also an error:
1095
1096  1..3
1097  ok 1 - input file opened
1098  not ok - first line of the input valid # todo some data
1099  ok 2 read the rest of the file
1100
1101 But this is not:
1102
1103  1..3
1104  ok  - input file opened
1105  not ok - first line of the input valid # todo some data
1106  ok 3 read the rest of the file
1107
1108 =back
1109
1110 =cut
1111
1112 sub parse_errors { @{ shift->{parse_errors} } }
1113
1114 sub _add_error {
1115     my ( $self, $error ) = @_;
1116     push @{ $self->{parse_errors} } => $error;
1117     return $self;
1118 }
1119
1120 sub _make_state_table {
1121     my $self = shift;
1122     my %states;
1123     my %planned_todo = ();
1124
1125     # These transitions are defaults for all states
1126     my %state_globals = (
1127         comment => {},
1128         bailout => {},
1129         yaml    => {},
1130         version => {
1131             act => sub {
1132                 $self->_add_error(
1133                     'If TAP version is present it must be the first line of output'
1134                 );
1135             },
1136         },
1137         unknown => {
1138             act => sub {
1139                 my $unk = shift;
1140                 if ( $self->pragma('strict') ) {
1141                     $self->_add_error(
1142                         'Unknown TAP token: "' . $unk->raw . '"' );
1143                 }
1144             },
1145         },
1146         pragma => {
1147             act => sub {
1148                 my ($pragma) = @_;
1149                 for my $pr ( $pragma->pragmas ) {
1150                     if ( $pr =~ /^ ([-+])(\w+) $/x ) {
1151                         $self->pragma( $2, $1 eq '+' );
1152                     }
1153                 }
1154             },
1155         },
1156     );
1157
1158     # Provides default elements for transitions
1159     my %state_defaults = (
1160         plan => {
1161             act => sub {
1162                 my ($plan) = @_;
1163                 $self->tests_planned( $plan->tests_planned );
1164                 $self->plan( $plan->plan );
1165                 if ( $plan->has_skip ) {
1166                     $self->skip_all( $plan->explanation
1167                           || '(no reason given)' );
1168                 }
1169
1170                 $planned_todo{$_}++ for @{ $plan->todo_list };
1171             },
1172         },
1173         test => {
1174             act => sub {
1175                 my ($test) = @_;
1176
1177                 my ( $number, $tests_run )
1178                   = ( $test->number, ++$self->{tests_run} );
1179
1180                 # Fake TODO state
1181                 if ( defined $number && delete $planned_todo{$number} ) {
1182                     $test->set_directive('TODO');
1183                 }
1184
1185                 my $has_todo = $test->has_todo;
1186
1187                 $self->in_todo($has_todo);
1188                 if ( defined( my $tests_planned = $self->tests_planned ) ) {
1189                     if ( $tests_run > $tests_planned ) {
1190                         $test->is_unplanned(1);
1191                     }
1192                 }
1193
1194                 if ($number) {
1195                     if ( $number != $tests_run ) {
1196                         my $count = $tests_run;
1197                         $self->_add_error( "Tests out of sequence.  Found "
1198                               . "($number) but expected ($count)" );
1199                     }
1200                 }
1201                 else {
1202                     $test->_number( $number = $tests_run );
1203                 }
1204
1205                 push @{ $self->{todo} } => $number if $has_todo;
1206                 push @{ $self->{todo_passed} } => $number
1207                   if $test->todo_passed;
1208                 push @{ $self->{skipped} } => $number
1209                   if $test->has_skip;
1210
1211                 push @{ $self->{ $test->is_ok ? 'passed' : 'failed' } } =>
1212                   $number;
1213                 push @{
1214                     $self->{
1215                         $test->is_actual_ok
1216                         ? 'actual_passed'
1217                         : 'actual_failed'
1218                       }
1219                   } => $number;
1220             },
1221         },
1222         yaml => { act => sub { }, },
1223     );
1224
1225     # Each state contains a hash the keys of which match a token type. For
1226     # each token
1227     # type there may be:
1228     #   act      A coderef to run
1229     #   goto     The new state to move to. Stay in this state if
1230     #            missing
1231     #   continue Goto the new state and run the new state for the
1232     #            current token
1233     %states = (
1234         INIT => {
1235             version => {
1236                 act => sub {
1237                     my ($version) = @_;
1238                     my $ver_num = $version->version;
1239                     if ( $ver_num <= $DEFAULT_TAP_VERSION ) {
1240                         my $ver_min = $DEFAULT_TAP_VERSION + 1;
1241                         $self->_add_error(
1242                                 "Explicit TAP version must be at least "
1243                               . "$ver_min. Got version $ver_num" );
1244                         $ver_num = $DEFAULT_TAP_VERSION;
1245                     }
1246                     if ( $ver_num > $MAX_TAP_VERSION ) {
1247                         $self->_add_error(
1248                                 "TAP specified version $ver_num but "
1249                               . "we don't know about versions later "
1250                               . "than $MAX_TAP_VERSION" );
1251                         $ver_num = $MAX_TAP_VERSION;
1252                     }
1253                     $self->version($ver_num);
1254                     $self->_grammar->set_version($ver_num);
1255                 },
1256                 goto => 'PLAN'
1257             },
1258             plan => { goto => 'PLANNED' },
1259             test => { goto => 'UNPLANNED' },
1260         },
1261         PLAN => {
1262             plan => { goto => 'PLANNED' },
1263             test => { goto => 'UNPLANNED' },
1264         },
1265         PLANNED => {
1266             test => { goto => 'PLANNED_AFTER_TEST' },
1267             plan => {
1268                 act => sub {
1269                     my ($version) = @_;
1270                     $self->_add_error(
1271                         'More than one plan found in TAP output');
1272                 },
1273             },
1274         },
1275         PLANNED_AFTER_TEST => {
1276             test => { goto => 'PLANNED_AFTER_TEST' },
1277             plan => { act  => sub { }, continue => 'PLANNED' },
1278             yaml => { goto => 'PLANNED' },
1279         },
1280         GOT_PLAN => {
1281             test => {
1282                 act => sub {
1283                     my ($plan) = @_;
1284                     my $line = $self->plan;
1285                     $self->_add_error(
1286                             "Plan ($line) must be at the beginning "
1287                           . "or end of the TAP output" );
1288                     $self->is_good_plan(0);
1289                 },
1290                 continue => 'PLANNED'
1291             },
1292             plan => { continue => 'PLANNED' },
1293         },
1294         UNPLANNED => {
1295             test => { goto => 'UNPLANNED_AFTER_TEST' },
1296             plan => { goto => 'GOT_PLAN' },
1297         },
1298         UNPLANNED_AFTER_TEST => {
1299             test => { act  => sub { }, continue => 'UNPLANNED' },
1300             plan => { act  => sub { }, continue => 'UNPLANNED' },
1301             yaml => { goto => 'PLANNED' },
1302         },
1303     );
1304
1305     # Apply globals and defaults to state table
1306     for my $name ( keys %states ) {
1307
1308         # Merge with globals
1309         my $st = { %state_globals, %{ $states{$name} } };
1310
1311         # Add defaults
1312         for my $next ( sort keys %{$st} ) {
1313             if ( my $default = $state_defaults{$next} ) {
1314                 for my $def ( sort keys %{$default} ) {
1315                     $st->{$next}->{$def} ||= $default->{$def};
1316                 }
1317             }
1318         }
1319
1320         # Stuff back in table
1321         $states{$name} = $st;
1322     }
1323
1324     return \%states;
1325 }
1326
1327 =head3 C<get_select_handles>
1328
1329 Get an a list of file handles which can be passed to C<select> to
1330 determine the readiness of this parser.
1331
1332 =cut
1333
1334 sub get_select_handles { shift->_stream->get_select_handles }
1335
1336 sub _grammar {
1337     my $self = shift;
1338     return $self->{_grammar} = shift if @_;
1339
1340     return $self->{_grammar} ||= $self->make_grammar(
1341         {   stream  => $self->_stream,
1342             parser  => $self,
1343             version => $self->version
1344         }
1345     );
1346 }
1347
1348 sub _iter {
1349     my $self        = shift;
1350     my $stream      = $self->_stream;
1351     my $grammar     = $self->_grammar;
1352     my $spool       = $self->_spool;
1353     my $state       = 'INIT';
1354     my $state_table = $self->_make_state_table;
1355
1356     $self->start_time( $self->get_time );
1357
1358     # Make next_state closure
1359     my $next_state = sub {
1360         my $token = shift;
1361         my $type  = $token->type;
1362         TRANS: {
1363             my $state_spec = $state_table->{$state}
1364               or die "Illegal state: $state";
1365
1366             if ( my $next = $state_spec->{$type} ) {
1367                 if ( my $act = $next->{act} ) {
1368                     $act->($token);
1369                 }
1370                 if ( my $cont = $next->{continue} ) {
1371                     $state = $cont;
1372                     redo TRANS;
1373                 }
1374                 elsif ( my $goto = $next->{goto} ) {
1375                     $state = $goto;
1376                 }
1377             }
1378             else {
1379                 confess("Unhandled token type: $type\n");
1380             }
1381         }
1382         return $token;
1383     };
1384
1385     # Handle end of stream - which means either pop a block or finish
1386     my $end_handler = sub {
1387         $self->exit( $stream->exit );
1388         $self->wait( $stream->wait );
1389         $self->_finish;
1390         return;
1391     };
1392
1393     # Finally make the closure that we return. For performance reasons
1394     # there are two versions of the returned function: one that handles
1395     # callbacks and one that does not.
1396     if ( $self->_has_callbacks ) {
1397         return sub {
1398             my $result = eval { $grammar->tokenize };
1399             $self->_add_error($@) if $@;
1400
1401             if ( defined $result ) {
1402                 $result = $next_state->($result);
1403
1404                 if ( my $code = $self->_callback_for( $result->type ) ) {
1405                     $_->($result) for @{$code};
1406                 }
1407                 else {
1408                     $self->_make_callback( 'ELSE', $result );
1409                 }
1410
1411                 $self->_make_callback( 'ALL', $result );
1412
1413                 # Echo TAP to spool file
1414                 print {$spool} $result->raw, "\n" if $spool;
1415             }
1416             else {
1417                 $result = $end_handler->();
1418                 $self->_make_callback( 'EOF', $result )
1419                   unless defined $result;
1420             }
1421
1422             return $result;
1423         };
1424     }    # _has_callbacks
1425     else {
1426         return sub {
1427             my $result = eval { $grammar->tokenize };
1428             $self->_add_error($@) if $@;
1429
1430             if ( defined $result ) {
1431                 $result = $next_state->($result);
1432
1433                 # Echo TAP to spool file
1434                 print {$spool} $result->raw, "\n" if $spool;
1435             }
1436             else {
1437                 $result = $end_handler->();
1438             }
1439
1440             return $result;
1441         };
1442     }    # no callbacks
1443 }
1444
1445 sub _finish {
1446     my $self = shift;
1447
1448     $self->end_time( $self->get_time );
1449
1450     # sanity checks
1451     if ( !$self->plan ) {
1452         $self->_add_error('No plan found in TAP output');
1453     }
1454     else {
1455         $self->is_good_plan(1) unless defined $self->is_good_plan;
1456     }
1457     if ( $self->tests_run != ( $self->tests_planned || 0 ) ) {
1458         $self->is_good_plan(0);
1459         if ( defined( my $planned = $self->tests_planned ) ) {
1460             my $ran = $self->tests_run;
1461             $self->_add_error(
1462                 "Bad plan.  You planned $planned tests but ran $ran.");
1463         }
1464     }
1465     if ( $self->tests_run != ( $self->passed + $self->failed ) ) {
1466
1467         # this should never happen
1468         my $actual = $self->tests_run;
1469         my $passed = $self->passed;
1470         my $failed = $self->failed;
1471         $self->_croak( "Panic: planned test count ($actual) did not equal "
1472               . "sum of passed ($passed) and failed ($failed) tests!" );
1473     }
1474
1475     $self->is_good_plan(0) unless defined $self->is_good_plan;
1476     return $self;
1477 }
1478
1479 =head3 C<delete_spool>
1480
1481 Delete and return the spool.
1482
1483   my $fh = $parser->delete_spool;
1484
1485 =cut
1486
1487 sub delete_spool {
1488     my $self = shift;
1489
1490     return delete $self->{_spool};
1491 }
1492
1493 ##############################################################################
1494
1495 =head1 CALLBACKS
1496
1497 As mentioned earlier, a "callback" key may be added to the
1498 C<TAP::Parser> constructor. If present, each callback corresponding to a
1499 given result type will be called with the result as the argument if the
1500 C<run> method is used. The callback is expected to be a subroutine
1501 reference (or anonymous subroutine) which is invoked with the parser
1502 result as its argument.
1503
1504  my %callbacks = (
1505      test    => \&test_callback,
1506      plan    => \&plan_callback,
1507      comment => \&comment_callback,
1508      bailout => \&bailout_callback,
1509      unknown => \&unknown_callback,
1510  );
1511
1512  my $aggregator = TAP::Parser::Aggregator->new;
1513  foreach my $file ( @test_files ) {
1514      my $parser = TAP::Parser->new(
1515          {
1516              source    => $file,
1517              callbacks => \%callbacks,
1518          }
1519      );
1520      $parser->run;
1521      $aggregator->add( $file, $parser );
1522  }
1523
1524 Callbacks may also be added like this:
1525
1526  $parser->callback( test => \&test_callback );
1527  $parser->callback( plan => \&plan_callback );
1528
1529 The following keys allowed for callbacks. These keys are case-sensitive.
1530
1531 =over 4
1532
1533 =item * C<test>
1534
1535 Invoked if C<< $result->is_test >> returns true.
1536
1537 =item * C<version>
1538
1539 Invoked if C<< $result->is_version >> returns true.
1540
1541 =item * C<plan>
1542
1543 Invoked if C<< $result->is_plan >> returns true.
1544
1545 =item * C<comment>
1546
1547 Invoked if C<< $result->is_comment >> returns true.
1548
1549 =item * C<bailout>
1550
1551 Invoked if C<< $result->is_unknown >> returns true.
1552
1553 =item * C<yaml>
1554
1555 Invoked if C<< $result->is_yaml >> returns true.
1556
1557 =item * C<unknown>
1558
1559 Invoked if C<< $result->is_unknown >> returns true.
1560
1561 =item * C<ELSE>
1562
1563 If a result does not have a callback defined for it, this callback will
1564 be invoked. Thus, if all of the previous result types are specified as
1565 callbacks, this callback will I<never> be invoked.
1566
1567 =item * C<ALL>
1568
1569 This callback will always be invoked and this will happen for each
1570 result after one of the above callbacks is invoked.  For example, if
1571 L<Term::ANSIColor> is loaded, you could use the following to color your
1572 test output:
1573
1574  my %callbacks = (
1575      test => sub {
1576          my $test = shift;
1577          if ( $test->is_ok && not $test->directive ) {
1578              # normal passing test
1579              print color 'green';
1580          }
1581          elsif ( !$test->is_ok ) {    # even if it's TODO
1582              print color 'white on_red';
1583          }
1584          elsif ( $test->has_skip ) {
1585              print color 'white on_blue';
1586
1587          }
1588          elsif ( $test->has_todo ) {
1589              print color 'white';
1590          }
1591      },
1592      ELSE => sub {
1593          # plan, comment, and so on (anything which isn't a test line)
1594          print color 'black on_white';
1595      },
1596      ALL => sub {
1597          # now print them
1598          print shift->as_string;
1599          print color 'reset';
1600          print "\n";
1601      },
1602  );
1603
1604 =item * C<EOF>
1605
1606 Invoked when there are no more lines to be parsed. Since there is no
1607 accompanying L<TAP::Parser::Result> object the C<TAP::Parser> object is
1608 passed instead.
1609
1610 =back
1611
1612 =head1 TAP GRAMMAR
1613
1614 If you're looking for an EBNF grammar, see L<TAP::Parser::Grammar>.
1615
1616 =head1 BACKWARDS COMPATABILITY
1617
1618 The Perl-QA list attempted to ensure backwards compatability with
1619 L<Test::Harness>.  However, there are some minor differences.
1620
1621 =head2 Differences
1622
1623 =over 4
1624
1625 =item * TODO plans
1626
1627 A little-known feature of L<Test::Harness> is that it supported TODO
1628 lists in the plan:
1629
1630  1..2 todo 2
1631  ok 1 - We have liftoff
1632  not ok 2 - Anti-gravity device activated
1633
1634 Under L<Test::Harness>, test number 2 would I<pass> because it was
1635 listed as a TODO test on the plan line. However, we are not aware of
1636 anyone actually using this feature and hard-coding test numbers is
1637 discouraged because it's very easy to add a test and break the test
1638 number sequence. This makes test suites very fragile. Instead, the
1639 following should be used:
1640
1641  1..2
1642  ok 1 - We have liftoff
1643  not ok 2 - Anti-gravity device activated # TODO
1644
1645 =item * 'Missing' tests
1646
1647 It rarely happens, but sometimes a harness might encounter
1648 'missing tests:
1649
1650  ok 1
1651  ok 2
1652  ok 15
1653  ok 16
1654  ok 17
1655
1656 L<Test::Harness> would report tests 3-14 as having failed. For the
1657 C<TAP::Parser>, these tests are not considered failed because they've
1658 never run. They're reported as parse failures (tests out of sequence).
1659
1660 =back
1661
1662 =head1 SUBCLASSING
1663
1664 If you find you need to provide custom functionality (as you would have using
1665 L<Test::Harness::Straps>), you're in luck: C<TAP::Parser> and friends are
1666 designed to be easily subclassed.
1667
1668 Before you start, it's important to know a few things:
1669
1670 =over 2
1671
1672 =item 1
1673
1674 All C<TAP::*> objects inherit from L<TAP::Object>.
1675
1676 =item 2
1677
1678 Most C<TAP::*> classes have a I<SUBCLASSING> section to guide you.
1679
1680 =item 3
1681
1682 Note that C<TAP::Parser> is designed to be the central 'maker' - ie: it is
1683 responsible for creating new objects in the C<TAP::Parser::*> namespace.
1684
1685 This makes it possible for you to have a single point of configuring what
1686 subclasses should be used, which in turn means that in many cases you'll find
1687 you only need to sub-class one of the parser's components.
1688
1689 =item 4
1690
1691 By subclassing, you may end up overriding undocumented methods.  That's not
1692 a bad thing per se, but be forewarned that undocumented methods may change
1693 without warning from one release to the next - we cannot guarantee backwards
1694 compatability.  If any I<documented> method needs changing, it will be
1695 deprecated first, and changed in a later release.
1696
1697 =back
1698
1699 =head2 Parser Components
1700
1701 =head3 Sources
1702
1703 A TAP parser consumes input from a I<source>.  There are currently two types
1704 of sources: L<TAP::Parser::Source> for general non-perl commands, and
1705 L<TAP::Parser::Source::Perl>.  You can subclass both of them.  You'll need to
1706 customize your parser by setting the C<source_class> & C<perl_source_class>
1707 parameters.  See L</new> for more details.
1708
1709 If you need to customize the objects on creation, subclass L<TAP::Parser> and
1710 override L</make_source> or L</make_perl_source>.
1711
1712 =head3 Iterators
1713
1714 A TAP parser uses I<iterators> to loop through the I<stream> provided by the
1715 parser's I<source>.  There are quite a few types of Iterators available.
1716 Choosing which class to use is the responsibility of the I<iterator factory>.
1717
1718 To create your own iterators you'll have to subclass
1719 L<TAP::Parser::IteratorFactory> and L<TAP::Parser::Iterator>.  Then you'll
1720 need to customize the class used by your parser by setting the
1721 C<iterator_factory_class> parameter.  See L</new> for more details.
1722
1723 If you need to customize the objects on creation, subclass L<TAP::Parser> and
1724 override L</make_iterator>.
1725
1726 =head3 Results
1727
1728 A TAP parser creates L<TAP::Parser::Result>s as it iterates through the
1729 input I<stream>.  There are quite a few result types available; choosing
1730 which class to use is the responsibility of the I<result factory>.
1731
1732 To create your own result types you have two options:
1733
1734 =over 2
1735
1736 =item option 1
1737
1738 Subclass L<TAP::Parser::Result> and register your new result type/class with
1739 the default L<TAP::Parser::ResultFactory>.
1740
1741 =item option 2
1742
1743 Subclass L<TAP::Parser::ResultFactory> itself and implement your own
1744 L<TAP::Parser::Result> creation logic.  Then you'll need to customize the
1745 class used by your parser by setting the C<result_factory_class> parameter.
1746 See L</new> for more details.
1747
1748 =back
1749
1750 If you need to customize the objects on creation, subclass L<TAP::Parser> and
1751 override L</make_result>.
1752
1753 =head3 Grammar
1754
1755 L<TAP::Parser::Grammar> is the heart of the parser - it tokenizes the TAP
1756 input I<stream> and produces results.  If you need to customize its behaviour
1757 you should probably familiarize yourself with the source first.  Enough
1758 lecturing.
1759
1760 Subclass L<TAP::Parser::Grammar> and customize your parser by setting the
1761 C<grammar_class> parameter.  See L</new> for more details.
1762
1763 If you need to customize the objects on creation, subclass L<TAP::Parser> and
1764 override L</make_grammar>
1765
1766 =head1 ACKNOWLEDGEMENTS
1767
1768 All of the following have helped. Bug reports, patches, (im)moral
1769 support, or just words of encouragement have all been forthcoming.
1770
1771 =over 4
1772
1773 =item * Michael Schwern
1774
1775 =item * Andy Lester
1776
1777 =item * chromatic
1778
1779 =item * GEOFFR
1780
1781 =item * Shlomi Fish
1782
1783 =item * Torsten Schoenfeld
1784
1785 =item * Jerry Gay
1786
1787 =item * Aristotle
1788
1789 =item * Adam Kennedy
1790
1791 =item * Yves Orton
1792
1793 =item * Adrian Howard
1794
1795 =item * Sean & Lil
1796
1797 =item * Andreas J. Koenig
1798
1799 =item * Florian Ragwitz
1800
1801 =item * Corion
1802
1803 =item * Mark Stosberg
1804
1805 =item * Matt Kraai
1806
1807 =item * David Wheeler
1808
1809 =back
1810
1811 =head1 AUTHORS
1812
1813 Curtis "Ovid" Poe <ovid@cpan.org>
1814
1815 Andy Armstong <andy@hexten.net>
1816
1817 Eric Wilhelm @ <ewilhelm at cpan dot org>
1818
1819 Michael Peters <mpeters at plusthree dot com>
1820
1821 Leif Eriksen <leif dot eriksen at bigpond dot com>
1822
1823 Steve Purkis <spurkis@cpan.org>
1824
1825 =head1 BUGS
1826
1827 Please report any bugs or feature requests to
1828 C<bug-tapx-parser@rt.cpan.org>, or through the web interface at
1829 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=TAP-Parser>.
1830 We will be notified, and then you'll automatically be notified of
1831 progress on your bug as we make changes.
1832
1833 Obviously, bugs which include patches are best. If you prefer, you can
1834 patch against bleed by via anonymous checkout of the latest version:
1835
1836  svn checkout http://svn.hexten.net/tapx
1837
1838 =head1 COPYRIGHT & LICENSE
1839
1840 Copyright 2006-2008 Curtis "Ovid" Poe, all rights reserved.
1841
1842 This program is free software; you can redistribute it and/or modify it
1843 under the same terms as Perl itself.
1844
1845 =cut
1846
1847 1;