source: for-distributions/trunk/bin/windows/perl/lib/Test/Harness/Iterator.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 1.3 KB
Line 
1package Test::Harness::Iterator;
2
3use strict;
4use vars qw($VERSION);
5$VERSION = 0.02;
6
7=head1 NAME
8
9Test::Harness::Iterator - Internal Test::Harness Iterator
10
11=head1 SYNOPSIS
12
13 use Test::Harness::Iterator;
14 my $it = Test::Harness::Iterator->new(\*TEST);
15 my $it = Test::Harness::Iterator->new(\@array);
16
17 my $line = $it->next;
18
19=head1 DESCRIPTION
20
21B<FOR INTERNAL USE ONLY!>
22
23This is a simple iterator wrapper for arrays and filehandles.
24
25=head2 new()
26
27Create an iterator.
28
29=head2 next()
30
31Iterate through it, of course.
32
33=cut
34
35sub new {
36 my($proto, $thing) = @_;
37
38 my $self = {};
39 if( ref $thing eq 'GLOB' ) {
40 bless $self, 'Test::Harness::Iterator::FH';
41 $self->{fh} = $thing;
42 }
43 elsif( ref $thing eq 'ARRAY' ) {
44 bless $self, 'Test::Harness::Iterator::ARRAY';
45 $self->{idx} = 0;
46 $self->{array} = $thing;
47 }
48 else {
49 warn "Can't iterate with a ", ref $thing;
50 }
51
52 return $self;
53}
54
55package Test::Harness::Iterator::FH;
56sub next {
57 my $fh = $_[0]->{fh};
58
59 # readline() doesn't work so good on 5.5.4.
60 return scalar <$fh>;
61}
62
63
64package Test::Harness::Iterator::ARRAY;
65sub next {
66 my $self = shift;
67 return $self->{array}->[$self->{idx}++];
68}
69
70"Steve Peters, Master Of True Value Finding, was here.";
Note: See TracBrowser for help on using the repository browser.