bring Test::Harness up to 3.06
[p5sagit/p5-mst-13.2.git] / lib / TAP / Parser / Iterator / Stream.pm
CommitLineData
b965d173 1package TAP::Parser::Iterator::Stream;
2
3use strict;
4use TAP::Parser::Iterator ();
5use vars qw($VERSION @ISA);
6@ISA = 'TAP::Parser::Iterator';
7
8=head1 NAME
9
10TAP::Parser::Iterator::Stream - Internal TAP::Parser Iterator
11
12=head1 VERSION
13
69f36734 14Version 3.06
b965d173 15
16=cut
17
69f36734 18$VERSION = '3.06';
b965d173 19
20=head1 SYNOPSIS
21
22 use TAP::Parser::Iterator;
23 my $it = TAP::Parser::Iterator::Stream->new(\*TEST);
24
25 my $line = $it->next;
26
27Originally ripped off from L<Test::Harness>.
28
29=head1 DESCRIPTION
30
31B<FOR INTERNAL USE ONLY!>
32
33This is a simple iterator wrapper for filehandles.
34
35=head2 Class Methods
36
37=head3 C<new>
38
39Create an iterator.
40
41=head2 Instance Methods
42
43=head3 C<next>
44
45Iterate through it, of course.
46
47=head3 C<next_raw>
48
49Iterate raw input without applying any fixes for quirky input syntax.
50
51=head3 C<wait>
52
53Get the wait status for this iterator. Always returns zero.
54
55=head3 C<exit>
56
57Get the exit status for this iterator. Always returns zero.
58
59=cut
60
61sub new {
62 my ( $class, $thing ) = @_;
63 bless {
64 fh => $thing,
65 }, $class;
66}
67
68##############################################################################
69
70sub wait { shift->exit }
71sub exit { shift->{fh} ? () : 0 }
72
73sub next_raw {
74 my $self = shift;
75 my $fh = $self->{fh};
76
77 if ( defined( my $line = <$fh> ) ) {
78 chomp $line;
79 return $line;
80 }
81 else {
82 $self->_finish;
83 return;
84 }
85}
86
87sub _finish {
88 my $self = shift;
89 close delete $self->{fh};
90}
91
921;