File: ResultSet.pm

package info (click to toggle)
libpithub-perl 0.01043-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: perl: 9,098; makefile: 7
file content (125 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package Pithub::ResultSet;
our $AUTHORITY = 'cpan:PLU';

# Honestly stolen from Array::Iterator, removed all unused parts

use strict;
use warnings;

our $VERSION = '0.01043';

sub new {
    my ( $class, @array ) = @_;
    my $_array   = $array[0];
    my $iterator = {
        _current_index => 0,
        _length        => 0,
        _iteratee      => [],
        _iterated      => 0,
    };
    bless $iterator => $class;
    $iterator->_init( scalar @{$_array}, $_array );
    return $iterator;
}

sub _init {
    my ( $self, $length, $iteratee ) = @_;
    $self->{_current_index} = 0;
    $self->{_length}        = $length;
    $self->{_iteratee}      = $iteratee;
}

sub _get_item {
    my ( $self, $iteratee, $index ) = @_;
    return $iteratee->[$index];
}

## no critic (NamingConventions::Capitalization)
sub getNext {
    my $self = shift;
    $self->{_iterated} = 1;
    $self->{_current_index} < $self->{_length} or return undef;
    return $self->_get_item( $self->{_iteratee}, $self->{_current_index}++ );
}

sub getLength {
    my $self = shift;
    return $self->{_length};
}

1;

=pod

=encoding UTF-8

=head1 NAME

Pithub::ResultSet - Iterate over the results

=head1 VERSION

version 0.01043

=head1 SYNOPSIS

  use Pithub::ResultSet ();

  see L<Pithub::Result>

=head1 DESCRIPTION

Iterate over items in the result-set.

=head1 METHODS

=head2 B<new ($content)>

Constructor

=head2 B<getLength>

Get length of result-set.

=head2 B<getNext>

Get next item in the result-set.

=head1 SEE ALSO

=over 4

=item B<Array::Iterator>

=back

=head1 AUTHOR

H.Merijn Brand E<lt>hmbrand@cpan.orgE<gt>

=head1 ORIGINAL AUTHOR

Stevan Little E<lt>stevan@iinteractive.comE<gt>
perlancar E<lt>perlancar@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Code derived from Array::Iterator, stripped down to only what is required

=head1 AUTHOR

Johannes Plunien <plu@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Johannes Plunien.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__

# ABSTRACT: Iterate over the results