| 1 | package VMOMI::PrimitiveType; | ||
| 2 | |||
| 3 | use Encode qw(decode_utf8 encode_utf8); | ||
| 4 | |||
| 5 | use constant P5NS => 'VMOMI'; | ||
| 6 | |||
| 7 | sub new { | ||
| 8 | my ($class, $val, $type) = @_; | ||
| 9 | my $self = { val => $val, type => $type }; | ||
| 10 | return bless $self, $class; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub serialize { | ||
| 14 | my ($self, $tag) = @_; | ||
| 15 | my ($node, $value, $xsd_type); | ||
| 16 | |||
| 17 | $xsd_type = "xsd:" . $self->{'type'}; | ||
| 18 | $node = new XML::LibXML::Element($tag); | ||
| 19 | $node->setAttribute('xsi:type', $xsd_type); | ||
| 20 | |||
| 21 | $value = encode_utf8($self->{'val'}); | ||
| 22 | $node->appendText($value); | ||
| 23 | |||
| 24 | return $node; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub val { | ||
| 28 | my $self = shift; | ||
| 29 | $self->{'val'} = shift if @_; | ||
| 30 | return $self->{'val'}; | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; |