1Net::DBus::Test::MockItUesreartoCro(n3t)ributed Perl DocNuemte:n:tDaBtuiso:n:Test::MockIterator(3)
2
3
4
6 Net::DBus::Test::MockIterator - Iterator over a mock message
7
9 Creating a new message
10
11 my $msg = new Net::DBus::Test::MockMessage
12 my $iterator = $msg->iterator;
13
14 $iterator->append_boolean(1);
15 $iterator->append_byte(123);
16
17 Reading from a message
18
19 my $msg = ...get it from somewhere...
20 my $iter = $msg->iterator();
21
22 my $i = 0;
23 while ($iter->has_next()) {
24 $iter->next();
25 $i++;
26 if ($i == 1) {
27 my $val = $iter->get_boolean();
28 } elsif ($i == 2) {
29 my $val = $iter->get_byte();
30 }
31 }
32
34 This module provides a "mock" counterpart to the
35 Net::DBus::Binding::Iterator object which is capable of iterating over
36 mock message objects. Instances of this module are not created
37 directly, instead they are obtained via the "iterator" method on the
38 Net::DBus::Test::MockMessage module.
39
41 $res = $iter->has_next()
42 Determines if there are any more fields in the message itertor to
43 be read. Returns a positive value if there are more fields, zero
44 otherwise.
45
46 $success = $iter->next()
47 Skips the iterator onto the next field in the message. Returns a
48 positive value if the current field pointer was successfully
49 advanced, zero otherwise.
50
51 my $val = $iter->get_boolean()
52 $iter->append_boolean($val);
53 Read or write a boolean value from/to the message iterator
54
55 my $val = $iter->get_byte()
56 $iter->append_byte($val);
57 Read or write a single byte value from/to the message iterator.
58
59 my $val = $iter->get_string()
60 $iter->append_string($val);
61 Read or write a UTF-8 string value from/to the message iterator
62
63 my $val = $iter->get_object_path()
64 $iter->append_object_path($val);
65 Read or write a UTF-8 string value, whose contents is a valid
66 object path, from/to the message iterator
67
68 my $val = $iter->get_signature()
69 $iter->append_signature($val);
70 Read or write a UTF-8 string, whose contents is a valid type
71 signature, value from/to the message iterator
72
73 my $val = $iter->get_int16()
74 $iter->append_int16($val);
75 Read or write a signed 16 bit value from/to the message iterator
76
77 my $val = $iter->get_uint16()
78 $iter->append_uint16($val);
79 Read or write an unsigned 16 bit value from/to the message iterator
80
81 my $val = $iter->get_int32()
82 $iter->append_int32($val);
83 Read or write a signed 32 bit value from/to the message iterator
84
85 my $val = $iter->get_uint32()
86 $iter->append_uint32($val);
87 Read or write an unsigned 32 bit value from/to the message iterator
88
89 my $val = $iter->get_int64()
90 $iter->append_int64($val);
91 Read or write a signed 64 bit value from/to the message iterator.
92 An error will be raised if this build of Perl does not support 64
93 bit integers
94
95 my $val = $iter->get_uint64()
96 $iter->append_uint64($val);
97 Read or write an unsigned 64 bit value from/to the message
98 iterator. An error will be raised if this build of Perl does not
99 support 64 bit integers
100
101 my $val = $iter->get_double()
102 $iter->append_double($val);
103 Read or write a double precision floating point value from/to the
104 message iterator
105
106 my $val = $iter->get_unix_fd()
107 $iter->append_unix_fd($val);
108 Read or write a unix_fd value from/to the message iterator
109
110 my $value = $iter->get()
111 my $value = $iter->get($type);
112 Get the current value pointed to by this iterator. If the optional
113 $type parameter is supplied, the wire type will be compared with
114 the desired type & a warning output if their differ. The $type
115 value must be one of the "Net::DBus::Binding::Message::TYPE*"
116 constants.
117
118 my $hashref = $iter->get_dict()
119 If the iterator currently points to a dictionary value, unmarshalls
120 and returns the value as a hash reference.
121
122 my $hashref = $iter->get_array()
123 If the iterator currently points to an array value, unmarshalls and
124 returns the value as a array reference.
125
126 my $hashref = $iter->get_variant()
127 If the iterator currently points to a variant value, unmarshalls
128 and returns the value contained in the variant.
129
130 my $hashref = $iter->get_struct()
131 If the iterator currently points to an struct value, unmarshalls
132 and returns the value as a array reference. The values in the array
133 correspond to members of the struct.
134
135 $iter->append($value)
136 $iter->append($value, $type)
137 Appends a value to the message associated with this iterator. The
138 value is marshalled into wire format, according to the following
139 rules.
140
141 If the $value is an instance of Net::DBus::Binding::Value, the
142 embedded data type is used.
143
144 If the $type parameter is supplied, that is taken to represent the
145 data type. The type must be one of the
146 "Net::DBus::Binding::Message::TYPE_*" constants.
147
148 Otherwise, the data type is chosen to be a string, dict or array
149 according to the perl data types SCALAR, HASH or ARRAY.
150
151 my $type = $iter->guess_type($value)
152 Make a best guess at the on the wire data type to use for
153 marshalling $value. If the value is a hash reference, the
154 dictionary type is returned; if the value is an array reference the
155 array type is returned; otherwise the string type is returned.
156
157 my $sig = $iter->format_signature($type)
158 Given a data type representation, construct a corresponding
159 signature string
160
161 $iter->append_array($value, $type)
162 Append an array of values to the message. The $value parameter must
163 be an array reference, whose elements all have the same data type
164 specified by the $type parameter.
165
166 $iter->append_struct($value, $type)
167 Append a struct to the message. The $value parameter must be an
168 array reference, whose elements correspond to members of the
169 structure. The $type parameter encodes the type of each member of
170 the struct.
171
172 $iter->append_dict($value, $type)
173 Append a dictionary to the message. The $value parameter must be an
174 hash reference.The $type parameter encodes the type of the key and
175 value of the hash.
176
177 $iter->append_variant($value)
178 Append a value to the message, encoded as a variant type. The
179 $value can be of any type, however, the variant will be encoded as
180 either a string, dictionary or array according to the rules of the
181 "guess_type" method.
182
183 my $type = $iter->get_arg_type
184 Retrieves the type code of the value pointing to by this iterator.
185 The returned code will correspond to one of the constants
186 "Net::DBus::Binding::Message::TYPE_*"
187
188 my $type = $iter->get_element_type
189 If the iterator points to an array, retrieves the type code of
190 array elements. The returned code will correspond to one of the
191 constants "Net::DBus::Binding::Message::TYPE_*"
192
194 It doesn't completely replicate the API of
195 Net::DBus::Binding::Iterator, merely enough to make the high level
196 bindings work in a test scenario.
197
199 Daniel P. Berrange
200
202 Copyright (C) 2005-2009 Daniel P. Berrange
203
205 Net::DBus::Test::MockMessage, Net::DBus::Binding::Iterator,
206 <http://www.mockobjects.com/Faq.html>
207
208
209
210perl v5.32.0 2020-07-28 Net::DBus::Test::MockIterator(3)