support/Test/Harness/Iterator.pm

filter: Statementstmt 72.7% 16 / 22 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 68.7% 22 / 32 CC 3 SCAR 9.1
CC
3
Cov
65%
new
4.1
next
2.0
BEGIN
1.0
CRAP 2.5
« examples/memmap.pl ↑ Summary support/Test/Builder/Module.pm »
1 package Test::Harness::Iterator;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $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<FOR INTERNAL USE ONLY!>
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 58 ▶ my($proto, $thing) = @_;
Subroutine new: called CC=3 SCAR=14.2
Pod documented
37  
38 58 my $self = {};
39 58 ▶ if( ref $thing eq 'GLOB' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $thing eq 'GLOB') { } 58 0 58
elsif (ref $thing eq 'ARRAY') { } 0 0 0
40 58 bless $self, 'Test::Harness::Iterator::FH';
41 58 $self->{fh} = $thing;
42 }
43 elsif( ref $thing eq 'ARRAY' ) {
44 0 bless $self, 'Test::Harness::Iterator::ARRAY';
45 0 $self->{idx} = 0;
46 0 $self->{array} = $thing;
47 }
48 else {
49 0 warn "Can't iterate with a ", ref $thing;
50 }
51  
52 58 return $self;
53 }
54  
55 package Test::Harness::Iterator::FH;
56 sub next {
57 64881 ▶ my $fh = $_[0]->{fh};
Subroutine next: called CC=1 SCAR=0.0
58  
59 # readline() doesn't work so good on 5.5.4.
60 64881 return scalar <$fh>;
61 }
62  
63  
64 package Test::Harness::Iterator::ARRAY;
65 sub next {
66 0 ▶ my $self = shift;
Subroutine next: not called CC=1 SCAR=6.9
67 0 return $self->{array}->[$self->{idx}++];
68 }
69  
70 1 "Steve Peters, Master Of True Value Finding, was here.";
« examples/memmap.pl ↑ Summary support/Test/Builder/Module.pm »