bring Test::Harness up to 3.06
[p5sagit/p5-mst-13.2.git] / lib / TAP / Parser / Iterator.pm
CommitLineData
b965d173 1package TAP::Parser::Iterator;
2
3use strict;
4use vars qw($VERSION);
5
6use TAP::Parser::Iterator::Array ();
7use TAP::Parser::Iterator::Stream ();
8use TAP::Parser::Iterator::Process ();
9
10=head1 NAME
11
12TAP::Parser::Iterator - Internal TAP::Parser Iterator
13
14=head1 VERSION
15
69f36734 16Version 3.06
b965d173 17
18=cut
19
69f36734 20$VERSION = '3.06';
b965d173 21
22=head1 SYNOPSIS
23
24 use TAP::Parser::Iterator;
25 my $it = TAP::Parser::Iterator->new(\*TEST);
26 my $it = TAP::Parser::Iterator->new(\@array);
27
28 my $line = $it->next;
29
30Originally ripped off from L<Test::Harness>.
31
32=head1 DESCRIPTION
33
34B<FOR INTERNAL USE ONLY!>
35
36This is a simple iterator wrapper for arrays and filehandles.
37
38=head2 Class Methods
39
40=head3 C<new>
41
42 my $iter = TAP::Parser::Iterator->new( $array_reference );
43 my $iter = TAP::Parser::Iterator->new( $filehandle );
44
45Create an iterator.
46
47=head2 Instance Methods
48
49=head3 C<next>
50
51 while ( my $item = $iter->next ) { ... }
52
53Iterate through it, of course.
54
55=head3 C<next_raw>
56
57 while ( my $item = $iter->next_raw ) { ... }
58
59Iterate raw input without applying any fixes for quirky input syntax.
60
61=cut
62
63sub new {
64 my ( $proto, $thing ) = @_;
65
66 my $ref = ref $thing;
67 if ( $ref eq 'GLOB' || $ref eq 'IO::Handle' ) {
68 return TAP::Parser::Iterator::Stream->new($thing);
69 }
70 elsif ( $ref eq 'ARRAY' ) {
71 return TAP::Parser::Iterator::Array->new($thing);
72 }
73 elsif ( $ref eq 'HASH' ) {
74 return TAP::Parser::Iterator::Process->new($thing);
75 }
76 else {
77 die "Can't iterate with a $ref";
78 }
79}
80
81sub next {
82 my $self = shift;
83 my $line = $self->next_raw;
84
85 # vms nit: When encountering 'not ok', vms often has the 'not' on a line
86 # by itself:
87 # not
88 # ok 1 - 'I hate VMS'
89 if ( defined($line) and $line =~ /^\s*not\s*$/ ) {
90 $line .= ( $self->next_raw || '' );
91 }
92
93 return $line;
94}
95
96=head3 C<handle_unicode>
97
98If necessary switch the input stream to handle unicode. This only has
99any effect for I/O handle based streams.
100
101=cut
102
103sub handle_unicode { }
104
105=head3 C<get_select_handles>
106
107Return a list of filehandles that may be used upstream in a select()
108call to signal that this Iterator is ready. Iterators that are not
109handle based should return an empty list.
110
111=cut
112
113sub get_select_handles {return}
114
1151;