File Coverage

blib/lib/Net/DRI/Protocol/EPP/Extensions/CoCCA/IPVerification.pm
Criterion Covered Total %
statement 12 48 25.0
branch 0 30 0.0
condition 0 3 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 91 17.5


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, CoCCA IP Protection
2             ## from http://cocca.org.nz/index.php/cocca-tools/extensions.html
3             ##
4             ## Copyright (c) 2011,2013 Patrick Mevzek . All rights reserved.
5             ##
6             ## This file is part of Net::DRI
7             ##
8             ## Net::DRI is free software; you can redistribute it and/or modify
9             ## it under the terms of the GNU General Public License as published by
10             ## the Free Software Foundation; either version 2 of the License, or
11             ## (at your option) any later version.
12             ##
13             ## See the LICENSE file that comes with this distribution for more details.
14             ####################################################################################################
15              
16             package Net::DRI::Protocol::EPP::Extensions::CoCCA::IPVerification;
17              
18 1     1   976 use strict;
  1         1  
  1         28  
19 1     1   3 use warnings;
  1         1  
  1         21  
20              
21 1     1   3 use Net::DRI::Util;
  1         1  
  1         16  
22 1     1   3 use Net::DRI::Exception;
  1         1  
  1         488  
23              
24             =pod
25              
26             =head1 NAME
27              
28             Net::DRI::Protocol::EPP::Extensions::CoCCA::IPVerification - CoCCA IP Protection EPP Extension for Net::DRI
29              
30             =head1 DESCRIPTION
31              
32             Please see the README file for details.
33              
34             =head1 SUPPORT
35              
36             For now, support questions should be sent to:
37              
38             Enetdri@dotandco.comE
39              
40             Please also see the SUPPORT file in the distribution.
41              
42             =head1 SEE ALSO
43              
44             Ehttp://www.dotandco.com/services/software/Net-DRI/E
45              
46             =head1 AUTHOR
47              
48             Patrick Mevzek, Enetdri@dotandco.comE
49              
50             =head1 COPYRIGHT
51              
52             Copyright (c) 2011,2013 Patrick Mevzek .
53             All rights reserved.
54              
55             This program is free software; you can redistribute it and/or modify
56             it under the terms of the GNU General Public License as published by
57             the Free Software Foundation; either version 2 of the License, or
58             (at your option) any later version.
59              
60             See the LICENSE file that comes with this distribution for more details.
61              
62             =cut
63              
64             ####################################################################################################
65              
66             sub register_commands
67             {
68 0     0 0   my ($class,$version)=@_;
69 0           my %tmp=(
70             create => [ \&create, undef ],
71             );
72              
73 0           return { 'domain' => \%tmp };
74             }
75              
76             sub setup
77             {
78 0     0 0   my ($class,$po,$version)=@_;
79 0           $po->ns({ 'cocca' => [ 'https://production.coccaregistry.net/cocca-ip-verification-1.1','cocca-ip-verification-1.1.xsd' ] });
80 0           return;
81             }
82              
83             ####################################################################################################
84              
85             sub create
86             {
87 0     0 0   my ($epp,$domain,$rd)=@_;
88 0           my $mes=$epp->message();
89              
90 0           my @ipv;
91              
92 0 0         if (Net::DRI::Util::has_key($rd,'chip'))
    0          
93             {
94 0 0         Net::DRI::Exception::usererr_invalid_parameters('chip code must be an XML token from 1 to 255 characters') unless Net::DRI::Util::xml_is_token($rd->{chip},1,255);
95 0           push @ipv,['cocca:chip',['cocca:code',$rd->{chip}]];
96             } elsif (Net::DRI::Util::has_key($rd,'trademark'))
97             {
98 0 0         foreach my $tm (ref $rd->{trademark} eq 'ARRAY' ? @{$rd->{trademark}} : ($rd->{trademark}))
  0            
99             {
100 0           my @t;
101              
102             ## Key names were chosen to mimic the ones in CloudRegistry/LaunchPhase
103 0 0         Net::DRI::Exception::usererr_insufficient_parameters('trademark name is mandatory') unless Net::DRI::Util::has_key($tm,'trademark_name');
104 0 0         Net::DRI::Exception::usererr_invalid_parameters('trademark name must be an XML token from 1 to 255 characters') unless Net::DRI::Util::xml_is_token($tm->{trademark_name},1,255);
105 0           push @t,['cocca:registeredMark',$tm->{trademark_name}];
106              
107 0 0         Net::DRI::Exception::usererr_insufficient_parameters('trademark number is mandatory') unless Net::DRI::Util::has_key($tm,'trademark_number');
108 0 0         Net::DRI::Exception::usererr_invalid_parameters('trademark number must be an XML token from 1 to 255 characters') unless Net::DRI::Util::xml_is_token($tm->{trademark_number},1,255);
109 0           push @t,['cocca:registrationNumber',$tm->{trademark_number}];
110              
111 0 0         Net::DRI::Exception::usererr_insufficient_parameters('trademark locality is mandatory') unless Net::DRI::Util::has_key($tm,'trademark_locality');
112 0 0         Net::DRI::Exception::usererr_invalid_parameters('trademark locality must be a 2 letters country code') unless Net::DRI::Util::xml_is_token($tm->{trademark_locality},2,2);
113 0           push @t,['cocca:registrationLocality',$tm->{trademark_locality}];
114              
115 0 0         Net::DRI::Exception::usererr_insufficient_parameters('trademark entitlement is mandatory') unless Net::DRI::Util::has_key($tm,'trademark_entitlement');
116 0 0 0       Net::DRI::Exception::usererr_invalid_parameters('trademark entitlement must be "OWNER" or "ASSIGNEE"') unless Net::DRI::Util::xml_is_token($tm->{trademark_entitlement}) && $tm->{trademark_entitlement}=~m/^(?:OWNER|ASSIGNEE)$/i;
117 0           push @t,['cocca:capacity',uc $tm->{trademark_entitlement}];
118              
119 0 0         if (Net::DRI::Util::has_key($tm,'legal_id'))
120             {
121 0 0         Net::DRI::Exception::usererr_invalid_parameters('legal id must be an XML token from 1 to 255 characters') unless Net::DRI::Util::xml_is_token($tm->{legal_id},1,255);
122 0           push @t,['cocca:companyNumber',$tm->{legal_id}];
123             }
124              
125 0           push @ipv,['cocca:trademark',@t];
126             }
127 0           @ipv=['cocca:trademarks',@ipv];
128             }
129              
130 0 0         return unless @ipv;
131              
132 0           my $eid=$mes->command_extension_register('cocca:extension',sprintf('xmlns:cocca="%s" xsi:schemaLocation="%s %s"',$mes->nsattrs('cocca')));
133 0           $mes->command_extension($eid,[@ipv]);
134 0           return;
135             }
136              
137             ####################################################################################################
138             1;