lib/WebService/Braintree/PaginatedCollection.pm

filter: Statementstmt 50.0% 12 / 24 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 51.6% 16 / 31 CC 3 SCAR 18.7
CC
3
Cov
46%
each
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.5
« lib/WebService/Braintree/DisputeGateway.pm ↑ Summary lib/WebService/Braintree/PayPalAccountGateway.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package WebService::Braintree::PaginatedCollection;
4 22 $WebService::Braintree::PaginatedCollection::VERSION = '1.7';
5 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 WebService::Braintree::PaginatedCollection
11  
12 =head1 PURPOSE
13  
14 This class provides a way of iterating over a paginated collection of resources.
15 It will lazily retrieve the objects from Braintree.
16  
17 This class will only be created as part of a L<response|WebService::Braintree::Result> or L<error response|WebService::Braintree::ErrorResult>.
18  
19 =cut
20  
21 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 =head1 METHODS
24  
25 =cut
26  
27 22 has callback => (is => 'ro');
28  
29 =head2 each($block)
30  
31 This takes a subroutine and executes that subroutine for each page of results
32 in this collection.
33  
34 =cut
35  
36 0 ▶sub each {
Subroutine each: not called CC=3 SCAR=24.8
Pod documented
37 0 my ($self, $block) = @_;
38  
39 0 my $current_page = 0;
40 0 my $total_items = 0;
41  
42 0 while (1) {
43 0 $current_page += 1;
44  
45 0 my $result = $self->callback->($current_page);
46 0 $total_items = $result->total_items;
47  
48 0 foreach my $item (@{$result->current_page}) {
49 0 $block->($item);
50 }
51  
52 0 ▶ last if $current_page * $result->page_size >= $total_items;
Branch: 1 branch
BranchTrueFalseTotal
if $current_page * $result->page_size >= $total_items 0 0 0
53 }
54  
55 0 return;
56 }
57  
58 22 __PACKAGE__->meta->make_immutable;
59  
60 22 1;
61 __END__
« lib/WebService/Braintree/DisputeGateway.pm ↑ Summary lib/WebService/Braintree/PayPalAccountGateway.pm »