Track /etc/gitconfig
[msysgit.git] / lib / perl5 / 5.8.8 / Test / Harness / Iterator.pm
blob2648cea70795472a94efe130448c656ce412399a
1 package Test::Harness::Iterator;
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.02;
7 =head1 NAME
9 Test::Harness::Iterator - Internal Test::Harness Iterator
11 =head1 SYNOPSIS
13 use Test::Harness::Iterator;
14 my $it = Test::Harness::Iterator->new(\*TEST);
15 my $it = Test::Harness::Iterator->new(\@array);
17 my $line = $it->next;
19 =head1 DESCRIPTION
21 B<FOR INTERNAL USE ONLY!>
23 This is a simple iterator wrapper for arrays and filehandles.
25 =head2 new()
27 Create an iterator.
29 =head2 next()
31 Iterate through it, of course.
33 =cut
35 sub new {
36 my($proto, $thing) = @_;
38 my $self = {};
39 if( ref $thing eq 'GLOB' ) {
40 bless $self, 'Test::Harness::Iterator::FH';
41 $self->{fh} = $thing;
43 elsif( ref $thing eq 'ARRAY' ) {
44 bless $self, 'Test::Harness::Iterator::ARRAY';
45 $self->{idx} = 0;
46 $self->{array} = $thing;
48 else {
49 warn "Can't iterate with a ", ref $thing;
52 return $self;
55 package Test::Harness::Iterator::FH;
56 sub next {
57 my $fh = $_[0]->{fh};
59 # readline() doesn't work so good on 5.5.4.
60 return scalar <$fh>;
64 package Test::Harness::Iterator::ARRAY;
65 sub next {
66 my $self = shift;
67 return $self->{array}->[$self->{idx}++];
70 "Steve Peters, Master Of True Value Finding, was here.";