Commit | Line | Data |
b965d173 |
1 | package TAP::Parser::Iterator::Stream; |
2 | |
3 | use strict; |
b965d173 |
4 | use vars qw($VERSION @ISA); |
f7c69158 |
5 | |
6 | use TAP::Parser::Iterator (); |
7 | |
b965d173 |
8 | @ISA = 'TAP::Parser::Iterator'; |
9 | |
10 | =head1 NAME |
11 | |
12 | TAP::Parser::Iterator::Stream - Internal TAP::Parser Iterator |
13 | |
14 | =head1 VERSION |
15 | |
f7c69158 |
16 | Version 3.13 |
b965d173 |
17 | |
18 | =cut |
19 | |
f7c69158 |
20 | $VERSION = '3.13'; |
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 |
34 | This is a simple iterator wrapper for reading from filehandles, used by |
35 | L<TAP::Parser>. Unless you're subclassing, you probably won't need to use |
36 | this module directly. |
b965d173 |
37 | |
f7c69158 |
38 | =head1 METHODS |
b965d173 |
39 | |
40 | =head2 Class Methods |
41 | |
42 | =head3 C<new> |
43 | |
f7c69158 |
44 | Create an iterator. Expects one argument containing a filehandle. |
45 | |
46 | =cut |
47 | |
48 | # new() implementation supplied by TAP::Object |
49 | |
50 | sub _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 | |
60 | Iterate through it, of course. |
61 | |
62 | =head3 C<next_raw> |
63 | |
64 | Iterate raw input without applying any fixes for quirky input syntax. |
65 | |
66 | =head3 C<wait> |
67 | |
68 | Get the wait status for this iterator. Always returns zero. |
69 | |
70 | =head3 C<exit> |
71 | |
72 | Get the exit status for this iterator. Always returns zero. |
73 | |
74 | =cut |
75 | |
b965d173 |
76 | sub wait { shift->exit } |
77 | sub exit { shift->{fh} ? () : 0 } |
78 | |
79 | sub 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 | |
93 | sub _finish { |
94 | my $self = shift; |
95 | close delete $self->{fh}; |
96 | } |
97 | |
98 | 1; |
f7c69158 |
99 | |
100 | =head1 ATTRIBUTION |
101 | |
102 | Originally ripped off from L<Test::Harness>. |
103 | |
104 | =head1 SEE ALSO |
105 | |
106 | L<TAP::Object>, |
107 | L<TAP::Parser>, |
108 | L<TAP::Parser::Iterator>, |
109 | L<TAP::Parser::IteratorFactory>, |
110 | |
111 | =cut |
112 | |