XPIDL/XPT/InterfaceDescriptor.pm untested

filter: Statementstmt 0.0% 0 / 106 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 158 CC 20 SCAR 48.3
CC
20
Cov
0%
stringify
210.0
demarshal
30.0
marshal
12.0
CRAP 125.3
1
2 package XPT::InterfaceDescriptor;
3
4 use strict;
5 use warnings;
6
7 use base qw(XPT);
8
9 sub demarshal {
10 my ($r_buffer, $r_offset) = @_;
11
12 my $parent_interface_index = XPT::Read16($r_buffer, $r_offset);
13 my @method_descriptors = ();
14 my @const_descriptors = ();
15 my $flags = 0;
16 eval {
17 my $num_methods = XPT::Read16($r_buffer, $r_offset);
18 while ($num_methods --) {
19 my $method = XPT::MethodDescriptor::demarshal($r_buffer, $r_offset);
20 push @method_descriptors, $method;
21 }
22 my $num_constants = XPT::Read16($r_buffer, $r_offset);
23 while ($num_constants --) {
24 my $const = XPT::ConstDescriptor::demarshal($r_buffer, $r_offset);
25 push @const_descriptors, $const;
26 }
27 $flags = XPT::Read8($r_buffer, $r_offset);
28 };
29 if ($@) {
30 $XPT::demarshal_retcode = 1;
31 if ($XPT::demarshal_not_abort) {
32 warn $@;
33 }
34 else {
35 die $@;
36 }
37 }
38
39 return new XPT::InterfaceDescriptor(
40 parent_interface_index => $parent_interface_index,
41 method_descriptors => \@method_descriptors,
42 const_descriptors => \@const_descriptors,
43 is_scriptable => ($flags & 0x80) ? 1 : 0,
44 is_function => ($flags & 0x40) ? 1 : 0,
45 );
46 }
47
48 sub marshal {
49 my $self = shift;
50 my $method_descriptors = q{};
51 foreach (@{$self->{method_descriptors}}) {
52 $method_descriptors .= $_->marshal();
53 }
54 my $const_descriptors = q{};
55 foreach (@{$self->{const_descriptors}}) {
56 $const_descriptors .= $_->marshal();
57 }
58 my $flags = 0;
59 $flags |= 0x80 if ($self->{is_scriptable});
60 $flags |= 0x40 if ($self->{is_function});
61 my $offset = 1 + length($XPT::data_pool);
62 $XPT::data_pool .= XPT::Write16($self->{parent_interface_index});
63 $XPT::data_pool .= XPT::Write16(scalar(@{$self->{method_descriptors}}));
64 $XPT::data_pool .= $method_descriptors;
65 $XPT::data_pool .= XPT::Write16(scalar(@{$self->{const_descriptors}}));
66 $XPT::data_pool .= $const_descriptors;
67 $XPT::data_pool .= XPT::Write8($flags);
68 return XPT::Write32($offset);
69 }
70
71 sub stringify {
72 my $self = shift;
73 my ($indent) = @_;
74 $indent = q{ } x 2 unless (defined $indent);
75 my $new_indent = $indent . q{ } x 3;
76 my $more_indent = $new_indent . q{ } x 3;
77
78 my $str = q{};
79 if ($self->{parent_interface_index}) {
80 my $name;
81 if (defined $self->{parent_interface}) {
82 my $itf = $self->{parent_interface};
83 if (ref $itf) {
84 $name = $itf->{name_space} . '::' . $itf->{name};
85 }
86 else {
87 $name = $itf;
88 }
89 }
90 else {
91 $name = "UNKNOWN_INTERFACE";
92 }
93 $str .= $indent . "Parent: " . $name . "\n"
94 }
95 $str .= $indent . "Flags:\n";
96 $str .= $new_indent . "Scriptable: " . ($self->{is_scriptable} ? 'TRUE' : 'FALSE') . "\n";
97 $str .= $new_indent . "Function: " . ($self->{is_function} ? 'TRUE' : 'FALSE') . "\n";
98 if ($XPT::stringify_verbose and exists $self->{parent_interface_index}) {
99 $str .= $indent . "Index of parent interface (in data pool): ";
100 $str .= $self->{parent_interface_index} . "\n";
101 }
102 if (scalar @{$self->{method_descriptors}}) {
103 if ($XPT::stringify_verbose) {
104 $str .= $indent . "# of Method Descriptors: ";
105 $str .= scalar(@{$self->{method_descriptors}}) . "\n";
106 }
107 else {
108 $str .= $indent . "Methods:\n";
109 }
110 my $nb = 0;
111 foreach (@{$self->{method_descriptors}}) {
112 if ($XPT::stringify_verbose) {
113 $str .= $new_indent . "Method #" . $nb ++ . ":\n";
114 $str .= $_->stringify($more_indent);
115 }
116 else {
117 $str .= $_->stringify($new_indent);
118 }
119 }
120 }
121 else {
122 $str .= $indent . "Methods:\n";
123 $str .= $new_indent . "No Methods\n";
124 }
125 if (scalar @{$self->{const_descriptors}}) {
126 if ($XPT::stringify_verbose) {
127 $str .= $indent . "# of Constant Descriptors: ";
128 $str .= scalar(@{$self->{const_descriptors}}) . "\n";
129 }
130 else {
131 $str .= $indent . "Constants:\n";
132 }
133 my $nb = 0;
134 foreach (@{$self->{const_descriptors}}) {
135 if ($XPT::stringify_verbose) {
136 $str .= $new_indent . "Constant #" . $nb ++ . ":\n";
137 $str .= $_->stringify($more_indent);
138 }
139 else {
140 $str .= $_->stringify($new_indent);
141 }
142 }
143 }
144 else {
145 $str .= $indent . "Constants:\n";
146 $str .= $new_indent . "No Constants\n";
147 }
148 return $str;
149 }
150
151 1;
152