VMOMI/SimpleType.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 51 CC 4 SCAR 14.3
CC
4
Cov
0%
deserialize
6.0
serialize
6.0
val
6.0
CRAP 4.2
1 package VMOMI::SimpleType;
2  
3 use strict;
4 use warnings;
5  
6 use Encode qw(decode_utf8 encode_utf8);
7  
8 sub new {
9 my ($class, $val) = @_;
10 return bless { val => $val }, $class;
11 }
12  
13 sub deserialize {
14 my ($class, $reader) = @_;
15 my ($self, $content);
16
17 return undef if not defined $reader;
18 $content = $reader->readInnerXml();
19 $self = { val => decode_utf8($content) };
20 return bless $self, $class;
21 }
22  
23 sub serialize {
24 my ($self, $tag, $emit_type) = @_;
25 my ($node, $value);
26
27 $node = new XML::LibXML::Element($tag);
28 if ($emit_type) {
29 $node->setAttribute('xsi:type', $emit_type);
30 }
31
32 $value = encode_utf8($self->{'val'});
33 $node->appendText($value);
34
35 return $node;
36 }
37  
38 sub TO_JSON {
39 my $self = shift;
40  
41 my $class = ref($self);
42 $class =~ s/VMOMI:://;
43 return {_class => $class, val => $self->{'val'}};
44 }
45  
46 sub val {
47 my $self = shift;
48 $self->{'val'} = shift if @_;
49 return $self->{'val'};
50 }
51  
52  
53 1;