| 1 | package VMOMI::SimpleType; | ||
| 2 | |||
| 3 | use Encode qw(decode_utf8 encode_utf8); | ||
| 4 | |||
| 5 | sub new { | ||
| 6 | my ($class, $val) = @_; | ||
| 7 | return bless { val => $val }, $class; | ||
| 8 | } | ||
| 9 | |||
| 10 | sub deserialize { | ||
| 11 | my ($class, $reader) = @_; | ||
| 12 | my ($self, $content); | ||
| 13 | |||
| 14 | return undef if not defined $reader; | ||
| 15 | $content = $reader->readInnerXml(); | ||
| 16 | $self = { val => decode_utf8($content) }; | ||
| 17 | return bless $self, $class; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub serialize { | ||
| 21 | my ($self, $tag, $emit_type) = @_; | ||
| 22 | my ($node, $value); | ||
| 23 | |||
| 24 | $node = new XML::LibXML::Element($tag); | ||
| 25 | if ($emit_type) { | ||
| 26 | $node->setAttribute('xsi:type', $emit_type); | ||
| 27 | } | ||
| 28 | |||
| 29 | $value = encode_utf8($self->{'val'}); | ||
| 30 | $node->appendText($value); | ||
| 31 | |||
| 32 | return $node; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub TO_JSON { | ||
| 36 | my $self = shift; | ||
| 37 | |||
| 38 | my $class = ref($self); | ||
| 39 | $class =~ s/VMOMI:://; | ||
| 40 | return {_class => $class, val => $self->{'val'}}; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub val { | ||
| 44 | my $self = shift; | ||
| 45 | $self->{'val'} = shift if @_; | ||
| 46 | return $self->{'val'}; | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | 1; |