| 1 | package UltraDNS::Type; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | UltraDNS::Type - Classes for argument and result value data types | ||||||||||
| 6 | |||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||
| 8 | |||||||||||
| 9 | This is an internal module. | ||||||||||
| 10 | |||||||||||
| 11 | =cut | ||||||||||
| 12 | |||||||||||
| 13 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 6 | ▶ | use RPC::XML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 6 | my %udns_types = ( | |||||||||
| 20 | |||||||||||
| 21 | # type list for arguments, generated by mk_methods.pl and manually copied here | ||||||||||
| 22 | |||||||||||
| 23 | # XXX we're happy to subclass int to unsigned, for example, | ||||||||||
| 24 | # because we know that RPC::XML::int doesn't do any range validation. | ||||||||||
| 25 | float => { | ||||||||||
| 26 | base => 'RPC::XML::double', | ||||||||||
| 27 | }, | ||||||||||
| 28 | hexint => { | ||||||||||
| 29 | base => 'RPC::XML::string', | ||||||||||
| 30 | }, | ||||||||||
| 31 | hostname => { | ||||||||||
| 32 | base => 'RPC::XML::string', | ||||||||||
| 33 | }, | ||||||||||
| 34 | id => { | ||||||||||
| 35 | base => 'RPC::XML::string', | ||||||||||
| 36 | }, | ||||||||||
| 37 | integer => { | ||||||||||
| 38 | base => 'RPC::XML::int', | ||||||||||
| 39 | }, | ||||||||||
| 40 | ip_address => { | ||||||||||
| 41 | base => 'RPC::XML::string', | ||||||||||
| 42 | }, | ||||||||||
| 43 | ipv6_address => { | ||||||||||
| 44 | base => 'RPC::XML::string', | ||||||||||
| 45 | }, | ||||||||||
| 46 | unsigned => { | ||||||||||
| 47 | base => 'RPC::XML::int', | ||||||||||
| 48 | }, | ||||||||||
| 49 | unsigned_short => { | ||||||||||
| 50 | base => 'RPC::XML::int', | ||||||||||
| 51 | }, | ||||||||||
| 52 | zonename => { | ||||||||||
| 53 | base => 'RPC::XML::string', | ||||||||||
| 54 | }, | ||||||||||
| 55 | |||||||||||
| 56 | # type list for result types not listed above | ||||||||||
| 57 | soa_record => { | ||||||||||
| 58 | base => 'RPC::XML::struct', | ||||||||||
| 59 | }, | ||||||||||
| 60 | ns_record => { | ||||||||||
| 61 | base => 'RPC::XML::struct', | ||||||||||
| 62 | }, | ||||||||||
| 63 | a_record => { | ||||||||||
| 64 | base => 'RPC::XML::struct', | ||||||||||
| 65 | }, | ||||||||||
| 66 | aaaa_record => { | ||||||||||
| 67 | base => 'RPC::XML::struct', | ||||||||||
| 68 | }, | ||||||||||
| 69 | ptr_record => { | ||||||||||
| 70 | base => 'RPC::XML::struct', | ||||||||||
| 71 | }, | ||||||||||
| 72 | cname_record => { | ||||||||||
| 73 | base => 'RPC::XML::struct', | ||||||||||
| 74 | }, | ||||||||||
| 75 | mx_record => { | ||||||||||
| 76 | base => 'RPC::XML::struct', | ||||||||||
| 77 | }, | ||||||||||
| 78 | txt_record => { | ||||||||||
| 79 | base => 'RPC::XML::struct', | ||||||||||
| 80 | }, | ||||||||||
| 81 | ds_record => { | ||||||||||
| 82 | base => 'RPC::XML::struct', | ||||||||||
| 83 | }, | ||||||||||
| 84 | rp_record => { | ||||||||||
| 85 | base => 'RPC::XML::struct', | ||||||||||
| 86 | }, | ||||||||||
| 87 | crs_mail_record => { | ||||||||||
| 88 | base => 'RPC::XML::struct', | ||||||||||
| 89 | }, | ||||||||||
| 90 | crs_web_record => { | ||||||||||
| 91 | base => 'RPC::XML::struct', | ||||||||||
| 92 | }, | ||||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | 6 | for my $type (keys %udns_types) { | |||||||||
| 97 | 132 | my $info = $udns_types{$type}; | |||||||||
| 98 | my $base = $info->{base} | ||||||||||
| 99 | 132 | ▶ | or die "No base class defined for $type type"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 132 | my $class = "RPC::XML::$type"; | |||||||||
| 101 | |||||||||||
| 102 | 6 | ▶ | no strict 'refs'; ## no critic | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 103 | die "Class $class already exists" | ||||||||||
| 104 | 132 | ▶ | if @{"${class}::ISA"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 132 | @{"${class}::ISA"} = ($base); | |||||||||
| 106 | |||||||||||
| 107 | 132 | ▶ | if ($type =~ m/_/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | # we need to compensate for the default as_string method that will | ||||||||||
| 109 | # replace '_' with '.' in the type name, by installing our own in | ||||||||||
| 110 | # our subclass that doesn't do that. | ||||||||||
| 111 | 90 | ▶ | *{"${class}::as_string"} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.1
| |||||||||||
| 112 | 0 | my $self = shift; | |||||||||
| 113 | 0 | my $class = ref $self; | |||||||||
| 114 | 0 | $class =~ s/^.*\://; | |||||||||
| 115 | 0 | return "<$class>$$self</$class>"; | |||||||||
| 116 | 90 | }; | |||||||||
| 117 | } | ||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | 6 | ▶ | sub _type_to_class_map { | ||||||||
|
Subroutine
_type_to_class_map: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 6 | return { map { $_ => "RPC::XML::$_" } keys %udns_types } | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 6 | 1; | |||||||||