| 1 | package Pithub::ResultSet; | ||||||||||
| 2 | 24 | our $AUTHORITY = 'cpan:PLU'; | |||||||||
| 3 | |||||||||||
| 4 | # Honestly stolen from Array::Iterator, removed all unused parts | ||||||||||
| 5 | |||||||||||
| 6 | 24 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 24 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 24 | our $VERSION = '0.01041'; | |||||||||
| 10 | |||||||||||
| 11 | sub new { | ||||||||||
| 12 | 12 | ▶ | my ( $class, @array ) = @_; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 12 | my $_array = $array[0]; | |||||||||
| 14 | 12 | my $iterator = { | |||||||||
| 15 | _current_index => 0, | ||||||||||
| 16 | _length => 0, | ||||||||||
| 17 | _iteratee => [], | ||||||||||
| 18 | _iterated => 0, | ||||||||||
| 19 | }; | ||||||||||
| 20 | 12 | bless $iterator => $class; | |||||||||
| 21 | 12 | $iterator->_init( scalar @{$_array}, $_array ); | |||||||||
| 22 | 12 | return $iterator; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | sub _init { | ||||||||||
| 26 | 12 | ▶ | my ( $self, $length, $iteratee ) = @_; | ||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 12 | $self->{_current_index} = 0; | |||||||||
| 28 | 12 | $self->{_length} = $length; | |||||||||
| 29 | 12 | $self->{_iteratee} = $iteratee; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub _get_item { | ||||||||||
| 33 | 114 | ▶ | my ( $self, $iteratee, $index ) = @_; | ||||||||
|
Subroutine
_get_item: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 114 | return $iteratee->[$index]; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | ## no critic (NamingConventions::Capitalization) | ||||||||||
| 38 | sub getNext { | ||||||||||
| 39 | 124 | ▶ | my $self = shift; | ||||||||
|
Subroutine
getNext: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 124 | $self->{_iterated} = 1; | |||||||||
| 41 | 124 | ▶ | $self->{_current_index} < $self->{_length} or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 114 | return $self->_get_item( $self->{_iteratee}, $self->{_current_index}++ ); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub getLength { | ||||||||||
| 46 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
getLength: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 47 | 2 | return $self->{_length}; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 24 | 1; | |||||||||
| 51 | |||||||||||
| 52 | =pod | ||||||||||
| 53 | |||||||||||
| 54 | =encoding UTF-8 | ||||||||||
| 55 | |||||||||||
| 56 | =head1 NAME | ||||||||||
| 57 | |||||||||||
| 58 | Pithub::ResultSet - Iterate over the results | ||||||||||
| 59 | |||||||||||
| 60 | =head1 VERSION | ||||||||||
| 61 | |||||||||||
| 62 | version 0.01041 | ||||||||||
| 63 | |||||||||||
| 64 | =head1 SYNOPSIS | ||||||||||
| 65 | |||||||||||
| 66 | use Pithub::ResultSet (); | ||||||||||
| 67 | |||||||||||
| 68 | see L<Pithub::Result> | ||||||||||
| 69 | |||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||
| 71 | |||||||||||
| 72 | Iterate over items in the result-set. | ||||||||||
| 73 | |||||||||||
| 74 | =head1 METHODS | ||||||||||
| 75 | |||||||||||
| 76 | =head2 B<new ($content)> | ||||||||||
| 77 | |||||||||||
| 78 | Constructor | ||||||||||
| 79 | |||||||||||
| 80 | =head2 B<getLength> | ||||||||||
| 81 | |||||||||||
| 82 | Get length of result-set. | ||||||||||
| 83 | |||||||||||
| 84 | =head2 B<getNext> | ||||||||||
| 85 | |||||||||||
| 86 | Get next item in the result-set. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 SEE ALSO | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item B<Array::Iterator> | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =head1 AUTHOR | ||||||||||
| 97 | |||||||||||
| 98 | H.Merijn Brand E<lt>hmbrand@cpan.orgE<gt> | ||||||||||
| 99 | |||||||||||
| 100 | =head1 ORIGINAL AUTHOR | ||||||||||
| 101 | |||||||||||
| 102 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||||||||
| 103 | perlancar E<lt>perlancar@cpan.orgE<gt> | ||||||||||
| 104 | |||||||||||
| 105 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 106 | |||||||||||
| 107 | Code derived from Array::Iterator, stripped down to only what is required | ||||||||||
| 108 | |||||||||||
| 109 | =head1 AUTHOR | ||||||||||
| 110 | |||||||||||
| 111 | Johannes Plunien <plu@cpan.org> | ||||||||||
| 112 | |||||||||||
| 113 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 114 | |||||||||||
| 115 | This software is copyright (c) 2011 by Johannes Plunien. | ||||||||||
| 116 | |||||||||||
| 117 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 118 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 119 | |||||||||||
| 120 | =cut | ||||||||||
| 121 | |||||||||||
| 122 | __END__ | ||||||||||