1Net::CLI::Interact::RolUes:e:rItCeornattroirb(u3t)ed PerNletD:o:cCuLmIe:n:tIanttieornact::Role::Iterator(3)
2
3
4

NAME

6       Net::CLI::Interact::Role::Iterator - Array-based Iterator
7

SYNOPSIS

9        my $count = $iter->count;
10
11        $iter->reset;
12        while ( $iter->has_next ) {
13           print $iter->next;
14        }
15

DESCRIPTION

17       This module implements an array-based iterator which may be mixed-in to
18       add management of a sequence of elements and processing of that
19       sequence.
20
21       The iterator is inspired by MooseX::Iterator but limited to arrays and
22       adds many other facilities. The following section describes the methods
23       provided by this class.
24

USAGE

26       The slot used for storing iterator elements is named "_sequence" and
27       you should write your consuming class to marshall data into this slot,
28       perhaps via "BUILD" or "init_arg". For example:
29
30        has '+_sequence' => (
31           isa => 'ArrayRef[Thingy]',
32           init_arg => 'things',
33        );
34

INTERFACE

36   count
37       The number of elements currently stored in the iterator. Note that this
38       is of course not the same as the index of the last item in the iterator
39       (which is 0-based)
40
41   first
42       Returns the first item in the iterator.
43
44   last
45       Returns the last item in the iterator.
46
47   item_at( $pos )
48       Returns the item at the given position in the iterator, or throws an
49       exception if $pos is past the end of the iterator. The position is
50       0-based.
51
52   insert_at( $pos, $iter )
53       Inserts the contents of the passed iterator starting at (not after) the
54       position given. The passed iterator must also be a consumer of this
55       role. The position is 0-based.
56
57   append( $iter )
58       Shorthand for "insert_at" when you want to add the contents of the
59       passed iterator after the end of the sequence.
60
61   idx( $pos? )
62       Returns the index (0-based) of the current iterator cursor, or sets the
63       cursor if a position (again, 0-based) is passed.
64
65       An exception is thrown if you attempt to read the cursor position
66       before having read any elements from the iterator, or if the iterator
67       is empty.
68
69   next
70       Returns the next item in the iterator sequence, and advances the
71       cursor.  Throws an exception if you have already reached the end of the
72       sequence.
73
74   has_next
75       Returns true if there are further elements to be read from the
76       iterator.
77
78   peek
79       Returns the next item in the sequence without advancing the position of
80       the cursor. It returns "undef" if you are already at the end of the
81       sequence.
82
83   reset
84       Resets the cursor so you can iterate through the sequence of elements
85       again.
86
87
88
89perl v5.32.0                      2020-07-N2e8t::CLI::Interact::Role::Iterator(3)
Impressum