line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Cycle; |
2
|
3
|
|
|
3
|
|
158907
|
use strict; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
138
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.227'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
18
|
use Carp qw(carp); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
157
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
18
|
use constant CURSOR_COL => 0; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
275
|
|
9
|
3
|
|
|
3
|
|
20
|
use constant COUNT_COL => 1; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
189
|
|
10
|
3
|
|
|
3
|
|
20
|
use constant ITEM_COL => 2; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1613
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub TIESCALAR { |
13
|
2
|
|
|
2
|
|
185
|
my( $class, $list_ref ) = @_; |
14
|
2
|
|
|
|
|
8
|
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
|
|
5912
|
my( $self ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
12
|
|
|
|
|
54
|
my $index = $self->[CURSOR_COL]++; |
28
|
12
|
|
|
|
|
28
|
$self->[CURSOR_COL] %= $self->_count; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
29
|
return $self->_item( $index ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub STORE { |
34
|
2
|
|
|
2
|
|
6
|
my( $self, $list_ref ) = @_; |
35
|
2
|
50
|
|
|
|
11
|
return unless ref $list_ref eq ref []; |
36
|
2
|
|
|
|
|
8
|
my @shallow_copy = map { $_ } @$list_ref; |
|
4
|
|
|
|
|
11
|
|
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
10
|
$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
|
|
21
|
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__ |