WWW/eNom/Contact.pm

filter: Statementstmt 71.6% 53 / 74 Branchbran 14.2% 4 / 28 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 75.0% 12 / 16 Podpod 66.6% 2 / 3 totaltotal 58.0% 76 / 131 CC 20 SCAR 33.6
CC
20
Cov
56%
construct_creation_request
72.0
__ANON__
42.0
construct_from_response
30.0
CRAP 28.8
« WWW/eNom/DomainRequest/Registration.pm ↑ Summary WWW/eNom/Role/Command/Domain.pm »
1 package WWW::eNom::Contact;
2  
3 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 54 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 54 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 54 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 54 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 54 ▶use WWW::eNom::Types qw( RawContactType EmailAddress HashRef PhoneNumber Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 54 ▶use WWW::eNom::PhoneNumber;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 54 ▶use Data::Util qw( is_string );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 54 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 54 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 54 our $VERSION = 'v2.7.0'; # VERSION
20 # ABSTRACT: Representation of eNom Contact
21  
22 54 has 'first_name' => (
23 is => 'rw',
24 isa => Str,
25 required => 1,
26 );
27  
28 54 has 'last_name' => (
29 is => 'rw',
30 isa => Str,
31 required => 1,
32 );
33  
34 54 has 'organization_name' => (
35 is => 'rw',
36 isa => Str,
37 predicate => 'has_organization_name',
38 clearer => 'clear_organization_name',
39 );
40  
41 54 has 'job_title' => (
42 is => 'rw',
43 isa => Str,
44 predicate => 'has_job_title',
45 clearer => 'clear_job_title',
46 );
47  
48 54 has 'address1' => (
49 is => 'rw',
50 isa => Str,
51 required => 1,
52 );
53  
54 54 has 'address2' => (
55 is => 'rw',
56 isa => Str,
57 predicate => 'has_address2',
58 clearer => 'clear_address2',
59 );
60  
61 54 has 'city' => (
62 is => 'rw',
63 isa => Str,
64 required => 1,
65 );
66  
67 54 has 'state' => (
68 is => 'rw',
69 isa => Str,
70 predicate => 'has_state',
71 clearer => 'clear_state',
72 );
73  
74 54 has 'country' => (
75 is => 'rw',
76 isa => Str,
77 required => 1,
78 );
79  
80 54 has 'zipcode' => (
81 is => 'rw',
82 isa => Str,
83 required => 1,
84 );
85  
86 54 has 'email' => (
87 is => 'rw',
88 isa => EmailAddress,
89 required => 1,
90 );
91  
92 54 has 'phone_number' => (
93 is => 'rw',
94 isa => PhoneNumber,
95 required => 1,
96 coerce => 1,
97 );
98  
99 54 has 'fax_number' => (
100 is => 'rw',
101 isa => PhoneNumber,
102 predicate => 'has_fax_number',
103 clearer => 'clear_fax_number',
104 coerce => 1,
105 );
106  
107 47 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
108 47 my $self = shift;
109  
110 47 ▶ if( $self->has_organization_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_organization_name) 3 44 47
111 3 ▶ if( !$self->has_job_title || !$self->has_fax_number ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->has_job_title && $self->has_fax_number) 2 1 3
Condition100%3/3
$self->has_job_title && $self->has_fax_number
!ll&&!rl&&r
111
MC/DC100%2/2
$self->has_job_title && $self->has_fax_number
$self->has_job_title $self->has_fax_number
Truth table100%3/3
A && B
A= $self->has_job_titleB= $self->has_fax_number
ABresult
0X0
100
111
112 2 croak 'Contacts with an organization_name require a job_title and fax_number';
113 }
114 }
115 }
116  
117 0 ▶sub construct_creation_request {
Subroutine construct_creation_request: not called CC=8 SCAR=42.8
Pod documented
118 0 my $self = shift;
119 0 my ( $contact_type ) = pos_validated_list( \@_, { isa => RawContactType, optional => 1 } );
120  
121 0 ▶ my $creation_request = {
Branch: 5 branches
BranchTrueFalseTotal
$self->has_organization_name ? : 0 0 0
$self->has_job_title ? : 0 0 0
$self->has_address2 ? : 0 0 0
$self->has_state ? : 0 0 0
$self->has_fax_number ? : 0 0 0
122 FirstName => $self->first_name,
123 LastName => $self->last_name,
124 $self->has_organization_name ? ( OrganizationName => $self->organization_name ) : ( ),
125 $self->has_job_title ? ( JobTitle => $self->job_title ) : ( ),
126 Address1 => $self->address1,
127 $self->has_address2 ? ( Address2 => $self->address2 ) : ( ),
128 City => $self->city,
129 $self->has_state ? ( StateProvince => $self->state ) : ( ),
130 Country => $self->country,
131 PostalCode => $self->zipcode,
132 EmailAddress => $self->email,
133 Phone => sprintf('+%s.%s', $self->phone_number->country_code, $self->phone_number->number ),
134 $self->has_fax_number ? ( Fax => sprintf('+%s.%s', $self->fax_number->country_code, $self->fax_number->number ) ) : ( ),
135 };
136  
137 0 ▶ if( $contact_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contact_type) 0 0 0
138 0 for my $key ( keys %{ $creation_request } ) {
139 0 $creation_request->{ $contact_type . $key } = delete $creation_request->{ $key };
140 }
141 }
142  
143 0 return $creation_request;
144 }
145  
146 0 ▶sub construct_from_response {
Subroutine construct_from_response: not called CC=5 SCAR=34.0
Pod documented
147 0 my $self = shift;
148 0 my ( $raw_response ) = pos_validated_list( \@_, { isa => HashRef } );
149  
150 # Some routes return 'FirstName' some 'RegistrantFirstName'
151 # This logic is meant to normalize that structure
152 0 my $response;
153 0 for my $prefix (qw( Admin Administrative Registrant Tech Technical AuxBilling )) {
154 0 ▶ if( exists $raw_response->{ $prefix . 'FirstName' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$raw_response{$prefix . 'FirstName'}) 0 0 0
155 0 for my $key ( keys %{ $raw_response } ) {
156 0 $response->{ substr( $key, length $prefix ) } = $raw_response->{ $key };
157 }
158  
159 0 last;
160 }
161 }
162  
163 0 ▶ $response //= $raw_response;
Condition0%0/3
$response //= $raw_response
l!l&&r!l&&!r
000
MC/DC0%0/2
$response //= $raw_response
$response $raw_response
Truth table0%0/3
A //= B
A= $responseB= $raw_response
ABresult
1X1
011
000
164  
165 0 ▶ return try {
Subroutine __ANON__: not called CC=6 SCAR=37.4
166 return $self->new({
167 first_name => $response->{'FirstName'},
168 last_name => $response->{'LastName'},
169 is_string( $response->{'OrganizationName'} ) ? ( organization_name => $response->{'OrganizationName'} ) : ( ),
170 is_string( $response->{'JobTitle'} ) ? ( job_title => $response->{'JobTitle'} ) : ( ),
171 address1 => $response->{'Address1'},
172 is_string( $response->{'Address2'} ) ? ( address2 => $response->{'Address2'} ) : ( ),
173 city => $response->{'City'},
174 is_string( $response->{'StateProvince'} ) ? ( state => $response->{'StateProvince'} ) : ( ),
175 country => $response->{'Country'},
176 zipcode => $response->{'PostalCode'},
177 email => $response->{'EmailAddress'},
178 phone_number => $response->{'Phone'},
179 0 ▶ is_string( $response->{'Fax'} ) ? ( fax_number => $response->{'Fax'} ) : ( ),
Branch: 5 branches
BranchTrueFalseTotal
is_string($response->{'OrganizationName'}) ? : 0 0 0
is_string($response->{'JobTitle'}) ? : 0 0 0
is_string($response->{'Address2'}) ? : 0 0 0
is_string($response->{'StateProvince'}) ? : 0 0 0
is_string($response->{'Fax'}) ? : 0 0 0
180 });
181 }
182 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
183 0 croak "Error constructing contact from response: $_";
184 0 };
185 }
186  
187 54 __PACKAGE__->meta->make_immutable;
188 54 1;
189  
190 __END__
« WWW/eNom/DomainRequest/Registration.pm ↑ Summary WWW/eNom/Role/Command/Domain.pm »