line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Harness::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
172
|
|
4
|
5
|
|
|
5
|
|
47
|
use vars qw($VERSION); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1270
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.02; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Test::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
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
B |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is a simple iterator wrapper for arrays and filehandles. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new() |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Create an iterator. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 next() |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Iterate through it, of course. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
41
|
|
|
41
|
1
|
286
|
my($proto, $thing) = @_; |
37
|
|
|
|
|
|
|
|
38
|
41
|
|
|
|
|
325
|
my $self = {}; |
39
|
41
|
50
|
|
|
|
460
|
if( ref $thing eq 'GLOB' ) { |
|
|
0
|
|
|
|
|
|
40
|
41
|
|
|
|
|
177
|
bless $self, 'Test::Harness::Iterator::FH'; |
41
|
41
|
|
|
|
|
551
|
$self->{fh} = $thing; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif( ref $thing eq 'ARRAY' ) { |
44
|
0
|
|
|
|
|
0
|
bless $self, 'Test::Harness::Iterator::ARRAY'; |
45
|
0
|
|
|
|
|
0
|
$self->{idx} = 0; |
46
|
0
|
|
|
|
|
0
|
$self->{array} = $thing; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
0
|
warn "Can't iterate with a ", ref $thing; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
41
|
|
|
|
|
258
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package Test::Harness::Iterator::FH; |
56
|
|
|
|
|
|
|
sub next { |
57
|
279
|
|
|
279
|
|
638
|
my $fh = $_[0]->{fh}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# readline() doesn't work so good on 5.5.4. |
60
|
279
|
|
|
|
|
114127549
|
return scalar <$fh>; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package Test::Harness::Iterator::ARRAY; |
65
|
|
|
|
|
|
|
sub next { |
66
|
0
|
|
|
0
|
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
return $self->{array}->[$self->{idx}++]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
"Steve Peters, Master Of True Value Finding, was here."; |