line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::Fixflo::Paginator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::Fixflo::Paginator |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A class for pagination through fixflo data returned as a list. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
16
|
|
|
16
|
|
102
|
use strict; |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
446
|
|
14
|
16
|
|
|
16
|
|
73
|
use warnings; |
|
16
|
|
|
|
|
29
|
|
|
16
|
|
|
|
|
357
|
|
15
|
|
|
|
|
|
|
|
16
|
16
|
|
|
16
|
|
65
|
use Moo; |
|
16
|
|
|
|
|
29
|
|
|
16
|
|
|
|
|
98
|
|
17
|
16
|
|
|
16
|
|
5277
|
use JSON (); |
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
357
|
|
18
|
|
|
|
|
|
|
|
19
|
16
|
|
|
16
|
|
6737
|
use Business::Fixflo::Issue; |
|
16
|
|
|
|
|
57
|
|
|
16
|
|
|
|
|
5411
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
client |
24
|
|
|
|
|
|
|
objects |
25
|
|
|
|
|
|
|
class |
26
|
|
|
|
|
|
|
links |
27
|
|
|
|
|
|
|
total_items |
28
|
|
|
|
|
|
|
total_pages |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has [ qw/ client objects class links total_items total_pages / ] => ( |
33
|
|
|
|
|
|
|
is => 'rw' |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 PAGER METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
next |
39
|
|
|
|
|
|
|
previous |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Return the current set of objects and then gets the next/previous page: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @objects = @{ $Paginator->next }; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 objects |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Gets the current set of objects |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @objects = @{ $Paginator->objects }; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 links |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns a hash that has the NextURL and previousURL within |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $urls = $Paginator->links |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub next { |
60
|
4
|
|
|
4
|
0
|
3659
|
my ( $self ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
4
|
50
|
50
|
|
|
5
|
if ( my @objects = @{ $self->objects // [] } ) { |
|
4
|
|
|
|
|
22
|
|
63
|
|
|
|
|
|
|
# get the next chunk and return the current chunk |
64
|
4
|
|
|
|
|
10
|
$self->objects( $self->_objects_from_page( 'next' ) ); |
65
|
4
|
|
|
|
|
23
|
return [ @objects ]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub previous { |
72
|
1
|
|
|
1
|
0
|
8058
|
my ( $self ) = @_; |
73
|
1
|
|
|
|
|
47
|
return $self->_objects_from_page( 'previous' ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _objects_from_page { |
77
|
|
|
|
|
|
|
|
78
|
5
|
|
|
5
|
|
11
|
my ( $self,$page ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# see if we have more data to get |
81
|
5
|
50
|
|
|
|
18
|
if ( my $url = $self->links->{$page} ) { |
82
|
|
|
|
|
|
|
|
83
|
5
|
|
|
|
|
18
|
my $data = $self->client->api_get( $url ); |
84
|
5
|
|
|
|
|
31
|
my $class = $self->class; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my @objects = map { |
87
|
|
|
|
|
|
|
$class->new( |
88
|
|
|
|
|
|
|
client => $self->client, |
89
|
|
|
|
|
|
|
# $_ might be a list of urls or list of hashes |
90
|
15
|
100
|
|
|
|
221
|
( ref( $_ ) ? ( %{ $_ } ) : ( url => $_ ) ), |
|
6
|
|
|
|
|
92
|
|
91
|
|
|
|
|
|
|
) |
92
|
5
|
|
|
|
|
7
|
} @{ $data->{Items} }; |
|
5
|
|
|
|
|
10
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->links({ |
95
|
|
|
|
|
|
|
next => $data->{NextURL}, |
96
|
|
|
|
|
|
|
previous => $data->{PreviousURL}, |
97
|
5
|
|
|
|
|
51
|
}); |
98
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
22
|
return [ @objects ]; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return []; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Lee Johnson - C |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
110
|
|
|
|
|
|
|
the same terms as Perl itself. If you would like to contribute documentation, |
111
|
|
|
|
|
|
|
features, bug fixes, or anything else then please raise an issue / pull request: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
https://github.com/Humanstate/business-fixflo |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# vim: ts=4:sw=4:et |