pull from upstream repository
[git-darcs-import.git] / tests / lib / perl / TAP / Parser / Iterator / Stream.pm
blob73ad147097d4d2b3fff199c3fcfc1229cbd6a359
1 package TAP::Parser::Iterator::Stream;
3 use strict;
4 use TAP::Parser::Iterator ();
5 use vars qw($VERSION @ISA);
6 @ISA = 'TAP::Parser::Iterator';
8 =head1 NAME
10 TAP::Parser::Iterator::Stream - Internal TAP::Parser Iterator
12 =head1 VERSION
14 Version 3.07
16 =cut
18 $VERSION = '3.07';
20 =head1 SYNOPSIS
22 use TAP::Parser::Iterator;
23 my $it = TAP::Parser::Iterator::Stream->new(\*TEST);
25 my $line = $it->next;
27 Originally ripped off from L<Test::Harness>.
29 =head1 DESCRIPTION
31 B<FOR INTERNAL USE ONLY!>
33 This is a simple iterator wrapper for filehandles.
35 =head2 Class Methods
37 =head3 C<new>
39 Create an iterator.
41 =head2 Instance Methods
43 =head3 C<next>
45 Iterate through it, of course.
47 =head3 C<next_raw>
49 Iterate raw input without applying any fixes for quirky input syntax.
51 =head3 C<wait>
53 Get the wait status for this iterator. Always returns zero.
55 =head3 C<exit>
57 Get the exit status for this iterator. Always returns zero.
59 =cut
61 sub new {
62 my ( $class, $thing ) = @_;
63 bless {
64 fh => $thing,
65 }, $class;
68 ##############################################################################
70 sub wait { shift->exit }
71 sub exit { shift->{fh} ? () : 0 }
73 sub next_raw {
74 my $self = shift;
75 my $fh = $self->{fh};
77 if ( defined( my $line = <$fh> ) ) {
78 chomp $line;
79 return $line;
81 else {
82 $self->_finish;
83 return;
87 sub _finish {
88 my $self = shift;
89 close delete $self->{fh};