UPS/Payment.pm

filter: Statementstmt 76.9% 30 / 39 Branchbran 18.1% 4 / 22 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 51.1% 43 / 84 CC 15 SCAR 34.5
CC
15
Cov
50%
__ANON__
54.7
as_hash
17.9
BEGIN
1.0
CRAP 31.4
↑ Summary UPS/Address.pm »
1 package Net::Async::Webservice::UPS::Payment;
2 5 $Net::Async::Webservice::UPS::Payment::VERSION = '1.1.4';
3 {
4 5 $Net::Async::Webservice::UPS::Payment::DIST = 'Net-Async-Webservice-UPS';
5 }
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Types::Standard qw(Str Bool Enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Net::Async::Webservice::UPS::Types ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: a payment method for UPS shipments
13  
14  
15 5 has method => (
16 is => 'ro',
17 isa => Enum[qw(prepaid third_party freight_collect)],
18 default => 'prepaid',
19 );
20  
21  
22 5 has account_number => (
23 is => 'ro',
24 isa => Str,
25 required => 0,
26 );
27  
28  
29 5 has credit_card => (
30 is => 'ro',
31 isa => CreditCard,
32 required => 0,
33 );
34  
35  
36 5 has address => (
37 is => 'ro',
38 isa => Address,
39 required => 0,
40 );
41  
42  
43 1 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=10 SCAR=40.0
44 1 my ($orig,$class,@etc) = @_;
45 1 my $args = $class->$orig(@etc);
46  
47 1 ▶ if ($args->{method} eq 'prepaid') {
Branch: 3 branches
BranchTrueFalseTotal
if ($args->{'method'} eq 'prepaid') { } 1 0 1
elsif ($args->{'method'} eq 'third_party') { } 0 0 0
elsif ($args->{'method'} eq 'freight_collect') { } 0 0 0
48 1 ▶ if (not ($args->{credit_card} or $args->{account_number})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"credit_card"} or $args->{"account_number"}) 0 1 1
Condition33%1/3
$args->{"credit_card"} or $args->{"account_number"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{"credit_card"} or $args->{"account_number"}
$args->{"credit_card"} $args->{"account_number"}
Truth table33%1/3
A or B
A= $args->{"credit_card"}B= $args->{"account_number"}
ABresult
1X1
011
000
49 0 require Carp;
50 0 Carp::croak "account_number or credit_card required when payment method is 'prepaid'";
51 }
52 }
53 elsif ($args->{method} eq 'third_party') {
54 0 ▶ if (not ($args->{account_number} and $args->{address})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"account_number"} and $args->{"address"}) 0 0 0
Condition0%0/3
$args->{"account_number"} and $args->{"address"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"account_number"} and $args->{"address"}
$args->{"account_number"} $args->{"address"}
Truth table0%0/3
A and B
A= $args->{"account_number"}B= $args->{"address"}
ABresult
0X0
100
111
55 0 require Carp;
56 0 Carp::croak "account_number and address required when payment method is 'third_party'";
57 }
58 }
59 elsif ($args->{method} eq 'freight_collect') {
60 0 ▶ if (not ($args->{account_number} and $args->{address})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"account_number"} and $args->{"address"}) 0 0 0
Condition0%0/3
$args->{"account_number"} and $args->{"address"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"account_number"} and $args->{"address"}
$args->{"account_number"} $args->{"address"}
Truth table0%0/3
A and B
A= $args->{"account_number"}B= $args->{"address"}
ABresult
0X0
100
111
61 0 require Carp;
62 0 Carp::croak "account_number required when payment method is 'freight_collect'";
63 }
64 }
65  
66 1 return $args;
67 5 };
68  
69  
70 3 ▶sub as_hash {
Subroutine as_hash: called CC=6 SCAR=28.9
Pod documented
71 3 my ($self) = @_;
72  
73 return {
74 ($self->method eq 'prepaid') ? ( Prepaid => {
75 BillShipper => {
76 ( $self->account_number ? ( AccountNumber => $self->account_number ) :
77 ( $self->credit_card ? ( CreditCard => $self->credit_card->as_hash ) :
78 () ) ),
79 },
80 } ) :
81 ($self->method eq 'third_party') ? ( BillThirdParty => {
82 BillThirdPartyShipper => {
83 AccountNumber => $self->account_number,
84 ThirdPartyShipper => $self->address->as_hash('Ship'),
85 },
86 } ) :
87 ($self->method eq 'freight_collect') ? ( FreightCollect => {
88 BillReceiver => {
89 AccountNumber => $self->account_number,
90 0 ▶ %{$self->address->as_hash('Ship')},
Branch: 5 branches
BranchTrueFalseTotal
$self->method eq 'prepaid' ? : 3 0 3
$self->account_number ? : 3 0 3
$self->credit_card ? : 0 0 0
$self->method eq 'third_party' ? : 0 0 0
$self->method eq 'freight_collect' ? : 0 0 0
91 },
92 } ) : ()
93 };
94 }
95  
96 5 1;
97  
98 __END__
↑ Summary UPS/Address.pm »