lib/WebService/Braintree/TransparentRedirect/QueryString.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 4 totaltotal 91.8% 68 / 74 CC 9 SCAR 12.3
CC
9
Cov
98%
check_http_status
7.0
validate
2.0
hash_is_forged
2.0
CRAP 3.4
« lib/WebService/Braintree/Role/MakeRequest.pm ↑ Summary lib/WebService/Braintree/_/Transaction.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package # hide from pause
4 WebService::Braintree::TransparentRedirect::QueryString;
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 URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use WebService::Braintree::Digest qw(hexdigest);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶has 'config' => ( is => 'rw', default => sub { WebService::Braintree->configuration});
Subroutine __ANON__: not called CC=1 SCAR=1.2
15  
16 12 ▶sub validate {
Subroutine validate: called CC=2 SCAR=6.9
Pod undocumented
17 12 my($self, $query_string) = @_;
18 12 $self->check_http_status($query_string);
19 5 ▶ confess "ForgedQueryString" if $self->hash_is_forged($query_string);
Branch: 1 branch
BranchTrueFalseTotal
if $self->hash_is_forged($query_string) 3 2 5
20 2 return 1;
21 }
22  
23 13 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
24 13 my ($self, $query_string) = @_;
25 13 my $uri = URI->new;
26 13 $uri->query($query_string);
27 13 return { $uri->query_form};
28 }
29  
30 5 ▶sub hash_is_forged {
Subroutine hash_is_forged: called CC=2 SCAR=6.9
Pod undocumented
31 5 my ($self, $query_string) = @_;
32 5 ▶ if ($query_string =~ /(.*)(&|;)hash=(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query_string =~ /(.*)(&|;)hash=(.*)/) 3 2 5
33 3 my $query_string_without_hash = $1;
34 3 my $hash = $3;
35 3 return $hash ne hexdigest($self->config->private_key, $query_string_without_hash);
36 }
37 2 return 1;
38 }
39  
40 12 ▶sub check_http_status {
Subroutine check_http_status: called CC=7 SCAR=19.5
Pod undocumented
41 12 my($self, $query_string) = @_;
42 12 my $params = $self->parse($query_string);
43 12 ▶ confess "UnexpectedError: expected query string to have an http_status param" unless $params->{'http_status'};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"http_status"} 1 11 12
44 11 ▶ confess "AuthenticationError" if $params->{'http_status'} eq '401';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"http_status"} eq 401 1 10 11
45 10 ▶ confess "AuthorizationError" if $params->{'http_status'} eq '403';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"http_status"} eq 403 2 8 10
46 8 ▶ confess "ServerError" if $params->{'http_status'} eq '500';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"http_status"} eq 500 1 7 8
47 7 ▶ confess "DownForMaintenance" if $params->{'http_status'} eq '503';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"http_status"} eq 503 1 6 7
48 6 ▶ confess "UnexpectedError" if $params->{'http_status'} ne '200';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"http_status"} ne 200 1 5 6
49 }
50  
51 22 __PACKAGE__->meta->make_immutable;
52  
53 22 1;
54 __END__
« lib/WebService/Braintree/Role/MakeRequest.pm ↑ Summary lib/WebService/Braintree/_/Transaction.pm »