line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Cycle; |
2
|
3
|
|
|
3
|
|
41966
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
161
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.225'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
100
|
use Carp qw(carp); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
230
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
24
|
use constant CURSOR_COL => 0; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
285
|
|
9
|
3
|
|
|
3
|
|
23
|
use constant COUNT_COL => 1; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
189
|
|
10
|
3
|
|
|
3
|
|
24
|
use constant ITEM_COL => 2; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1587
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub TIESCALAR { |
13
|
2
|
|
|
2
|
|
33
|
my( $class, $list_ref ) = @_; |
14
|
2
|
|
|
|
|
7
|
my $self = bless [], $class; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
9
|
unless( $self->STORE( $list_ref ) ) { |
17
|
0
|
|
|
|
|
0
|
carp "The argument to Tie::Cycle must be an array reference"; |
18
|
0
|
|
|
|
|
0
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
7
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub FETCH { |
25
|
12
|
|
|
12
|
|
4888
|
my( $self ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
12
|
|
|
|
|
23
|
my $index = $self->[CURSOR_COL]++; |
28
|
12
|
|
|
|
|
31
|
$self->[CURSOR_COL] %= $self->_count; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
28
|
return $self->_item( $index ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub STORE { |
34
|
2
|
|
|
2
|
|
6
|
my( $self, $list_ref ) = @_; |
35
|
2
|
50
|
|
|
|
9
|
return unless ref $list_ref eq ref []; |
36
|
2
|
|
|
|
|
5
|
my @shallow_copy = map { $_ } @$list_ref; |
|
4
|
|
|
|
|
11
|
|
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
9
|
$self->[CURSOR_COL] = 0; |
39
|
2
|
|
|
|
|
5
|
$self->[COUNT_COL] = scalar @shallow_copy; |
40
|
2
|
|
|
|
|
9
|
$self->[ITEM_COL] = \@shallow_copy; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
1
|
0
|
sub reset { $_[0]->[CURSOR_COL] = 0 } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub previous { |
46
|
0
|
|
|
0
|
1
|
0
|
my( $self ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $index = $self->_cursor - 1; |
49
|
0
|
|
|
|
|
0
|
$self->[CURSOR_COL] %= $self->_count; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
return $self->_item( $index ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub next { |
55
|
0
|
|
|
0
|
1
|
0
|
my( $self ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my $index = $self->_cursor + 1; |
58
|
0
|
|
|
|
|
0
|
$self->[CURSOR_COL] %= $self->_count; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
return $self->_item( $index ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
|
0
|
sub _cursor { $_[0]->[CURSOR_COL] } |
64
|
12
|
|
|
12
|
|
25
|
sub _count { $_[0]->[COUNT_COL] } |
65
|
|
|
|
|
|
|
sub _item { |
66
|
12
|
|
|
12
|
|
23
|
my( $self, $index ) = @_; |
67
|
12
|
50
|
|
|
|
30
|
$index = defined $index ? $index : $self->_cursor; |
68
|
12
|
|
|
|
|
40
|
$self->[ITEM_COL][ $index ] |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
"Tie::Cycle"; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |