Commit | Line | Data |
b965d173 |
1 | package TAP::Parser::Iterator::Stream; |
2 | |
3 | use strict; |
4 | use TAP::Parser::Iterator (); |
5 | use vars qw($VERSION @ISA); |
6 | @ISA = 'TAP::Parser::Iterator'; |
7 | |
8 | =head1 NAME |
9 | |
10 | TAP::Parser::Iterator::Stream - Internal TAP::Parser Iterator |
11 | |
12 | =head1 VERSION |
13 | |
69f36734 |
14 | Version 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 | |
27 | Originally ripped off from L<Test::Harness>. |
28 | |
29 | =head1 DESCRIPTION |
30 | |
31 | B<FOR INTERNAL USE ONLY!> |
32 | |
33 | This is a simple iterator wrapper for filehandles. |
34 | |
35 | =head2 Class Methods |
36 | |
37 | =head3 C<new> |
38 | |
39 | Create an iterator. |
40 | |
41 | =head2 Instance Methods |
42 | |
43 | =head3 C<next> |
44 | |
45 | Iterate through it, of course. |
46 | |
47 | =head3 C<next_raw> |
48 | |
49 | Iterate raw input without applying any fixes for quirky input syntax. |
50 | |
51 | =head3 C<wait> |
52 | |
53 | Get the wait status for this iterator. Always returns zero. |
54 | |
55 | =head3 C<exit> |
56 | |
57 | Get the exit status for this iterator. Always returns zero. |
58 | |
59 | =cut |
60 | |
61 | sub new { |
62 | my ( $class, $thing ) = @_; |
63 | bless { |
64 | fh => $thing, |
65 | }, $class; |
66 | } |
67 | |
68 | ############################################################################## |
69 | |
70 | sub wait { shift->exit } |
71 | sub exit { shift->{fh} ? () : 0 } |
72 | |
73 | sub 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 | |
87 | sub _finish { |
88 | my $self = shift; |
89 | close delete $self->{fh}; |
90 | } |
91 | |
92 | 1; |