line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::GoCardless::Paginator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::GoCardless::Paginator |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A class for pagination through gocardless data returned as a list. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
19
|
|
|
19
|
|
117
|
use strict; |
|
19
|
|
|
|
|
35
|
|
|
19
|
|
|
|
|
510
|
|
14
|
19
|
|
|
19
|
|
91
|
use warnings; |
|
19
|
|
|
|
|
40
|
|
|
19
|
|
|
|
|
408
|
|
15
|
|
|
|
|
|
|
|
16
|
19
|
|
|
19
|
|
88
|
use Moo; |
|
19
|
|
|
|
|
34
|
|
|
19
|
|
|
|
|
87
|
|
17
|
|
|
|
|
|
|
extends 'Business::GoCardless::Resource'; |
18
|
19
|
|
|
19
|
|
5765
|
use JSON (); |
|
19
|
|
|
|
|
49
|
|
|
19
|
|
|
|
|
405
|
|
19
|
|
|
|
|
|
|
|
20
|
19
|
|
|
19
|
|
102
|
use Business::GoCardless::Bill; |
|
19
|
|
|
|
|
39
|
|
|
19
|
|
|
|
|
434
|
|
21
|
19
|
|
|
19
|
|
100
|
use Business::GoCardless::PreAuthorization; |
|
19
|
|
|
|
|
46
|
|
|
19
|
|
|
|
|
413
|
|
22
|
19
|
|
|
19
|
|
95
|
use Business::GoCardless::Payout; |
|
19
|
|
|
|
|
51
|
|
|
19
|
|
|
|
|
409
|
|
23
|
19
|
|
|
19
|
|
94
|
use Business::GoCardless::User; |
|
19
|
|
|
|
|
47
|
|
|
19
|
|
|
|
|
467
|
|
24
|
19
|
|
|
19
|
|
118
|
use Business::GoCardless::Paginator; |
|
19
|
|
|
|
|
39
|
|
|
19
|
|
|
|
|
12460
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
client |
29
|
|
|
|
|
|
|
objects |
30
|
|
|
|
|
|
|
class |
31
|
|
|
|
|
|
|
info |
32
|
|
|
|
|
|
|
links |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has [ qw/ |
37
|
|
|
|
|
|
|
client |
38
|
|
|
|
|
|
|
objects |
39
|
|
|
|
|
|
|
class |
40
|
|
|
|
|
|
|
/ ] => ( |
41
|
|
|
|
|
|
|
is => 'rw' |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has info => ( |
45
|
|
|
|
|
|
|
is => 'rw', |
46
|
|
|
|
|
|
|
required => 1, |
47
|
|
|
|
|
|
|
coerce => sub { |
48
|
|
|
|
|
|
|
my ( $info ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return {} if ! $info; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ( $info =~ /^[{\[]/ ) { |
53
|
|
|
|
|
|
|
# defensive decoding |
54
|
|
|
|
|
|
|
eval { $info = JSON->new->decode( $info ) }; |
55
|
|
|
|
|
|
|
$@ && do { return "Failed to parse JSON response ($info): $@"; }; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return $info; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has links => ( |
62
|
|
|
|
|
|
|
is => 'rw', |
63
|
|
|
|
|
|
|
required => 1, |
64
|
|
|
|
|
|
|
coerce => sub { |
65
|
|
|
|
|
|
|
my ( $links ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $links_hash = {}; |
68
|
|
|
|
|
|
|
return $links_hash if ! $links; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
foreach my $link ( split( /, /,$links ) ) { |
71
|
|
|
|
|
|
|
my ( $rel,$url ) = reverse split( />; /,$link ); |
72
|
|
|
|
|
|
|
$url =~ s/^/; |
73
|
|
|
|
|
|
|
$rel =~ s/^.*?"([A-z]+)"/$1/; |
74
|
|
|
|
|
|
|
$links_hash->{$rel} = $url; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return $links_hash; |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 PAGER METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
next |
84
|
|
|
|
|
|
|
previous |
85
|
|
|
|
|
|
|
first |
86
|
|
|
|
|
|
|
last |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Return the objects from the next/previous/first/last page: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my @objects = $Paginator->next; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub next { |
95
|
3
|
|
|
3
|
0
|
13162
|
my ( $self ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
3
|
100
|
50
|
|
|
6
|
if ( my @objects = @{ $self->objects // [] } ) { |
|
3
|
|
|
|
|
26
|
|
98
|
|
|
|
|
|
|
# get the next chunk and return the current chunk |
99
|
2
|
|
|
|
|
8
|
$self->objects( $self->_objects_from_page( 'next' ) ); |
100
|
2
|
|
|
|
|
14
|
return @objects; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
5
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub previous { |
107
|
1
|
|
|
1
|
0
|
7501
|
my ( $self ) = @_; |
108
|
1
|
|
|
|
|
3
|
return @{ $self->_objects_from_page( 'previous' ) }; |
|
1
|
|
|
|
|
3
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub first { |
112
|
1
|
|
|
1
|
0
|
609
|
my ( $self ) = @_; |
113
|
1
|
|
|
|
|
4
|
return @{ $self->_objects_from_page( 'first' ) }; |
|
1
|
|
|
|
|
3
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub last { |
117
|
1
|
|
|
1
|
0
|
575
|
my ( $self ) = @_; |
118
|
1
|
|
|
|
|
3
|
return @{ $self->_objects_from_page( 'last' ) }; |
|
1
|
|
|
|
|
3
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _objects_from_page { |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
5
|
|
14
|
my ( $self,$page ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# see if we have more data to get |
126
|
5
|
50
|
|
|
|
120
|
if ( my $url = $self->links->{$page} ) { |
127
|
|
|
|
|
|
|
|
128
|
5
|
|
|
|
|
58
|
my ( $data,$links,$info ) = $self->client->api_get( $url ); |
129
|
|
|
|
|
|
|
|
130
|
5
|
|
|
|
|
20
|
my $class = $self->class; |
131
|
12
|
|
|
|
|
77
|
my @objects = map { $class->new( client => $self->client,%{ $_ } ) } |
|
12
|
|
|
|
|
210
|
|
132
|
5
|
|
|
|
|
10
|
@{ $data }; |
|
5
|
|
|
|
|
12
|
|
133
|
|
|
|
|
|
|
|
134
|
5
|
|
|
|
|
145
|
$self->links( $links ); |
135
|
5
|
|
|
|
|
112
|
$self->info( $info ); |
136
|
5
|
|
|
|
|
80
|
return [ @objects ]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return []; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Lee Johnson - C |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
147
|
|
|
|
|
|
|
the same terms as Perl itself. If you would like to contribute documentation, |
148
|
|
|
|
|
|
|
features, bug fixes, or anything else then please raise an issue / pull request: |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
https://github.com/Humanstate/business-gocardless |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |