CPI/Role/Account.pm

filter: Statementstmt 96.8% 62 / 64 Branchbran 80.0% 8 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 87.3% 83 / 95 CC 8 SCAR 7.7
CC
8
Cov
90%
__ANON__
4.0
__ANON__
2.1
__ANON__
2.1
CRAP 2.2
« CPI/Role/Gateway/FormCheckout.pm ↑ Summary CPI/Role/Cart.pm »
1 package Business::CPI::Role::Account;
2 # ABSTRACT: Manage accounts in the gateway
3 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Business::CPI::Util::Types qw/PhoneNumber DateTime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Type::EmailAddress qw/EmailAddress/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Types::Standard qw/Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.924'; # VERSION
10  
11 # TODO: Validate this? URI.pm seems to accept anything
12 # actually... does this really belong here???
13 2 has return_url => ( is => 'rw' );
14  
15 2 has _gateway => ( is => 'ro', required => 1 );
16  
17 2 has id => ( is => 'rw' );
18 2 has gateway_id => ( is => 'rw' );
19  
20 # Some gateways use the Full Name, others use the first and last separately.
21 # You can set both and let the driver decide what to send.
22 2 has full_name => ( is => 'lazy' );
23 2 has first_name => ( is => 'rw' );
24 2 has last_name => ( is => 'rw' );
25  
26 2 has phone => (
27 is => 'rw',
28 isa => PhoneNumber,
29 coerce => PhoneNumber->coercion,
30 );
31  
32 2 has login => ( is => 'rw' );
33  
34 2 has email => (
35 is => 'rw',
36 isa => EmailAddress,
37 );
38  
39 2 has birthdate => (
40 is => 'rw',
41 isa => DateTime,
42 );
43  
44 2 has registration_date => (
45 is => 'rw',
46 isa => DateTime,
47 );
48  
49 2 has is_business_account => ( is => 'rw', isa => Bool );
50  
51 2 has address => ( is => 'rw' );
52  
53 2 has business => ( is => 'rw' );
54  
55 2 ▶around address => sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
56 2 my $orig = shift;
57 2 my $self = shift;
58  
59 2 ▶ if (my $new_address = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $new_address = shift()) 0 2 2
60 0 return $self->$orig( $self->_inflate_address($new_address) );
61 }
62  
63 2 return $self->$orig();
64 2 };
65  
66 3 ▶around business => sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
67 3 my $orig = shift;
68 3 my $self = shift;
69  
70 3 ▶ if (my $new_business = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $new_business = shift()) 0 3 3
71 0 return $self->$orig( $self->_inflate_business($new_business) );
72 }
73  
74 3 return $self->$orig();
75 2 };
76  
77 11 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
78 11 my $orig = shift;
79 11 my $class = shift;
80 11 my $args = $class->$orig(@_);
81  
82 11 ▶ return $args if !$args->{_gateway}; # let it die elsewhere
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"_gateway"} 1 10 11
83  
84 10 ▶ if (exists $args->{business}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"business"}) 1 9 10
85 1 $args->{business} = $class->_inflate_business($args->{business}, $args->{_gateway});
86 }
87  
88 10 ▶ if (exists $args->{address}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"address"}) 1 9 10
89 1 $args->{address} = $class->_inflate_address($args->{address}, $args->{_gateway});
90 }
91  
92 10 return $args;
93 2 };
94  
95 1 ▶sub _build_full_name {
Subroutine _build_full_name: called CC=1 SCAR=0.0
96 1 my $self = shift;
97  
98 1 return $self->first_name . ' ' . $self->last_name;
99 }
100  
101 1 ▶sub _inflate_address {
Subroutine _inflate_address: called CC=2 SCAR=7.4
102 1 my ($self, $comp, $gateway) = @_;
103  
104 1 ▶ $gateway ||= $self->_gateway;
Condition33%1/3
$gateway ||= $self->_gateway
l!l&&r!l&&!r
100
MC/DC0%0/2
$gateway ||= $self->_gateway
$gateway $self->_gateway
Truth table33%1/3
A ||= B
A= $gatewayB= $self->_gateway
ABresult
1X1
011
000
105  
106 1 $comp->{_gateway} = $gateway;
107  
108 1 return $gateway->account_address_class->new($comp);
109 }
110  
111 1 ▶sub _inflate_business {
Subroutine _inflate_business: called CC=2 SCAR=7.4
112 1 my ($self, $comp, $gateway) = @_;
113  
114 1 ▶ $gateway ||= $self->_gateway;
Condition33%1/3
$gateway ||= $self->_gateway
l!l&&r!l&&!r
100
MC/DC0%0/2
$gateway ||= $self->_gateway
$gateway $self->_gateway
Truth table33%1/3
A ||= B
A= $gatewayB= $self->_gateway
ABresult
1X1
011
000
115  
116 1 $comp->{_gateway} = $gateway;
117  
118 1 return $gateway->account_business_class->new($comp);
119 }
120  
121 2 1;
122  
123 __END__
« CPI/Role/Gateway/FormCheckout.pm ↑ Summary CPI/Role/Cart.pm »