File Coverage

blib/lib/XML/SRS/Types.pm
Criterion Covered Total %
statement 11 13 84.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 16 18 88.8


line stmt bran cond sub pod time code
1              
2             package XML::SRS::Types;
3             BEGIN {
4 1     1   1681 $XML::SRS::Types::VERSION = '0.09';
5             }
6              
7 1     1   34 use 5.010;
  1         4  
  1         36  
8 1     1   5 use strict;
  1         2  
  1         43  
9 1     1   5 use warnings;
  1         1  
  1         120  
10              
11 1     1   400 use Moose::Util::TypeConstraints;
  0            
  0            
12             use PRANG::XMLSchema::Types;
13             use Regexp::Common qw(net);
14              
15             our $PKG = "XML::SRS";
16             subtype "${PKG}::Number"
17             => as "PRANG::XMLSchema::nonNegativeInteger";
18             subtype "${PKG}::RegistrarId"
19             => as "PRANG::XMLSchema::positiveInteger";
20             subtype "${PKG}::Term"
21             => as "PRANG::XMLSchema::positiveInteger";
22             subtype "${PKG}::token_OTHERS"
23             => as "Str",
24             => where { $_ eq "OTHERS" };
25             subtype "${PKG}::RegistrarIdOrOTHERS"
26             => as "${PKG}::RegistrarId|${PKG}::token_OTHERS";
27              
28             subtype "${PKG}::Dollars"
29             => as "PRANG::XMLSchema::decimal"
30             => where {
31             ($_ - sprintf("%.2f",$_)) < 0.0000001;
32             };
33             subtype "${PKG}::UID"
34             => as "Str"; # XXX - any other constraints on ActionIDs?
35              
36             # a non-IDN domain name
37             our $RR_re = qr/[a-zA-Z0-9](:?[a-zA-Z0-9\-]*[a-zA-Z0-9])?/;
38             our $DNS_name_re = qr/(?:$RR_re\.)+$RR_re/;
39             subtype "${PKG}::DomainName"
40             => as "Str"
41             => where {
42             m{\A$DNS_name_re\Z};
43             };
44              
45             subtype "${PKG}::UDAI"
46             => as "Str"
47             => where {
48             $_ =~
49             m{ \A [abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789]{8} \z }xms;
50             };
51              
52             subtype "${PKG}::HandleId"
53             => as "PRANG::XMLSchema::token"
54             => where {
55              
56             # this is a subset of the EPP handle ID specification,
57             # which allows for 3-16 characters. Here we just
58             # restrict it to "word" characters, which still allows
59             # a whole bunch of Unicode characters. And hyphens.
60             m{\A[\p{IsWord}\- ]{3,16}\Z};
61             };
62              
63             subtype "${PKG}::Email"
64             => as "Str"
65             => where {
66              
67             # kept as-is for historical reasons
68             m{\A(?:[^@\s]+|".*")\@$DNS_name_re\Z};
69             };
70              
71             subtype "${PKG}::IPv4"
72             => as "Str"
73             => where {
74             $_ =~ m{ \A $RE{net}{IPv4} \z }xms;
75             };
76              
77             # IPv6 : from Regexp::IPv6
78             # http://search.cpan.org/~salva/Regexp-IPv6-0.02/lib/Regexp/IPv6.pm
79             # http://cpansearch.perl.org/src/SALVA/Regexp-IPv6-0.02/lib/Regexp/IPv6.pm
80             my $IPv4 =
81             "(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))";
82             my $G = "[\\da-f]{1,4}";
83             my @tail =
84             ( ":", ":(?:$G)?", "(?:(?::$G){1,2}|:$IPv4?)",
85             "(?::$G)?(?:(?::$G){1,2}|:$IPv4?)",
86             "(?::$G){0,2}(?:(?::$G){1,2}|:$IPv4?)",
87             "(?::$G){0,3}(?:(?::$G){1,2}|:$IPv4?)",
88             "(?::$G){0,4}(?:(?::$G){1,2}|:$IPv4?)" );
89             my $IPv6_re = $G;
90             $IPv6_re = "$G:(?:$IPv6_re|$_)" for @tail;
91             $IPv6_re = qr/:(?::$G){0,5}(?:(?::$G){1,2}|:$IPv4)|$IPv6_re/i;
92              
93             subtype "${PKG}::IPv6"
94             => as "Str"
95             => where {
96             $_ =~ m{ \A $IPv6_re \z }xms;
97             };
98              
99             our @Boolean = qw(0 1);
100             subtype "${PKG}::Boolean"
101             => as "Bool"
102             => where {
103             $_ ~~ @Boolean;
104             };
105             coerce "${PKG}::Boolean"
106             => from "Bool"
107             => via { $_ ? 1 : 0 };
108             coerce "${PKG}::Dollars"
109             => from "PRANG::XMLSchema::decimal"
110             => via {
111             sprintf("%.2f",$_);
112             };
113              
114             our @AccountingAction = qw(Credit Debit);
115             subtype "${PKG}::token_OTHERS"
116             => as "Str",
117             => where { $_ ~~ @AccountingAction };
118              
119             enum "${PKG}::DomainWriteAction" =>
120             qw(DomainCreate DomainUpdate);
121              
122             enum "${PKG}::DomainQueryAction" =>
123             qw(Whois DomainDetailsQry ActionDetailsQry UDAIValidQry);
124              
125             enum "${PKG}::HandleWriteAction" =>
126             qw(HandleCreate HandleUpdate);
127              
128             subtype "${PKG}::HandleQueryAction"
129             => as "Str",
130             => where {
131             $_ eq qw(HandleDetailsQry);
132             };
133              
134             enum "${PKG}::RegistrarWriteAction" =>
135             qw(RegistrarCreate RegistrarUpdate AckMessage);
136              
137             enum "${PKG}::RegistrarQueryAction" =>
138             qw(RegistrarDetailsQry RegistrarAccountQry GetMessages);
139              
140             enum "${PKG}::RegistryAction" =>
141             qw(SysParamsUpdate SysParamsQry RunLogCreate RunLogQry
142             ScheduleCreate ScheduleCancel ScheduleQry ScheduleUpdate
143             BillingExtract SetBillingAmount BillingAmountQry
144             DeferredIncomeSummaryQry DeferredIncomeDetailQry
145             BilledUntilAdjustment BuildDnsZoneFiles GenerateDomainReport
146             AdjustRegistrarAccount AccessControlListQry
147             AccessControlListAdd AccessControlListRemove);
148              
149             subtype "${PKG}::ActionName" =>
150             as join(
151             "|",
152             map {"${PKG}::$_"}
153             qw(DomainWriteAction DomainQueryAction
154             HandleWriteAction HandleQueryAction
155             RegistrarWriteAction RegistrarQueryAction
156             RegistryAction)
157             );
158              
159             enum "${PKG}::ActionEtcExtra" =>
160             qw(UnknownTransaction DomainTransfer);
161              
162             enum "${PKG}::RegDomainStatus" =>
163             qw(Active PendingRelease);
164             enum "${PKG}::DomainStatus" =>
165             qw(Active PendingRelease Available);
166              
167             subtype "${PKG}::ActionEtc"
168             => as "${PKG}::ActionName|${PKG}::ActionEtcExtra";
169              
170             enum "${PKG}::RoleName" =>
171             qw( Registrar Registry Whois Query CreateDomain UpdateDomain
172             TransferDomain CancelDomain UncancelDomain UpdateRegistrar
173             Administer Supervisor Connect ReleaseDomain QueryACL
174             UpdateACL QueryRegACL);
175              
176             # Domain Statuses
177             enum "${PKG}::RegDomainStatus" =>
178             qw(Active PendingRelease);
179              
180             enum "${PKG}::DomainStatus" =>
181             qw(Active PendingRelease Available);
182              
183             enum "${PKG}::BillStatus" =>
184             qw(PendingConfirmation Confirmed);
185              
186             1;