| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 50 |  |  | 50 |  | 506 | use v5.14; | 
|  | 50 |  |  |  |  | 135 |  | 
| 2 | 50 |  |  | 50 |  | 234 | use warnings; | 
|  | 50 |  |  |  |  | 78 |  | 
|  | 50 |  |  |  |  | 2138 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 NAME | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | Attean::ListIterator - Iterator implementation backed by a list/array of values | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 VERSION | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | This document describes Attean::ListIterator version 0.033 | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | use v5.14; | 
| 15 |  |  |  |  |  |  | use Attean; | 
| 16 |  |  |  |  |  |  | my @values = map { Attean::Literal->new($_) } (1,2,3); | 
| 17 |  |  |  |  |  |  | my $iter = Attean::ListIterator->new( | 
| 18 |  |  |  |  |  |  | values => \@values, | 
| 19 |  |  |  |  |  |  | item_type => 'Attean::API::Term', | 
| 20 |  |  |  |  |  |  | ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | say $iter->next->value; # 1 | 
| 23 |  |  |  |  |  |  | say $iter->next->value; # 2 | 
| 24 |  |  |  |  |  |  | say $iter->next->value; # 3 | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | The Attean::ListIterator class represents a typed iterator. | 
| 29 |  |  |  |  |  |  | It conforms to the L<Attean::API::RepeatableIterator|Attean::API::Iterator> role. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | The Attean::ListIterator constructor requires two named arguments: | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =over 4 | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =item values | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | An array reference containing the items to iterate over. | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =item item_type | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | A string representing the type of the items that will be returned from the | 
| 42 |  |  |  |  |  |  | iterator. | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =back | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head1 METHODS | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =over 4 | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =cut | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | use Moo; | 
| 53 | 50 |  |  | 50 |  | 272 | use Scalar::Util qw(blessed); | 
|  | 50 |  |  |  |  | 144 |  | 
|  | 50 |  |  |  |  | 279 |  | 
| 54 | 50 |  |  | 50 |  | 14007 | use Type::Tiny::Role; | 
|  | 50 |  |  |  |  | 122 |  | 
|  | 50 |  |  |  |  | 2152 |  | 
| 55 | 50 |  |  | 50 |  | 268 | use Types::Standard qw(ArrayRef Int); | 
|  | 50 |  |  |  |  | 124 |  | 
|  | 50 |  |  |  |  | 1789 |  | 
| 56 | 50 |  |  | 50 |  | 278 | use namespace::clean; | 
|  | 50 |  |  |  |  | 104 |  | 
|  | 50 |  |  |  |  | 374 |  | 
| 57 | 50 |  |  | 50 |  | 38218 |  | 
|  | 50 |  |  |  |  | 99 |  | 
|  | 50 |  |  |  |  | 342 |  | 
| 58 |  |  |  |  |  |  | has values => (is => 'ro', isa => ArrayRef, required => 1); | 
| 59 |  |  |  |  |  |  | has current => (is => 'rw', isa => Int, init_arg => undef, default => 0); | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | my $self	 = shift; | 
| 62 |  |  |  |  |  |  | my $role	= $self->item_type; | 
| 63 |  |  |  |  |  |  | foreach my $item (@{ $self->values }) { | 
| 64 |  |  |  |  |  |  | if (Role::Tiny->is_role($role)) { | 
| 65 |  |  |  |  |  |  | die "ListIterator item <$item> is not a $role" unless (blessed($item) and $item->does($role)); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =item C<< reset >> | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Resets the iterator's internal state so that iteration begins again at the | 
| 73 |  |  |  |  |  |  | beginning of the values array. | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =cut | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | my $self	= shift; | 
| 78 |  |  |  |  |  |  | $self->current(0); | 
| 79 |  |  |  |  |  |  | } | 
| 80 | 807 |  |  | 807 | 1 | 837 |  | 
| 81 | 807 |  |  |  |  | 8587 | =item C<< next >> | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Returns the iterator's next item, or undef upon reaching the end of iteration. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =cut | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | my $self	= shift; | 
| 88 |  |  |  |  |  |  | my $list	= $self->values; | 
| 89 |  |  |  |  |  |  | my $index	= $self->current; | 
| 90 |  |  |  |  |  |  | my $item	= $list->[$index]; | 
| 91 | 4704 |  |  | 4704 | 1 | 177599 | return unless defined($item); | 
| 92 | 4704 |  |  |  |  | 6469 | $self->current(1+$index); | 
| 93 | 4704 |  |  |  |  | 61498 | return $item; | 
| 94 | 4704 |  |  |  |  | 19921 | } | 
| 95 | 4704 | 100 |  |  |  | 8337 |  | 
| 96 | 3603 |  |  |  |  | 41561 | =item C<< size >> | 
| 97 | 3603 |  |  |  |  | 66250 |  | 
| 98 |  |  |  |  |  |  | Returns the number of elements still remaining in the iterator until it is | 
| 99 |  |  |  |  |  |  | fully consumed or until C<< reset >> is called. | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =cut | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | my $self	= shift; | 
| 104 |  |  |  |  |  |  | return scalar(@{ $self->values }) - $self->current; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | with 'Attean::API::RepeatableIterator'; | 
| 108 | 1 |  |  | 1 | 1 | 3 | } | 
| 109 | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 110 |  |  |  |  |  |  | 1; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =back | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 BUGS | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | Please report any bugs or feature requests to through the GitHub web interface | 
| 118 |  |  |  |  |  |  | at L<https://github.com/kasei/attean/issues>. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =head1 AUTHOR | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | Gregory Todd Williams  C<< <gwilliams@cpan.org> >> | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | Copyright (c) 2014--2022 Gregory Todd Williams. | 
| 131 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it under | 
| 132 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =cut |