line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Cycle; |
2
|
3
|
|
|
3
|
|
141468
|
use strict; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
130
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.226'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
18
|
use Carp qw(carp); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
218
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
21
|
use constant CURSOR_COL => 0; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
303
|
|
9
|
3
|
|
|
3
|
|
19
|
use constant COUNT_COL => 1; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
144
|
|
10
|
3
|
|
|
3
|
|
15
|
use constant ITEM_COL => 2; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1551
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub TIESCALAR { |
13
|
2
|
|
|
2
|
|
182
|
my( $class, $list_ref ) = @_; |
14
|
2
|
|
|
|
|
8
|
my $self = bless [], $class; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
7
|
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
|
|
|
|
|
6
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub FETCH { |
25
|
12
|
|
|
12
|
|
5985
|
my( $self ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
12
|
|
|
|
|
25
|
my $index = $self->[CURSOR_COL]++; |
28
|
12
|
|
|
|
|
27
|
$self->[CURSOR_COL] %= $self->_count; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
28
|
return $self->_item( $index ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub STORE { |
34
|
2
|
|
|
2
|
|
5
|
my( $self, $list_ref ) = @_; |
35
|
2
|
50
|
|
|
|
11
|
return unless ref $list_ref eq ref []; |
36
|
2
|
|
|
|
|
6
|
my @shallow_copy = map { $_ } @$list_ref; |
|
4
|
|
|
|
|
12
|
|
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
12
|
$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
|
|
|
|
29
|
$index = defined $index ? $index : $self->_cursor; |
68
|
12
|
|
|
|
|
40
|
$self->[ITEM_COL][ $index ] |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
"Tie::Cycle"; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |