| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ## Domain Registry Interface, Price Extension Mapping for EPP | 
| 2 |  |  |  |  |  |  | ## | 
| 3 |  |  |  |  |  |  | ## Copyright (c) 2015 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::Protocol::EPP::Extensions::AusRegistry::Price; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  | 1 |  | 1287 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 91 |  | 
| 18 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 19 | 1 |  |  | 1 |  | 4 | use feature 'state'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 190 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 6 | use Net::DRI::Util; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 22 | 1 |  |  | 1 |  | 4 | use Net::DRI::Exception; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 23 | 1 |  |  | 1 |  | 6 | use Net::DRI::Protocol::EPP::Util; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 823 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | #################################################################################################### | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub register_commands | 
| 28 |  |  |  |  |  |  | { | 
| 29 | 0 |  |  | 0 | 0 |  | my ($class,$version)=@_; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | state $rops = { 'domain' => { check            => [ \&check_build,    \&check_parse ], | 
| 32 |  |  |  |  |  |  | check_multi      => [ \&check_build,    \&check_parse ], | 
| 33 |  |  |  |  |  |  | create           => [ \&create_build,   undef ], | 
| 34 |  |  |  |  |  |  | renew            => [ \&renew_build,    undef ], | 
| 35 |  |  |  |  |  |  | transfer_request => [ \&transfer_build, undef ], | 
| 36 |  |  |  |  |  |  | update           => [ \&update_build,   undef ], | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | }; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | return $rops; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub setup | 
| 44 |  |  |  |  |  |  | { | 
| 45 | 0 |  |  | 0 | 0 |  | my ($class,$po,$version)=@_; | 
| 46 | 0 |  |  |  |  |  | state $ns = { 'price' => [ 'urn:ar:params:xml:ns:price-1.2','price-1.2.xsd' ] }; | 
| 47 | 0 |  |  |  |  |  | $po->ns($ns); | 
| 48 | 0 |  |  |  |  |  | return; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  | 0 | 0 |  | sub implements { return 'https://ausregistry.github.io/doc/price-1.2/price-1.2.html'; } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | #################################################################################################### | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub check_build | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 0 |  |  | 0 | 0 |  | my ($epp,$domain,$rp)=@_; | 
| 58 | 0 |  |  |  |  |  | my $mes=$epp->message(); | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 0 | 0 |  |  |  |  | return unless Net::DRI::Util::has_key($rp,'price'); | 
| 61 | 0 | 0 |  |  |  |  | return unless $rp->{price}; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 0 |  |  |  |  |  | my $eid=$mes->command_extension_register('price','check'); | 
| 64 | 0 | 0 |  |  |  |  | $mes->command_extension($eid,Net::DRI::Protocol::EPP::Util::build_period($rp->{price},'price')) if Net::DRI::Util::is_class($rp->{price},'DateTime::Duration'); | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 0 |  |  |  |  |  | return; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub check_parse | 
| 70 |  |  |  |  |  |  | { | 
| 71 | 0 |  |  | 0 | 0 |  | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | 
| 72 | 0 |  |  |  |  |  | my $mes=$po->message(); | 
| 73 | 0 | 0 |  |  |  |  | return unless $mes->is_success(); | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 0 |  |  |  |  |  | my $data=$mes->get_extension('price','chkData'); | 
| 76 | 0 | 0 |  |  |  |  | return unless defined $data; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  |  | foreach my $cd (grep { $_->[0] eq 'cd' } Net::DRI::Util::xml_list_children($data)) | 
|  | 0 |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | { | 
| 80 | 0 |  |  |  |  |  | my ($domain,%p); | 
| 81 | 0 |  |  |  |  |  | foreach my $el (Net::DRI::Util::xml_list_children($cd->[1])) | 
| 82 |  |  |  |  |  |  | { | 
| 83 | 0 |  |  |  |  |  | my ($name,$node)=@$el; | 
| 84 | 0 | 0 |  |  |  |  | if ($name eq 'name') | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | { | 
| 86 | 0 |  |  |  |  |  | $domain=$node->textContent(); | 
| 87 |  |  |  |  |  |  | } elsif ($name=~m/^(category|reason)$/) | 
| 88 |  |  |  |  |  |  | { | 
| 89 | 0 |  |  |  |  |  | $p{$name}=$node->textContent(); | 
| 90 |  |  |  |  |  |  | } elsif ($name eq 'period') | 
| 91 |  |  |  |  |  |  | { | 
| 92 | 0 |  |  |  |  |  | state $rperiods={qw/y years m months/}; | 
| 93 | 0 |  |  |  |  |  | $p{duration}=$po->create_local_object('duration',$rperiods->{$node->getAttribute('unit')},$node->textContent()); | 
| 94 |  |  |  |  |  |  | } elsif ($name=~m/^(create|renew|transfer|restore)Price$/) | 
| 95 |  |  |  |  |  |  | { | 
| 96 | 0 |  |  |  |  |  | $p{$1}=0+$node->textContent(); | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  | } | 
| 99 | 0 |  |  |  |  |  | $rinfo->{$otype}->{$domain}->{price}=\%p; | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 0 |  |  |  |  |  | return; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub _build | 
| 106 |  |  |  |  |  |  | { | 
| 107 | 0 |  |  | 0 |  |  | my ($epp,$domain,$rp,$topname)=@_; | 
| 108 | 0 |  |  |  |  |  | my $mes=$epp->message(); | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 0 | 0 |  |  |  |  | return unless Net::DRI::Util::has_key($rp,'price'); | 
| 111 | 0 | 0 |  |  |  |  | return unless $rp->{price}; | 
| 112 | 0 | 0 |  |  |  |  | Net::DRI::Exception::usererr_invalid_parameters('if provided, price element must be "ack" or a decimal number') unless $rp->{price}=~m/^(?:ack|\d+(?:\.\d+)?)$/; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  |  | my $eid=$mes->command_extension_register('price',$topname); | 
| 115 | 0 | 0 |  |  |  |  | $mes->command_extension($eid,['price:ack',$rp->{price} ne 'ack' ? ['price:price', 0+$rp->{price}] : ()]); | 
| 116 | 0 |  |  |  |  |  | return; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  | 0 | 0 |  | sub create_build   { return _build(@_,'create');   } ## no critic (Subroutines::RequireArgUnpacking) | 
| 120 | 0 |  |  | 0 | 0 |  | sub renew_build    { return _build(@_,'renew');    } ## no critic (Subroutines::RequireArgUnpacking) | 
| 121 | 0 |  |  | 0 | 0 |  | sub transfer_build { return _build(@_,'transfer'); } ## no critic (Subroutines::RequireArgUnpacking) | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | sub update_build | 
| 124 |  |  |  |  |  |  | { | 
| 125 | 0 |  |  | 0 | 0 |  | my ($epp,$domain,$todo,$rp)=@_; | 
| 126 | 0 |  |  |  |  |  | my $rgp=$todo->set('rgp'); | 
| 127 | 0 | 0 | 0 |  |  |  | return unless Net::DRI::Util::has_key($rgp,'op') && $rgp->{op} eq 'request'; | 
| 128 | 0 |  |  |  |  |  | return _build($epp,$domain,$rp,'update'); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | #################################################################################################### | 
| 132 |  |  |  |  |  |  | 1; | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | __END__ |