Initial import of Net::Ikano
[Net-Ikano.git] / lib / Net / Ikano / XMLUtil.pm
1 package Net::Ikano::XMLUtil;
2
3 use warnings;
4 use strict;
5 use base 'XML::Simple';
6 use Data::Dumper;
7 use Switch;
8
9 =head1 DESCRIPTION
10     
11 Unfortunately the Ikano API schema has xs:sequence everywhere, so we need to have most elements in a particular order.
12 This class solves this problem by extending XML::Simple and overriding sorted_keys to provide the element order for each request.
13
14 IMPORTANT: when using this class, XMLOut must have SuppressEmpty => 1 as an option.
15 You will break everything otherwise.
16
17 =cut
18
19 sub sorted_keys {
20     my ($self,$name,$hashref) = @_;
21
22     switch ($name) { 
23
24         # quals
25         return qw( AddressLine1 AddressUnitType AddressUnitValue AddressCity
26                     AddressState ZipCode Country LocationType ) case 'Address';
27         return qw( Address PhoneNumber CheckNetworks RequestClientIP ) case 'PreQual';
28
29         # orders
30         return qw( type ProductCustomId DSLPhoneNumber VirtualPhoneNumber Password
31             TermsId PrequalId CompanyName FirstName MiddleName LastName
32             ContactMethod ContactPhoneNumber ContactEmail ContactFax DateToOrder
33             RequestClientIP IspChange IspPrevious CurrentProvider ) case 'Order';
34
35         # password change
36         return qw( DSLPhoneNumber NewPassword ) case 'PasswordChange';
37
38         # account status change
39         return qw( type DSLServiceId DSLPhoneNumber ) case 'AccountStatusChange';
40
41     }
42     return $self->SUPER::sorted_keys($name, $hashref);
43 }
44
45 1;