NumSeq/Base/Array.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 58 CC 3 SCAR 16.1
CC
3
Cov
0%
next
12.0
rewind
2.0
pred
2.0
CRAP 5.0
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Math::NumSeq::Base::Array;
19 use 5.004;
20 use strict;
21  
22 use vars '$VERSION', '@ISA';
23 $VERSION = 75;
24  
25 use Math::NumSeq;
26 @ISA = ('Math::NumSeq');
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31 # sub new {
32 # my $class = shift;
33 # my $self = $class->SUPER::new (@_);
34 # my $array = $self->{'array'};
35 # if ($self->{'lo'}) {
36 # while (@$array && (! defined $array->[0] || $array->[0] < $self->{'lo'})) {
37 # shift @$array;
38 # }
39 # }
40 # ### shifted to: @$array
41 # return $self;
42 # }
43 sub rewind {
44 my ($self) = @_;
45 $self->{'i'} = $self->i_start;
46 }
47 sub next {
48 my ($self) = @_;
49 ### ValuesArray next(): $self->{'i'} . ' of ' . scalar(@{$self->{'array'}})
50 my $array = $self->{'array'};
51 my $i;
52 for (;;) {
53 if (($i = $self->{'i'}++) > $#$array) {
54 return;
55 }
56 if (defined (my $n = $self->{'array'}->[$i])) {
57 return ($i, $n);
58 }
59 }
60 }
61 sub pred {
62 my ($self, $n) = @_;
63 return exists (($self->{'hash'} ||= do {
64 my %h;
65 @h{grep {defined} @{$self->{'array'}}} = ();
66 ### %h
67 \%h
68 })->{$n});
69 }
70 sub ith {
71 my ($self, $i) = @_;
72 return $self->{'array'}->[$i];
73 }
74  
75 1;
76 __END__