File Coverage

blib/lib/SRS/EPP/Common/Contact.pm
Criterion Covered Total %
statement 14 41 34.1
branch 0 18 0.0
condition 0 6 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 18 75 24.0


line stmt bran cond sub pod time code
1             package SRS::EPP::Common::Contact;
2             {
3             $SRS::EPP::Common::Contact::VERSION = '0.22';
4             }
5              
6 1     1   3046 use Moose::Role;
  1         1  
  1         10  
7 1     1   8421 use Moose::Util::TypeConstraints;
  1         4  
  1         14  
8 1     1   38622 use MooseX::Params::Validate;
  1         58877  
  1         15  
9              
10             requires 'make_error';
11              
12             BEGIN {
13 1     1   769 class_type "XML::EPP::Contact::ChangePostalInfo";
14 1         3517 class_type "XML::EPP::Contact::PostalInfo";
15 1         5915 class_type "XML::EPP::Contact::E164";
16 1         3074 class_type "XML::EPP::Contact::Addr";
17 1         3066 subtype 'SRS::EPP::Common::Contact::PostalInfo'
18             => as join "|", "XML::EPP::Contact::ChangePostalInfo",
19             "XML::EPP::Contact::PostalInfo";
20             }
21              
22             # Check if an epp contact has certain field we don't support
23             # Return an error message if they do, nothing if it's valid
24             sub validate_contact_postal {
25 0     0 0   my $self = shift;
26            
27 0           my ( $epp_postal_info ) = pos_validated_list(
28             \@_,
29             { isa => 'ArrayRef[SRS::EPP::Common::Contact::PostalInfo]' },
30             );
31              
32 0 0         if ( scalar @$epp_postal_info != 1 ) {
33              
34             # The SRS doesn't support the US's idea of i18n. That
35             # is that ASCII=international, anything else=local.
36             # Instead, well accept either form of postalinfo, but
37             # throw an error if they try to provide both types
38             # (because the SRS can't have two translations for one
39             # address)
40 0           $self->log_error(
41             "$self validating_contact_postal found "
42             .@$epp_postal_info
43             ." contacts, wanted 1"
44             );
45 0           return $self->make_error(
46             code => 2306,
47             value => '',
48             reason =>
49             'Only one postal info element per contact supported',
50             );
51             }
52              
53 0           my $postalInfo = $epp_postal_info->[0];
54              
55             # The SRS doesn't have a 'org' field, we don't want to lose
56             # info, so
57 0 0         if ( $postalInfo->org ) {
58 0           $self->log_error(
59             "$self validating_epp_contact found unsupported "
60             ."field organization"
61             );
62 0           return $self->make_error(
63             code => 2306,
64             value => $postalInfo->org,
65             reason => 'org field not supported',
66             );
67             }
68              
69             # SRS requires at least one address line, but not more than
70             # 2; Reject request if they send 0 or 3 street lines
71 0 0         if ( my $addr = $postalInfo->addr() ) {
72 0           my $street_lines = $addr->street;
73 0 0 0       if (
      0        
74             !$street_lines
75             || scalar @$street_lines < 1
76             || @$street_lines > 2
77             )
78             {
79 0 0         $self->log_error(
80             "$self validating_epp_contact found "
81 0           .@{$street_lines||[]}
82             ." lines of street address, 1-2 allowed"
83             );
84 0           return $self->make_error(
85             code => 2306,
86             value => '',
87             reason =>
88             'At least 1 and no more than 2 street lines must be supplied in the address',
89             );
90             }
91             }
92              
93 0           return;
94             }
95              
96             sub validate_contact_voice {
97 0     0 0   my $self = shift;
98            
99 0           my ( $voice ) = pos_validated_list(
100             \@_,
101             { isa => 'XML::EPP::Contact::E164' },
102             );
103              
104 0 0         if ( !$voice->content ) {
105 0           $self->log_error(
106             "$self validate_contact_voice found no phone number"
107             );
108 0           return $self->make_error(
109             code => 2306,
110             value => '',
111             reason => 'Voice phone number cannot be blank',
112             );
113             }
114 0           return;
115             }
116              
117             # Turn an epp address into an srs address
118             sub translate_address {
119 0     0 0   my $self = shift;
120            
121 0           my ( $epp_address ) = pos_validated_list(
122             \@_,
123             { isa => 'XML::EPP::Contact::Addr' },
124             );
125            
126              
127 0           my $street = $epp_address->street();
128 0 0         my $address = XML::SRS::Contact::Address->new(
    0          
    0          
129             address1 => $street->[0],
130             ( $street->[1] ? (address2 => $street->[1]) : () ),
131             city => $epp_address->city,
132             ( $epp_address->sp ? ( region => $epp_address->sp ) : () ),
133             cc => $epp_address->cc,
134             ( $epp_address->pc ? ( postcode => $epp_address->pc ) : () ),
135             );
136              
137 0           return $address;
138             }
139              
140             1;