Braintree/ResourceCollection.pm

filter: Statementstmt 23.0% 9 / 39 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 12.5% 1 / 8 Podpod 0.0% 0 / 7 totaltotal 15.6% 10 / 64 CC 7 SCAR 21.7
CC
7
Cov
18%
each
20.0
is_success
6.0
first
6.0
CRAP 8.8
« Braintree/Digest.pm ↑ Summary Braintree/MerchantAccount.pm »
1 package Net::Braintree::ResourceCollection;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 extends "Net::Braintree::ResultObject";
4  
5 1 has 'response' => (is => 'rw');
6 1 has 'ids' => (is => 'rw');
7 1 has 'page_size' => (is => 'rw');
8 1 has 'callback' => (is => 'rw');
9  
10 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my ($self, $response, $callback) = @_;
12 0 $self->response($response);
13 0 $self->ids($response->{search_results}->{ids});
14 0 $self->page_size($response->{search_results}->{page_size});
15 0 $self->callback($callback);
16 0 return $self;
17 }
18  
19 0 ▶sub is_success {
Subroutine is_success: not called CC=2 SCAR=17.9
Pod undocumented
20 0 my $self = shift;
21 0 ▶ return 1 unless $self->response->{'api_error_response'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->response->{"api_error_response"} 0 0 0
22 0 return 0;
23 }
24  
25 0 ▶sub first {
Subroutine first: not called CC=2 SCAR=17.9
Pod undocumented
26 0 my $self = shift;
27 0 ▶ return undef if $self->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_empty 0 0 0
28 0 my $first_id = $self->ids->[0];
29 0 return $self->callback->([$first_id])->[0];
30 }
31  
32 0 ▶sub is_empty {
Subroutine is_empty: not called CC=1 SCAR=6.9
Pod undocumented
33 0 my $self = shift;
34 0 $self->maximum_size == 0;
35 }
36  
37 0 ▶sub maximum_size {
Subroutine maximum_size: not called CC=1 SCAR=6.9
Pod undocumented
38 0 my $self = shift;
39 0 return (scalar @{$self->ids});
40 }
41  
42 0 ▶sub each {
Subroutine each: not called CC=4 SCAR=30.0
Pod undocumented
43 0 my ($self, $block) = @_;
44 0 my @page = ();
45  
46 0 ▶ for(my $count = 0; $count < $self->maximum_size; $count++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $self->maximum_size) 0 0 0
47 0 push(@page, $self->ids->[$count]);
48 0 ▶ if((scalar @page) == $self->page_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @page == $self->page_size) 0 0 0
49 0 $self->execute_block_for_page($block, @page);
50 0 @page = ();
51 }
52 }
53  
54 0 ▶ $self->execute_block_for_page($block, @page) if(scalar(@page) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @page > 0 0 0 0
55 }
56  
57 0 ▶sub execute_block_for_page {
Subroutine execute_block_for_page: not called CC=2 SCAR=17.9
Pod undocumented
58 0 my ($self, $block, @page) = @_;
59 0 my $resources = $self->callback->([@page]);
60 0 for my $resource (@$resources) {
61 0 $block->($resource);
62 }
63 }
64  
65 1 1;
« Braintree/Digest.pm ↑ Summary Braintree/MerchantAccount.pm »