Debian lenny version packages
[pkg-perl] / deb-src / libtest-harness-perl / libtest-harness-perl-3.12 / lib / TAP / Parser / Iterator / Array.pm
1 package TAP::Parser::Iterator::Array;
2
3 use strict;
4 use vars qw($VERSION @ISA);
5
6 use TAP::Parser::Iterator ();
7
8 @ISA = 'TAP::Parser::Iterator';
9
10 =head1 NAME
11
12 TAP::Parser::Iterator::Array - Internal TAP::Parser array Iterator
13
14 =head1 VERSION
15
16 Version 3.12
17
18 =cut
19
20 $VERSION = '3.12';
21
22 =head1 SYNOPSIS
23
24   # see TAP::Parser::IteratorFactory for preferred usage
25
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);
30   my $line = $it->next;
31
32 =head1 DESCRIPTION
33
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.
37
38 =head1 METHODS
39
40 =head2 Class Methods
41
42 =head3 C<new>
43
44 Create an iterator.  Takes one argument: an C<$array_ref>
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
68 # new() implementation supplied by TAP::Object
69
70 sub _initialize {
71     my ( $self, $thing ) = @_;
72     chomp @$thing;
73     $self->{idx}   = 0;
74     $self->{array} = $thing;
75     $self->{exit}  = undef;
76     return $self;
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;
93
94
95 =head1 ATTRIBUTION
96
97 Originally ripped off from L<Test::Harness>.
98
99 =head1 SEE ALSO
100
101 L<TAP::Object>,
102 L<TAP::Parser>,
103 L<TAP::Parser::Iterator>,
104 L<TAP::Parser::IteratorFactory>,
105
106 =cut
107