File Coverage

blib/lib/Net/DRI/Data/Contact/BE.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 28 0.0
condition 0 35 0.0
subroutine 4 7 57.1
pod 1 3 33.3
total 17 113 15.0


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, Handling of contact data for .BE
2             ##
3             ## Copyright (c) 2006,2008,2009,2013 Patrick Mevzek . All rights reserved.
4             ##
5             ## This file is part of Net::DRI
6             ##
7             ## Net::DRI is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 2 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## See the LICENSE file that comes with this distribution for more details.
13             #########################################################################################
14              
15             package Net::DRI::Data::Contact::BE;
16              
17 1     1   2192 use strict;
  1         2  
  1         28  
18 1     1   3 use warnings;
  1         2  
  1         26  
19              
20 1     1   3 use base qw/Net::DRI::Data::Contact/;
  1         2  
  1         67  
21              
22 1     1   5 use Net::DRI::Exception;
  1         1  
  1         463  
23              
24             __PACKAGE__->register_attributes(qw(vat lang));
25              
26             =pod
27              
28             =head1 NAME
29              
30             Net::DRI::Data::Contact::BE - Handle .BE contact data for Net::DRI
31              
32             =head1 DESCRIPTION
33              
34             This subclass of Net::DRI::Data::Contact adds accessors and validation for
35             .BE specific data.
36              
37             =head1 METHODS
38              
39             The following accessors/mutators can be called in chain, as they all return the object itself.
40              
41             =head2 type()
42              
43             type of contact : billing, tech, registrant, onsite or accmgr (mandatory)
44              
45             registrant is called licensee by the registry : you can use both names when setting value,
46             but you will get back only registrant when getting.
47              
48             =head2 vat()
49              
50             vat number of contact
51              
52             =head2 lang()
53              
54             language of contact, either fr, nl or en
55              
56             =head1 SUPPORT
57              
58             For now, support questions should be sent to:
59              
60             Enetdri@dotandco.comE
61              
62             Please also see the SUPPORT file in the distribution.
63              
64             =head1 SEE ALSO
65              
66             http://www.dotandco.com/services/software/Net-DRI/
67              
68             =head1 AUTHOR
69              
70             Patrick Mevzek, Enetdri@dotandco.comE
71              
72             =head1 COPYRIGHT
73              
74             Copyright (c) 2006,2008,2009,2013 Patrick Mevzek .
75             All rights reserved.
76              
77             This program is free software; you can redistribute it and/or modify
78             it under the terms of the GNU General Public License as published by
79             the Free Software Foundation; either version 2 of the License, or
80             (at your option) any later version.
81              
82             See the LICENSE file that comes with this distribution for more details.
83              
84             =cut
85              
86             ####################################################################################################
87              
88             sub validate
89             {
90 0     0 0   my ($self,$change)=@_;
91 0   0       $change||=0;
92 0           my @errs;
93              
94 0           $self->SUPER::validate($change); ## will trigger an Exception if problem
95              
96 0 0         if (!$change)
97             {
98 0 0 0       Net::DRI::Exception::usererr_insufficient_parameters('Invalid contact information: voice/type mandatory') unless ($self->voice() && $self->type());
99             }
100              
101             ## Lower limits than in EPP (other checks already done in superclass)
102 0 0 0       push @errs,'name' if ($self->name() && grep { length($_) > 50 } ($self->name()));
  0            
103 0 0 0       push @errs,'org' if ($self->org() && grep { length($_) > 100 } ($self->org())); ## docs says only that it will be truncated if more than 100 characters
  0            
104              
105              
106 0 0 0       push @errs,'type' if ($self->type() && $self->type()!~m/^(?:billing|tech|registrant|onsite|accmgr)$/); ## licensee is translated to registrant !
107 0 0 0       push @errs,'vat' if ($self->vat() && !Net::DRI::Util::xml_is_token($self->vat(),1,20));
108 0 0 0       push @errs,'lang' if ($self->lang() && $self->lang()!~m/^(?:fr|nl|en)$/);
109              
110 0 0         Net::DRI::Exception::usererr_invalid_parameters('Invalid contact information: '.join('/',@errs)) if @errs;
111              
112 0 0 0       Net::DRI::Exception::usererr_insufficient_parameters('Org is mandatory for billing, tech or accmgr contacts') if ($self->type() && $self->type()=~m/^(?:type|billing|accmgr)$/ && !$self->org());
      0        
113              
114 0           return 1; ## everything ok.
115             }
116              
117             sub init
118             {
119 0     0 0   my ($self,$what,$ndr)=@_;
120 0 0         if ($what eq 'create')
121             {
122 0           my $a=$self->auth();
123 0 0 0       $self->auth({pw=>''}) unless ($a && (ref($a) eq 'HASH') && exists($a->{pw}));
      0        
124 0 0         $self->srid('ABCD') unless defined $self->srid(); ## we can not choose the ID
125             }
126 0           return;
127             }
128              
129             sub type
130             {
131 0     0 1   my ($self,$what)=@_;
132 0 0 0       if (defined $what && $what)
133             {
134 0 0         $what='registrant' if $what eq 'licensee';
135 0           $self->{type}=$what;
136 0           return $self;
137             }
138 0           return $self->{type};
139             }
140              
141             ####################################################################################################
142             1;