examples/HTTP/API/Core/Example/Stripe.pm

filter: Statementstmt 100% 32 / 32 Branchbran 75.0% 6 / 8 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 76.9% 50 / 65 CC 8 SCAR 10.4
CC
8
Cov
85%
new
4.6
__ANON__
4.2
create_customer
2.0
CRAP 2.8
« examples/HTTP/API/Core/Example/Cloudflare.pm ↑ Summary examples/HTTP/API/Core/Example/GitHub.pm »
1 package HTTP::API::Core::Example::Stripe;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use HTTP::API::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::API::Core::Auth qw(bearer_auth);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::API::Core::Form qw(form_urlencode);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶sub new {
Subroutine new: called CC=4 SCAR=15.2
Pod undocumented
11 1 my ($class, %args) = @_;
12 1 my $token = delete $args{token};
13 1 ▶ die "token is required\n" if !defined($token) || $token eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $token or $token eq "" 0 1 1
Condition33%1/3
not defined $token or $token eq ""
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $token or $token eq ""
not defined $token $token eq ""
Truth table33%1/3
not(A) or B
A= not defined $tokenB= $token eq ""
ABresult
1X1
011
000
14  
15 my $api = HTTP::API::Core->new(
16 1 ▶ base_url => delete($args{base_url}) || 'https://api.stripe.com/v1',
Condition50%1/2
delete $args{'base_url'} || 'https://api.stripe.com/v1'
l!l
01
MC/DC0%0/1
delete $args{'base_url'} || 'https://api.stripe.com/v1'
delete $args{'base_url'}
Truth table50%1/2
A
A= delete $args{'base_url'}
Aresult
11
00
17 hooks => { before_request => bearer_auth($token) },
18 %args,
19 );
20 1 return bless { api => $api }, $class;
21 }
22  
23 1 ▶sub customers_pager {
Subroutine customers_pager: called CC=1 SCAR=0.1
Pod undocumented
24 1 my ($self, %query) = @_;
25 return $self->{api}->paginate(
26 '/customers',
27 mode => 'cursor',
28 items => 'data',
29 2 ▶ next => sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
30 2 my ($json) = @_;
31 2 ▶ return undef if !$json->{has_more};
Branch: 1 branch
BranchTrueFalseTotal
unless $json->{"has_more"} 1 1 2
32 1 ▶ return undef if ref($json->{data}) ne 'ARRAY' || !@{ $json->{data} };
Branch: 1 branch
BranchTrueFalseTotal
if ref $json->{"data"} ne "ARRAY" or not @{$json->{"data"};} 0 1 1
Condition33%1/3
ref $json->{"data"} ne "ARRAY" or not @{$json->{"data"};}
l!l&&r!l&&!r
001
MC/DC0%0/2
ref $json->{"data"} ne "ARRAY" or not @{$json->{"data"};}
ref $json->{"data"} ne "ARRAY" not @{$json->{"data"};}
Truth table33%1/3
A or not(B)
A= ref $json->{"data"} ne "ARRAY"B= not @{$json->{"data"};}
ABresult
1X1
011
000
33 1 return $json->{data}[-1]{id};
34 },
35 1 cursor_param => 'starting_after',
36 query => \%query,
37 );
38 }
39  
40 2 ▶sub create_customer {
Subroutine create_customer: called CC=2 SCAR=6.9
Pod undocumented
41 2 my ($self, %args) = @_;
42 2 my $idempotency_key = delete $args{idempotency_key};
43 2 my $content = form_urlencode(\%args);
44  
45 return $self->{api}->post(
46 2 ▶ '/customers',
Branch: 1 branch
BranchTrueFalseTotal
defined $idempotency_key ? : 1 1 2
47 headers => { 'content-type' => 'application/x-www-form-urlencoded' },
48 content => $content,
49 (defined($idempotency_key) ? (
50 idempotency => {
51 key => $idempotency_key,
52 header => 'Idempotency-Key',
53 },
54 ) : ()),
55 );
56 }
57  
58 1 1;
« examples/HTTP/API/Core/Example/Cloudflare.pm ↑ Summary examples/HTTP/API/Core/Example/GitHub.pm »