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 mesage
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 Net::DBus::Bind‐
35 ing::Iterator object which is capable of iterating over mock message
36 objects. Instances of this module are not created directly, instead
37 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 signa‐
71 ture, 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 itera‐
98 tor. An error will be raised if this build of Perl does not support
99 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 $value = $iter->get()
107 my $value = $iter->get($type);
108 Get the current value pointed to by this iterator. If the optional
109 $type parameter is supplied, the wire type will be compared with
110 the desired type & a warning output if their differ. The $type
111 value must be one of the "Net::DBus::Binding::Message::TYPE*" con‐
112 stants.
113
114 my $hashref = $iter->get_dict()
115 If the iterator currently points to a dictionary value, unmarshalls
116 and returns the value as a hash reference.
117
118 my $hashref = $iter->get_array()
119 If the iterator currently points to an array value, unmarshalls and
120 returns the value as a array reference.
121
122 my $hashref = $iter->get_variant()
123 If the iterator currently points to a variant value, unmarshalls
124 and returns the value contained in the variant.
125
126 my $hashref = $iter->get_struct()
127 If the iterator currently points to an struct value, unmarshalls
128 and returns the value as a array reference. The values in the array
129 correspond to members of the struct.
130
131 $iter->append($value)
132 $iter->append($value, $type)
133 Appends a value to the message associated with this iterator. The
134 value is marshalled into wire format, according to the following
135 rules.
136
137 If the $value is an instance of Net::DBus::Binding::Value, the
138 embedded data type is used.
139
140 If the $type parameter is supplied, that is taken to represent the
141 data type. The type must be one of the "Net::DBus::Binding::Mes‐
142 sage::TYPE_*" constants.
143
144 Otherwise, the data type is chosen to be a string, dict or array
145 according to the perl data types SCALAR, HASH or ARRAY.
146
147 my $type = $iter->guess_type($value)
148 Make a best guess at the on the wire data type to use for mar‐
149 shalling $value. If the value is a hash reference, the dictionary
150 type is returned; if the value is an array reference the array type
151 is returned; otherwise the string type is returned.
152
153 my $sig = $iter->format_signature($type)
154 Given a data type representation, construct a corresponding signa‐
155 ture string
156
157 $iter->append_array($value, $type)
158 Append an array of values to the message. The $value parameter must
159 be an array reference, whose elements all have the same data type
160 specified by the $type parameter.
161
162 $iter->append_struct($value, $type)
163 Append a struct to the message. The $value parameter must be an
164 array reference, whose elements correspond to members of the struc‐
165 ture. The $type parameter encodes the type of each member of the
166 struct.
167
168 $iter->append_dict($value, $type)
169 Append a dictionary to the message. The $value parameter must be an
170 hash reference.The $type parameter encodes the type of the key and
171 value of the hash.
172
173 $iter->append_variant($value)
174 Append a value to the message, encoded as a variant type. The
175 $value can be of any type, however, the variant will be encoded as
176 either a string, dictionary or array according to the rules of the
177 "guess_type" method.
178
179 my $type = $iter->get_arg_type
180 Retrieves the type code of the value pointing to by this iterator.
181 The returned code will correspond to one of the constants
182 "Net::DBus::Binding::Message::TYPE_*"
183
184 my $type = $iter->get_element_type
185 If the iterator points to an array, retrieves the type code of
186 array elements. The returned code will correspond to one of the
187 constants "Net::DBus::Binding::Message::TYPE_*"
188
190 It doesn't completely replicate the API of Net::DBus::Binding::Itera‐
191 tor, merely enough to make the high level bindings work in a test sce‐
192 nario.
193
195 Net::DBus::Test::MockMessage, Net::DBus::Binding::Iterator,
196 <http://www.mockobjects.com/Faq.html>
197
199 Copyright 2006 Daniel Berrange <dan@berrange.com>
200
201
202
203perl v5.8.8 2008-02-20 Net::DBus::Test::MockIterator(3)