File Coverage

blib/lib/Pithub/ResultSet.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             package Pithub::ResultSet;
2             our $AUTHORITY = 'cpan:PLU';
3              
4             # Honestly stolen from Array::Iterator, removed all unused parts
5              
6 24     24   177 use strict;
  24         53  
  24         802  
7 24     24   149 use warnings;
  24         52  
  24         7448  
8              
9             our $VERSION = '0.01041';
10              
11             sub new {
12 12     12 1 34 my ( $class, @array ) = @_;
13 12         21 my $_array = $array[0];
14 12         46 my $iterator = {
15             _current_index => 0,
16             _length => 0,
17             _iteratee => [],
18             _iterated => 0,
19             };
20 12         26 bless $iterator => $class;
21 12         19 $iterator->_init( scalar @{$_array}, $_array );
  12         47  
22 12         217 return $iterator;
23             }
24              
25             sub _init {
26 12     12   23 my ( $self, $length, $iteratee ) = @_;
27 12         26 $self->{_current_index} = 0;
28 12         19 $self->{_length} = $length;
29 12         24 $self->{_iteratee} = $iteratee;
30             }
31              
32             sub _get_item {
33 114     114   194 my ( $self, $iteratee, $index ) = @_;
34 114         256 return $iteratee->[$index];
35             }
36              
37             ## no critic (NamingConventions::Capitalization)
38             sub getNext {
39 124     124 1 845 my $self = shift;
40 124         164 $self->{_iterated} = 1;
41 124 100       252 $self->{_current_index} < $self->{_length} or return undef;
42 114         194 return $self->_get_item( $self->{_iteratee}, $self->{_current_index}++ );
43             }
44              
45             sub getLength {
46 2     2 1 51 my $self = shift;
47 2         13 return $self->{_length};
48             }
49              
50             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
69              
70             =head1 DESCRIPTION
71              
72             Iterate over items in the result-set.
73              
74             =head1 METHODS
75              
76             =head2 B
77              
78             Constructor
79              
80             =head2 B
81              
82             Get length of result-set.
83              
84             =head2 B
85              
86             Get next item in the result-set.
87              
88             =head1 SEE ALSO
89              
90             =over 4
91              
92             =item B
93              
94             =back
95              
96             =head1 AUTHOR
97              
98             H.Merijn Brand Ehmbrand@cpan.orgE
99              
100             =head1 ORIGINAL AUTHOR
101              
102             Stevan Little Estevan@iinteractive.comE
103             perlancar Eperlancar@cpan.orgE
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
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__