line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Array::Iterator::BiDirectional; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
57493
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.12'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
363
|
use Array::Iterator; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
293
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Array::Iterator); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub has_previous { |
13
|
17
|
|
|
17
|
1
|
84
|
my ($self, $n) = @_; |
14
|
|
|
|
|
|
|
|
15
|
17
|
100
|
|
|
|
38
|
if(not defined $n) { $n = 1 } |
|
10
|
100
|
|
|
|
14
|
|
|
|
100
|
|
|
|
|
|
16
|
1
|
|
|
|
|
8
|
elsif(not $n) { die "has_previous(0) doesn't make sense, did you mean current()?" } |
17
|
1
|
|
|
|
|
7
|
elsif($n < 0) { die "has_previous() with negative argument doesn't make sense, did you mean has_next()?" } |
18
|
|
|
|
|
|
|
|
19
|
15
|
|
|
|
|
29
|
my $idx = $self->_current_index - $n; |
20
|
|
|
|
|
|
|
|
21
|
15
|
100
|
|
|
|
50
|
return ($idx > 0) ? 1 : 0; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
10
|
0
|
1438
|
sub hasPrevious { my $self = shift; $self->has_previous(@_) } |
|
10
|
|
|
|
|
18
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub previous { |
27
|
5
|
|
|
5
|
1
|
1378
|
my ($self) = @_; |
28
|
5
|
100
|
|
|
|
13
|
(($self->_current_index - 1) > 0) |
29
|
|
|
|
|
|
|
|| die "Out Of Bounds : no more elements"; |
30
|
4
|
|
|
|
|
10
|
$self->_iterated = 1; |
31
|
4
|
|
|
|
|
10
|
return $self->_getItem($self->_iteratee, --$self->_current_index); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_previous { |
35
|
5
|
|
|
5
|
1
|
9
|
my ($self) = @_; |
36
|
5
|
100
|
|
|
|
10
|
return undef unless (($self->_current_index - 1) > 0); |
37
|
4
|
|
|
|
|
9
|
$self->_iterated = 1; |
38
|
4
|
|
|
|
|
9
|
return $self->_getItem($self->_iteratee, --$self->_current_index); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
5
|
0
|
1409
|
sub getPrevious { my $self = shift; $self->get_previous(@_) } |
|
5
|
|
|
|
|
10
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub look_back { |
44
|
14
|
|
|
14
|
1
|
73
|
my ($self, $n) = @_; |
45
|
|
|
|
|
|
|
|
46
|
14
|
100
|
|
|
|
37
|
if(not defined $n) { $n = 1 } |
|
5
|
100
|
|
|
|
7
|
|
|
|
100
|
|
|
|
|
|
47
|
1
|
|
|
|
|
7
|
elsif(not $n) { die "look_back(0) doesn't make sense, did you mean get_previous()?" } |
48
|
1
|
|
|
|
|
7
|
elsif($n < 0) { die "look_back() with negative argument doesn't make sense, did you mean get_next()?" } |
49
|
|
|
|
|
|
|
|
50
|
12
|
|
|
|
|
27
|
my $idx = $self->_current_index - ($n + 1); |
51
|
|
|
|
|
|
|
|
52
|
12
|
100
|
|
|
|
33
|
return undef unless ($idx > 0); |
53
|
7
|
|
|
|
|
16
|
$self->_iterated = 1; |
54
|
7
|
|
|
|
|
17
|
return $self->_getItem($self->_iteratee, $idx); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
4
|
0
|
5
|
sub lookBack { my $self = shift; $self->look_back(@_) } |
|
4
|
|
|
|
|
9
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
# ABSTRACT: A subclass of Array::Iterator to allow forwards and backwards iteration |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |