Upgrade to Test::Harness 3.14
[p5sagit/p5-mst-13.2.git] / ext / Test / Harness / lib / TAP / Parser / Iterator / Stream.pm
CommitLineData
b965d173 1package TAP::Parser::Iterator::Stream;
2
3use strict;
b965d173 4use vars qw($VERSION @ISA);
f7c69158 5
6use TAP::Parser::Iterator ();
7
b965d173 8@ISA = 'TAP::Parser::Iterator';
9
10=head1 NAME
11
12TAP::Parser::Iterator::Stream - Internal TAP::Parser Iterator
13
14=head1 VERSION
15
27fc0087 16Version 3.14
b965d173 17
18=cut
19
27fc0087 20$VERSION = '3.14';
b965d173 21
22=head1 SYNOPSIS
23
f7c69158 24 # see TAP::Parser::IteratorFactory for preferred usage
b965d173 25
f7c69158 26 # to use directly:
27 use TAP::Parser::Iterator::Stream;
28 open( TEST, 'test.tap' );
29 my $it = TAP::Parser::Iterator::Stream->new(\*TEST);
b965d173 30 my $line = $it->next;
31
b965d173 32=head1 DESCRIPTION
33
f7c69158 34This is a simple iterator wrapper for reading from filehandles, used by
35L<TAP::Parser>. Unless you're subclassing, you probably won't need to use
36this module directly.
b965d173 37
f7c69158 38=head1 METHODS
b965d173 39
40=head2 Class Methods
41
42=head3 C<new>
43
f7c69158 44Create an iterator. Expects one argument containing a filehandle.
45
46=cut
47
48# new() implementation supplied by TAP::Object
49
50sub _initialize {
51 my ( $self, $thing ) = @_;
52 $self->{fh} = $thing;
53 return $self;
54}
b965d173 55
56=head2 Instance Methods
57
58=head3 C<next>
59
60Iterate through it, of course.
61
62=head3 C<next_raw>
63
64Iterate raw input without applying any fixes for quirky input syntax.
65
66=head3 C<wait>
67
68Get the wait status for this iterator. Always returns zero.
69
70=head3 C<exit>
71
72Get the exit status for this iterator. Always returns zero.
73
74=cut
75
b965d173 76sub wait { shift->exit }
77sub exit { shift->{fh} ? () : 0 }
78
79sub next_raw {
80 my $self = shift;
81 my $fh = $self->{fh};
82
83 if ( defined( my $line = <$fh> ) ) {
84 chomp $line;
85 return $line;
86 }
87 else {
88 $self->_finish;
89 return;
90 }
91}
92
93sub _finish {
94 my $self = shift;
95 close delete $self->{fh};
96}
97
981;
f7c69158 99
100=head1 ATTRIBUTION
101
102Originally ripped off from L<Test::Harness>.
103
104=head1 SEE ALSO
105
106L<TAP::Object>,
107L<TAP::Parser>,
108L<TAP::Parser::Iterator>,
109L<TAP::Parser::IteratorFactory>,
110
111=cut
112