blib/lib/Sort/MergeSort/Iterator.pm

filter: Statementstmt 67.3% 66 / 98 Branchbran 77.2% 17 / 22 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 37.8% 14 / 37 Podpod 35.0% 7 / 20 totaltotal 59.3% 111 / 187 CC 14 SCAR 9.1
CC
14
Cov
70%
close
6.0
getlines
6.0
new
4.0
CRAP 2.5
« lib/Sort/MergeSort.pm ↑ Summary
1 package Sort::MergeSort::Iterator;
2  
3 # $Id: Iterator.pm 13859 2009-07-24 08:02:37Z david $
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our $VERSION = '0.01';
10 2 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ##############################################################################
13 # Constructor.
14 ##############################################################################
15  
16 164 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
17 164 my ( $class, $code, $destroy ) = @_;
18 164 ▶ croak qq{Argument "$code" is not a code reference} if ref $code ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 1 163 164
19 163 ▶ croak qq{Argument "$destroy" is not a code reference}
Branch: 1 branch
BranchTrueFalseTotal
if $destroy and ref $destroy ne "CODE" 0 163 163
Condition66%2/3
$destroy and ref $destroy ne "CODE"
!ll&&!rl&&r
16210
MC/DC0%0/2
$destroy and ref $destroy ne "CODE"
$destroy ref $destroy ne "CODE"
Truth table66%2/3
A and B
A= $destroyB= ref $destroy ne "CODE"
ABresult
0X0
100
111
20 if $destroy && ref $destroy ne 'CODE';
21  
22 163 my $self = bless gensym, $class;
23 163 ${*$self}{code} = $code;
24 163 ${*$self}{destroy} = $destroy;
25 163 ${*$self}{count} = 0;
26  
27 163 tie(*$self, $class, $self);
28  
29 163 return $self;
30 }
31  
32 163 ▶DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
33 163 my $self = shift;
34 163 ▶ my $dest = ${*$self}{destroy} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dest = do { *$self }->{"destroy"} or return 1 162 163
35 1 $dest->();
36 }
37  
38 ##############################################################################
39 # Instance Methods.
40 ##############################################################################
41  
42 89074 ▶sub next {
Subroutine next: called CC=3 SCAR=11.0
Pod documented
43 89074 my $self = shift;
44 89074 ${*$self}{curr} = exists ${*$self}{peek}
45 17 ? delete ${*$self}{peek}
46 89074 ▶ : ${*$self}{code}->();
Branch: 1 branch
BranchTrueFalseTotal
exists do { *$self }->{'peek'} ? : 17 89057 89074
47 89074 ▶ ${*$self}{count}++ if defined ${*$self}{curr};
Branch: 1 branch
BranchTrueFalseTotal
if defined do { *$self }->{"curr"} 88909 165 89074
48 89074 return ${*$self}{curr};
49 }
50  
51 ##############################################################################
52  
53 2 ▶sub current {
Subroutine current: called CC=1 SCAR=0.0
Pod documented
54 2 my $self = shift;
55 2 ${*$self}{curr};
56 }
57  
58 ##############################################################################
59  
60 18 ▶sub peek {
Subroutine peek: called CC=2 SCAR=6.9
Pod documented
61 18 my $self = shift;
62 18 ▶ return ${*$self}{peek} ||= ${*$self}{code}->();
Condition100%3/3
do { *$self }->{"peek"} ||= do { *$self }->{"code"}->()
l!l&&r!l&&!r
1152
MC/DC100%2/2
do { *$self }->{"peek"} ||= do { *$self }->{"code"}->()
do { *$self }->{"peek"} do { *$self }->{"code"}->()
Truth table100%3/3
A ||= B
A= do { *$self }->{"peek"}B= do { *$self }->{"code"}->()
ABresult
1X1
011
000
63 }
64  
65 ##############################################################################
66  
67 4 ▶sub position {
Subroutine position: called CC=1 SCAR=0.0
Pod documented
68 4 my $self = shift;
69 4 ${*$self}{count};
70 }
71  
72 ##############################################################################
73  
74 2 ▶sub all {
Subroutine all: called CC=3 SCAR=11.0
Pod documented
75 2 my $self = shift;
76 2 my @items;
77 2 ▶ push @items, $self->next while $self->peek;
Branch: 1 branch
BranchTrueFalseTotal
$self->peek and do { push @items, $self->next } 12 2 14
78 2 ▶ return wantarray ? @items : \@items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
79 }
80  
81 ##############################################################################
82  
83 3 ▶sub do {
Subroutine do: called CC=3 SCAR=11.0
Pod documented
84 3 my ( $self, $code ) = @_;
85 3 ▶ while ( local $_ = $self->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (local $_ = $self->next) 16 2 18
86 16 ▶ return unless $code->($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($_) 1 15 16
87 }
88 }
89  
90 ##############################################################################
91  
92 sub close
93 0 ▶{
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my $self = shift;
95 0 ▶ my $dest = ${*$self}{destroy} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dest = do { *$self }->{"destroy"} or return 0 0 0
96 0 $dest->();
97 0 delete ${*$self}{destroy};
98 0 ▶ ${*self}{code} = sub { die "attempt to read a closed iterator" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 }
100  
101 2 *CLOSE = \&close;
102  
103 0 ▶sub sysread { die "not implemented" }
Subroutine sysread: not called CC=1 SCAR=6.9
Pod undocumented
104 0 ▶sub open { die "not implemented" }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
105 0 ▶sub syswrite { die "not implemented" }
Subroutine syswrite: not called CC=1 SCAR=6.9
Pod undocumented
106 0 ▶sub ungetc { die "not implemented" }
Subroutine ungetc: not called CC=1 SCAR=6.9
Pod undocumented
107 0 ▶sub getc { die "not implemented" }
Subroutine getc: not called CC=1 SCAR=6.9
Pod undocumented
108 0 ▶sub ungetline { die "not implemented" }
Subroutine ungetline: not called CC=1 SCAR=6.9
Pod undocumented
109 0 ▶sub xungetc { die "not implemented" }
Subroutine xungetc: not called CC=1 SCAR=6.9
Pod undocumented
110 0 ▶sub print { die "not implemented" }
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
111 0 ▶sub fileno { die "not implemented" }
Subroutine fileno: not called CC=1 SCAR=6.9
Pod undocumented
112 0 ▶sub PRINTF { die "not implemented" }
Subroutine PRINTF: not called CC=1 SCAR=6.9
113 0 ▶sub PRINT { die "not implemented" }
Subroutine PRINT: not called CC=1 SCAR=6.9
114 0 ▶sub READ { confess "not implemented" }
Subroutine READ: not called CC=1 SCAR=6.9
115 0 ▶sub read { die "not implemented" }
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
116 0 ▶sub WRITE { die "not implemented" }
Subroutine WRITE: not called CC=1 SCAR=6.9
117 0 ▶sub TELL { die "not implemented" }
Subroutine TELL: not called CC=1 SCAR=6.9
118 0 ▶sub SEEK { die "not implemented" }
Subroutine SEEK: not called CC=1 SCAR=6.9
119 0 ▶sub OPEN { die "not implemented" }
Subroutine OPEN: not called CC=1 SCAR=6.9
120 0 ▶sub GETC { die "not implemented" }
Subroutine GETC: not called CC=1 SCAR=6.9
121 0 ▶sub BINMODE { }
Subroutine BINMODE: not called CC=1 SCAR=0.0
122  
123 sub eof
124 0 ▶{
Subroutine eof: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $self = shift;
126 0 return ! defined $self->peek;
127 }
128  
129 2 *EOF = \&eof;
130  
131 sub getlines
132 0 ▶{
Subroutine getlines: not called CC=2 SCAR=17.9
Pod undocumented
133 0 my $self = shift;
134 0 ▶ die unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
135 0 return ($self->all());
136 }
137  
138 sub TIEHANDLE
139 163 ▶{
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
140 163 my ($class, $self) = @_;
141 163 return $self;
142 }
143  
144 2 *READLINE = \&next;
145  
146 2 1;
147 __END__
« lib/Sort/MergeSort.pm ↑ Summary