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