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