EPP/DCP.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« EPP/CredsOptions.pm ↑ Summary EPP/Domain/Node.pm »
1  
2 package XML::EPP::DCP::Expiry;
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 0 ▶use MooseX::Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=2.6
6 use Moose::Util::TypeConstraints;
7 use PRANG::Graph;
8 use PRANG::XMLSchema::Types;
9  
10 our $SCHEMA_PKG = "XML::EPP";
11  
12 # hmm, choice with simpleTypes can't be mapped quite the same..
13 has 'absolute' =>
14 is => "rw",
15 isa => "PRANG::XMLSchema::dateTime",
16 predicate => "has_absolute",
17 clearer => "clear_absolute",
18 ;
19  
20 has 'relative' =>
21 is => "rw",
22 isa => "PRANG::XMLSchema::duration",
23 predicate => "has_relative",
24 clearer => "clear_relative",
25 ;
26  
27 has_element 'abs_or_rel' =>
28 is => "rw",
29 isa => "PRANG::XMLSchema::duration|PRANG::XMLSchema::dateTime",
30 xml_nodeName => {
31 "absolute" => "PRANG::XMLSchema::dateTime",
32 "relative" => "PRANG::XMLSchema::duration",
33 },
34 xml_nodeName_attr => "is_abs_or_rel",
35 lazy => 1,
36 default => sub {
37 my $self = shift;
38 $self->has_absolute ? $self->absolute : $self->relative
39 },
40 trigger => sub {
41 my $self = shift;
42 my $val = shift;
43 if ( $self->is_abs_or_rel eq "relative" ) {
44 $self->clear_absolute;
45 $self->relative($val);
46 }
47 else {
48 $self->clear_relative;
49 $self->absolute($val);
50 }
51 },
52 ;
53  
54 method is_abs_or_rel( Str $abs_or_rel? where { m{^(relative|absolute)$} } ) {
55 if ( defined $abs_or_rel ) {
56 if ( $abs_or_rel eq "relative" ) {
57 $self->clear_absolute;
58 }
59 else {
60 $self->clear_relative;
61 }
62 }
63 else {
64 if ( $self->has_relative ) {
65 "relative";
66 }
67 elsif ( $self->has_absolute ) {
68 "absolute";
69 }
70 else {
71 die "neither absolute nor relative time in $self";
72 }
73 }
74 }
75  
76 with 'XML::EPP::Node';
77  
78 subtype "${SCHEMA_PKG}::dcpExpiryType"
79 => as __PACKAGE__;
80 coerce "${SCHEMA_PKG}::dcpExpiryType"
81 => from "PRANG::XMLSchema::duration"
82 => via {
83 __PACKAGE__->new(relative => $_);
84 };
85 coerce "${SCHEMA_PKG}::dcpExpiryType"
86 => from "PRANG::XMLSchema::dateTime"
87 => via {
88 __PACKAGE__->new(absolute => $_);
89 };
90  
91 package XML::EPP::DCP::Ours;
92  
93 use Moose;
94 use Moose::Util::TypeConstraints;
95 use MooseX::Method::Signatures;
96 use PRANG::Graph;
97 our $SCHEMA_PKG = "XML::EPP";
98  
99 subtype "${SCHEMA_PKG}::dcpRecDescType"
100 => as "PRANG::XMLSchema::token"
101 => where {
102 length($_) and length($_) <= 255;
103 };
104  
105 has_element 'name' =>
106 is => "rw",
107 isa => "${SCHEMA_PKG}::dcpRecDescType",
108 predicate => "has_name",
109 xml_nodeName => "recDesc",
110 ;
111  
112 with 'XML::EPP::Node';
113  
114 subtype "${SCHEMA_PKG}::dcpOursType"
115 => as __PACKAGE__;
116  
117  
118 package XML::EPP::DCP::Recipient;
119  
120 use Moose;
121 use Moose::Util::TypeConstraints;
122 use MooseX::Method::Signatures;
123 use PRANG::Graph;
124 our $SCHEMA_PKG = "XML::EPP";
125  
126 our @valid_recipients = qw(other ours public same unrelated);
127 for my $recipient ( @valid_recipients ) {
128  
129 my $type = $recipient eq "ours" ?
130 "ArrayRef[${SCHEMA_PKG}::dcpOursType]" : "Bool";
131  
132 has_element $recipient =>
133 (is => "rw",
134 isa => $type,
135 predicate => "has_$recipient",
136 );
137 }
138  
139 with 'XML::EPP::Node';
140  
141 subtype "${SCHEMA_PKG}::dcpRecipientType"
142 => as __PACKAGE__;
143  
144 coerce "${SCHEMA_PKG}::dcpRecipientType"
145 => from "Str|ArrayRef[Str]"
146 => via {
147 my @recipient = (ref $_ ? @$_ : $_);
148 my %recipients = map { $_ => 1 } @recipient;
149 my @init_args;
150 my @ours;
151 for my $recipient ( @valid_recipients ) {
152 if (delete $recipients{$recipient}) {
153 if ( $recipient eq "ours") {
154 push @ours, XML::EPP::DCP::Ours->new;
155 }
156 else {
157 push @init_args, $recipient => 1;
158 }
159 }
160 }
161 push @ours, map {
162 XML::EPP::DCP::Ours->new( name => $_ );
163 } keys %recipients;
164  
165 push @init_args, ours => \@ours
166 if @ours;
167  
168 __PACKAGE__->new(@init_args);
169 };
170  
171 package XML::EPP::DCP::Access;
172  
173 use Moose;
174 use MooseX::Method::Signatures;
175 use Moose::Util::TypeConstraints;
176 use PRANG::Graph;
177 our $SCHEMA_PKG = "XML::EPP";
178  
179 my @access_enum = qw(all none null other personal personalAndOther);
180 enum "${SCHEMA_PKG}::dcpAccessType::enum" => @access_enum;
181  
182 has 'access' =>
183 is => "rw",
184 isa => "${SCHEMA_PKG}::dcpAccessType::enum",
185 trigger => sub { $_[0]->access_node(1) },
186 ;
187  
188 has_element 'access_node' =>
189 is => "rw",
190 isa => "Bool",
191 xml_nodeName => { map { $_ => "Bool" } @access_enum },
192 xml_nodeName_attr => "access",
193 ;
194  
195 with "${SCHEMA_PKG}::Node";
196  
197 subtype "${SCHEMA_PKG}::dcpAccessType"
198 => as __PACKAGE__;
199  
200 coerce "${SCHEMA_PKG}::dcpAccessType"
201 => from "Str"
202 => via {
203 __PACKAGE__->new($_ => 1);
204 };
205  
206  
207 package XML::EPP::DCP;
208  
209 use Moose;
210 use MooseX::Method::Signatures;
211 use Moose::Util::TypeConstraints;
212 use PRANG::Graph;
213 our $SCHEMA_PKG = "XML::EPP";
214  
215 has_element 'access' =>
216 is => "rw",
217 isa => "XML::EPP::dcpAccessType",
218 coerce => 1,
219 required => 1,
220 ;
221  
222 has_element 'statement' =>
223 is => "rw",
224 isa => "ArrayRef[XML::EPP::DCP::Statement]",
225 coerce => 1,
226 required => 1,
227 ;
228  
229 coerce "ArrayRef[XML::EPP::DCP::Statement]"
230 => from "ArrayRef[HashRef]"
231 => via {
232 my @x = @$_;
233 [ map { XML::EPP::DCP::Statement->new(%$_) }
234 @x ];
235 };
236  
237 coerce "ArrayRef[XML::EPP::DCP::Statement]"
238 => from "HashRef"
239 => via {
240 [ XML::EPP::DCP::Statement->new(%$_) ];
241 };
242  
243 has_element 'expiry' =>
244 is => "rw",
245 predicate => "has_expiry",
246 isa => "${SCHEMA_PKG}::dcpExpiryType",
247 coerce => 1,
248 ;
249  
250 with "${SCHEMA_PKG}::Node";
251  
252 subtype "${SCHEMA_PKG}::dcpType"
253 => as __PACKAGE__;
254  
255 coerce __PACKAGE__
256 => from "HashRef"
257 => via {
258 __PACKAGE__->new(%$_);
259 };
260  
261 package XML::EPP::DCP::Purpose;
262  
263 use Moose;
264 our $SCHEMA_PKG = "XML::EPP";
265 use Moose::Util::TypeConstraints;
266 use MooseX::Method::Signatures;
267 use PRANG::Graph;
268  
269 my @valid_purposes = qw(admin contact other prov);
270 has_element $_ =>
271 is => "rw",
272 isa => "Bool"
273 for @valid_purposes;
274  
275 with "${SCHEMA_PKG}::Node";
276  
277 subtype "${SCHEMA_PKG}::dcpPurposeType"
278 => as __PACKAGE__;
279  
280 coerce "${SCHEMA_PKG}::dcpPurposeType"
281 => from "Str|ArrayRef[Str]"
282 => via {
283 my @purposes = ref $_ ? @$_ : $_;
284 my %purposes = map { $_ => 1 } @purposes;
285 my @init_args;
286 for my $purpose ( @valid_purposes ) {
287 if ( delete $purposes{$purpose} ) {
288 push @init_args, $purpose => 1,
289 }
290 }
291 if ( keys %purposes ) {
292 die "invalid purpose(s): @{[keys %purposes]}";
293 }
294 __PACKAGE__->new(@init_args);
295 };
296  
297 package XML::EPP::DCP::Retention;
298  
299 use Moose;
300 our $SCHEMA_PKG = "XML::EPP";
301 use Moose::Util::TypeConstraints;
302 use MooseX::Method::Signatures;
303 use PRANG::Graph;
304  
305 my @retention_types = qw(business indefinite legal none stated);
306 enum "${SCHEMA_PKG}::dcpRetentionType::enum"
307 => @retention_types;
308  
309 with "${SCHEMA_PKG}::Node";
310  
311 has 'retention' =>
312 is => "rw",
313 isa => "${SCHEMA_PKG}::dcpRetentionType::enum",
314 trigger => sub {
315 $_[0]->has_retention(1);
316 };
317  
318 has_element 'has_retention' =>
319 is => "rw",
320 isa => "Bool",
321 xml_nodeName => { map { $_ => "Bool" } @retention_types },
322 xml_nodeName_attr => "retention",
323 ;
324  
325 subtype "${SCHEMA_PKG}::dcpRetentionType"
326 => as __PACKAGE__;
327 coerce "${SCHEMA_PKG}::dcpRetentionType"
328 => from "Str"
329 => via {
330 __PACKAGE__->new(retention => $_);
331 };
332  
333 package XML::EPP::DCP::Statement;
334  
335 use Moose;
336 our $SCHEMA_PKG = "XML::EPP";
337 use Moose::Util::TypeConstraints;
338 use MooseX::Method::Signatures;
339 use PRANG::Graph;
340  
341 has_element 'purpose' =>
342 is => "rw",
343 isa => "${SCHEMA_PKG}::dcpPurposeType",
344 required => 1,
345 coerce => 1,
346 ;
347  
348 has_element 'recipient' =>
349 is => "rw",
350 isa => "${SCHEMA_PKG}::dcpRecipientType",
351 required => 1,
352 coerce => 1,
353 ;
354  
355 has_element 'retention' =>
356 is => "rw",
357 isa => "${SCHEMA_PKG}::dcpRetentionType",
358 required => 1,
359 coerce => 1,
360 ;
361  
362 with "${SCHEMA_PKG}::Node";
363  
364 subtype "${SCHEMA_PKG}::dcpStatementType"
365 => as __PACKAGE__;
366  
367 1;
368  
369 __END__
« EPP/CredsOptions.pm ↑ Summary EPP/Domain/Node.pm »