Commit | Line | Data |
---|---|---|
b965d173 NC |
1 | package TAP::Parser::Iterator::Array; |
2 | ||
3 | use strict; | |
b965d173 | 4 | use vars qw($VERSION @ISA); |
f7c69158 NC |
5 | |
6 | use TAP::Parser::Iterator (); | |
7 | ||
b965d173 NC |
8 | @ISA = 'TAP::Parser::Iterator'; |
9 | ||
10 | =head1 NAME | |
11 | ||
f7c69158 | 12 | TAP::Parser::Iterator::Array - Internal TAP::Parser array Iterator |
b965d173 NC |
13 | |
14 | =head1 VERSION | |
15 | ||
f7c69158 | 16 | Version 3.13 |
b965d173 NC |
17 | |
18 | =cut | |
19 | ||
f7c69158 | 20 | $VERSION = '3.13'; |
b965d173 NC |
21 | |
22 | =head1 SYNOPSIS | |
23 | ||
f7c69158 | 24 | # see TAP::Parser::IteratorFactory for preferred usage |
b965d173 | 25 | |
f7c69158 NC |
26 | # to use directly: |
27 | use TAP::Parser::Iterator::Array; | |
28 | my @data = ('foo', 'bar', baz'); | |
29 | my $it = TAP::Parser::Iterator::Array->new(\@data); | |
b965d173 NC |
30 | my $line = $it->next; |
31 | ||
b965d173 NC |
32 | =head1 DESCRIPTION |
33 | ||
f7c69158 NC |
34 | This is a simple iterator wrapper for arrays of scalar content, 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 NC |
39 | |
40 | =head2 Class Methods | |
41 | ||
42 | =head3 C<new> | |
43 | ||
f7c69158 | 44 | Create an iterator. Takes one argument: an C<$array_ref> |
b965d173 NC |
45 | |
46 | =head2 Instance Methods | |
47 | ||
48 | =head3 C<next> | |
49 | ||
50 | Iterate through it, of course. | |
51 | ||
52 | =head3 C<next_raw> | |
53 | ||
54 | Iterate raw input without applying any fixes for quirky input syntax. | |
55 | ||
56 | =head3 C<wait> | |
57 | ||
58 | Get the wait status for this iterator. For an array iterator this will always | |
59 | be zero. | |
60 | ||
61 | =head3 C<exit> | |
62 | ||
63 | Get the exit status for this iterator. For an array iterator this will always | |
64 | be zero. | |
65 | ||
66 | =cut | |
67 | ||
f7c69158 NC |
68 | # new() implementation supplied by TAP::Object |
69 | ||
70 | sub _initialize { | |
71 | my ( $self, $thing ) = @_; | |
b965d173 | 72 | chomp @$thing; |
f7c69158 NC |
73 | $self->{idx} = 0; |
74 | $self->{array} = $thing; | |
75 | $self->{exit} = undef; | |
76 | return $self; | |
b965d173 NC |
77 | } |
78 | ||
79 | sub wait { shift->exit } | |
80 | ||
81 | sub exit { | |
82 | my $self = shift; | |
83 | return 0 if $self->{idx} >= @{ $self->{array} }; | |
84 | return; | |
85 | } | |
86 | ||
87 | sub next_raw { | |
88 | my $self = shift; | |
89 | return $self->{array}->[ $self->{idx}++ ]; | |
90 | } | |
91 | ||
92 | 1; | |
f7c69158 NC |
93 | |
94 | =head1 ATTRIBUTION | |
95 | ||
96 | Originally ripped off from L<Test::Harness>. | |
97 | ||
98 | =head1 SEE ALSO | |
99 | ||
100 | L<TAP::Object>, | |
101 | L<TAP::Parser>, | |
102 | L<TAP::Parser::Iterator>, | |
103 | L<TAP::Parser::IteratorFactory>, | |
104 | ||
105 | =cut | |
106 |