1Tie::Cycle(3)         User Contributed Perl Documentation        Tie::Cycle(3)
2
3
4

NAME

6       Tie::Cycle - Cycle through a list of values via a scalar.
7

SYNOPSIS

9               use v5.10;
10               use Tie::Cycle;
11
12               tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ];
13
14               say $cycle; # FFFFFF
15               say $cycle; # 000000
16               say $cycle; # FFFF00
17               say $cycle; # FFFFFF  back to the beginning
18
19               (tied $cycle)->reset;  # back to the beginning
20

DESCRIPTION

22       You use "Tie::Cycle" to go through a list over and over again.  Once
23       you get to the end of the list, you go back to the beginning.  You
24       don't have to worry about any of this since the magic of tie does that
25       for you.
26
27       The tie takes an array reference as its third argument. The tie should
28       succeed unless the argument is not an array reference.  Previous
29       versions required you to use an array that had more than one element
30       (what's the pointing of looping otherwise?), but I've removed that
31       restriction since the number of elements you want to use may change
32       depending on the situation.
33
34       During the tie, this module makes a shallow copy of the array
35       reference. If the array reference contains references, and those
36       references are changed after the tie, the elements of the cycle will
37       change as well. See the included test.pl script for an example of this
38       effect.
39

OBJECT METHODS

41       You can call methods on the underlying object (which you access with
42       "tied()" ).
43
44       reset
45           Roll the iterator back to the starting position. The next access
46           will give the first element in the list.
47
48       previous
49           Give the previous element. This does not affect the current
50           position.
51
52       next
53           Give the next element. This does not affect the current position.
54           You can peek at the next element if you like.
55

SOURCE AVAILABILITY

57       This module is on Github:
58
59               https://github.com/briandfoy/tie-cycle
60

AUTHOR

62       brian d foy, "<bdfoy@cpan.org>"
63
65       Copyright © 2000-2022, brian d foy "<bdfoy@cpan.org>". All rights
66       reserved.  This software is available under the Artistic License 2.0.
67
68
69
70perl v5.34.0                      2022-01-21                     Tie::Cycle(3)
Impressum