lib/WebService/Braintree/Role/CollectionBuilder.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 2 totaltotal 34.4% 32 / 93 CC 10 SCAR 23.3
CC
10
Cov
32%
__ANON__
20.0
__ANON__
20.0
resource_collection
12.0
CRAP 10.3
« lib/WebService/Braintree/CreditCardGateway.pm ↑ Summary lib/WebService/Braintree/PaymentMethodResult.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package # hide from pause
4 WebService::Braintree::Role::CollectionBuilder;
5  
6 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 22 ▶use WebService::Braintree::Util qw(to_instance_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 22 ▶use WebService::Braintree::GenericSearch;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 22 ▶use WebService::Braintree::PaginatedCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 22 ▶use WebService::Braintree::PaginatedResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 22 ▶use WebService::Braintree::ResourceCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub resource_collection {
Subroutine resource_collection: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my ($self, $opts) = @_;
20  
21 0 my ($ids_resp, $search);
22 0 ▶ if ($opts->{search}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'search'}) { } 0 0 0
23 0 $search = $opts->{search};
24 $ids_resp = $self->gateway->http->post($opts->{ids_url}, {
25 0 search => $search->to_hash,
26 });
27 }
28 else {
29 0 $ids_resp = $self->gateway->http->post($opts->{ids_url});
30 0 $search = WebService::Braintree::GenericSearch->new;
31 }
32  
33 0 ▶ if ($opts->{post_ids}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"post_ids"}) 0 0 0
34 0 $opts->{post_ids}->($ids_resp);
35 }
36  
37 0 my $obj_class = $opts->{inflate}[2];
38 return WebService::Braintree::ResourceCollection->new({
39 response => $ids_resp,
40 0 ▶ callback => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
41 0 my $ids = shift;
42 0 ▶ return [] if scalar @{$ids} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$ids;} == 0 0 0 0
43 0 $search->ids->in($ids);
44  
45 my $response = $self->gateway->http->post($opts->{obj_url}, {
46 0 search => $search->to_hash,
47 });
48 0 ▶ my $body = $response->{$opts->{inflate}[0]} // {};
Condition0%0/2
$$response{$opts->{"inflate"}[0]} // {}
l!l
00
MC/DC0%0/1
$$response{$opts->{"inflate"}[0]} // {}
$$response{$opts->{"inflate"}[0]}
Truth table0%0/2
A
A= $$response{$opts->{"inflate"}[0]}
Aresult
11
00
49 0 ▶ my $attrs = $body->{$opts->{inflate}[1]} // [];
Condition0%0/2
$$body{$opts->{"inflate"}[1]} // []
l!l
00
MC/DC0%0/1
$$body{$opts->{"inflate"}[1]} // []
$$body{$opts->{"inflate"}[1]}
Truth table0%0/2
A
A= $$body{$opts->{"inflate"}[1]}
Aresult
11
00
50 0 return to_instance_array($attrs, "WebService::Braintree::${obj_class}");
51 },
52 0 });
53 }
54  
55 0 ▶sub paginated_collection {
Subroutine paginated_collection: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my ($self, $opts) = @_;
57 0 my $url = $opts->{url};
58 0 my $obj_class = $opts->{inflate}[2];
59  
60 0 ▶ my $method = $opts->{method} // 'get';
Condition0%0/2
$opts->{"method"} // "get"
l!l
00
MC/DC0%0/1
$opts->{"method"} // "get"
$opts->{"method"}
Truth table0%0/2
A
A= $opts->{"method"}
Aresult
11
00
61  
62 0 ▶ return WebService::Braintree::PaginatedCollection->new({ callback => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
63 0 my $page_number = shift;
64  
65 0 my $response;
66 0 ▶ if ($opts->{search}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'search'}) { } 0 0 0
67 $response = $self->gateway->http->$method(
68 "${url}?page=${page_number}", {
69 search => $opts->{search}->to_hash,
70 0 page => $page_number,
71 }
72 );
73 }
74 else {
75 0 $response = $self->gateway->http->$method(
76 "${url}?page=${page_number}",
77 );
78 }
79  
80 0 ▶ my $body = $response->{$opts->{inflate}[0]} // {};
Condition0%0/2
$$response{$opts->{"inflate"}[0]} // {}
l!l
00
MC/DC0%0/1
$$response{$opts->{"inflate"}[0]} // {}
$$response{$opts->{"inflate"}[0]}
Truth table0%0/2
A
A= $$response{$opts->{"inflate"}[0]}
Aresult
11
00
81 0 ▶ my $attrs = $body->{$opts->{inflate}[1]} // [];
Condition0%0/2
$$body{$opts->{"inflate"}[1]} // []
l!l
00
MC/DC0%0/1
$$body{$opts->{"inflate"}[1]} // []
$$body{$opts->{"inflate"}[1]}
Truth table0%0/2
A
A= $$body{$opts->{"inflate"}[1]}
Aresult
11
00
82 return WebService::Braintree::PaginatedResult->new({
83 total_items => $body->{total_items},
84 page_size => $body->{page_size},
85 0 current_page => to_instance_array(
86 $attrs, "WebService::Braintree::${obj_class}"
87 ),
88 });
89 0 }});
90 }
91  
92 22 1;
93 __END__
« lib/WebService/Braintree/CreditCardGateway.pm ↑ Summary lib/WebService/Braintree/PaymentMethodResult.pm »