Commit | Line | Data |
b965d173 |
1 | package TAP::Parser::Iterator; |
2 | |
3 | use strict; |
4 | use vars qw($VERSION); |
5 | |
6 | use TAP::Parser::Iterator::Array (); |
7 | use TAP::Parser::Iterator::Stream (); |
8 | use TAP::Parser::Iterator::Process (); |
9 | |
10 | =head1 NAME |
11 | |
12 | TAP::Parser::Iterator - Internal TAP::Parser Iterator |
13 | |
14 | =head1 VERSION |
15 | |
69f36734 |
16 | Version 3.06 |
b965d173 |
17 | |
18 | =cut |
19 | |
69f36734 |
20 | $VERSION = '3.06'; |
b965d173 |
21 | |
22 | =head1 SYNOPSIS |
23 | |
24 | use TAP::Parser::Iterator; |
25 | my $it = TAP::Parser::Iterator->new(\*TEST); |
26 | my $it = TAP::Parser::Iterator->new(\@array); |
27 | |
28 | my $line = $it->next; |
29 | |
30 | Originally ripped off from L<Test::Harness>. |
31 | |
32 | =head1 DESCRIPTION |
33 | |
34 | B<FOR INTERNAL USE ONLY!> |
35 | |
36 | This is a simple iterator wrapper for arrays and filehandles. |
37 | |
38 | =head2 Class Methods |
39 | |
40 | =head3 C<new> |
41 | |
42 | my $iter = TAP::Parser::Iterator->new( $array_reference ); |
43 | my $iter = TAP::Parser::Iterator->new( $filehandle ); |
44 | |
45 | Create an iterator. |
46 | |
47 | =head2 Instance Methods |
48 | |
49 | =head3 C<next> |
50 | |
51 | while ( my $item = $iter->next ) { ... } |
52 | |
53 | Iterate through it, of course. |
54 | |
55 | =head3 C<next_raw> |
56 | |
57 | while ( my $item = $iter->next_raw ) { ... } |
58 | |
59 | Iterate raw input without applying any fixes for quirky input syntax. |
60 | |
61 | =cut |
62 | |
63 | sub new { |
64 | my ( $proto, $thing ) = @_; |
65 | |
66 | my $ref = ref $thing; |
67 | if ( $ref eq 'GLOB' || $ref eq 'IO::Handle' ) { |
68 | return TAP::Parser::Iterator::Stream->new($thing); |
69 | } |
70 | elsif ( $ref eq 'ARRAY' ) { |
71 | return TAP::Parser::Iterator::Array->new($thing); |
72 | } |
73 | elsif ( $ref eq 'HASH' ) { |
74 | return TAP::Parser::Iterator::Process->new($thing); |
75 | } |
76 | else { |
77 | die "Can't iterate with a $ref"; |
78 | } |
79 | } |
80 | |
81 | sub next { |
82 | my $self = shift; |
83 | my $line = $self->next_raw; |
84 | |
85 | # vms nit: When encountering 'not ok', vms often has the 'not' on a line |
86 | # by itself: |
87 | # not |
88 | # ok 1 - 'I hate VMS' |
89 | if ( defined($line) and $line =~ /^\s*not\s*$/ ) { |
90 | $line .= ( $self->next_raw || '' ); |
91 | } |
92 | |
93 | return $line; |
94 | } |
95 | |
96 | =head3 C<handle_unicode> |
97 | |
98 | If necessary switch the input stream to handle unicode. This only has |
99 | any effect for I/O handle based streams. |
100 | |
101 | =cut |
102 | |
103 | sub handle_unicode { } |
104 | |
105 | =head3 C<get_select_handles> |
106 | |
107 | Return a list of filehandles that may be used upstream in a select() |
108 | call to signal that this Iterator is ready. Iterators that are not |
109 | handle based should return an empty list. |
110 | |
111 | =cut |
112 | |
113 | sub get_select_handles {return} |
114 | |
115 | 1; |