Net::DB...Iterator(3)
π
Net::DBus::Test::MockIterator β the Net::DB...Iterator(3) page, but make it make sense π
okay bestie, so this whole page is about Net::DBus::Test::MockIterator β an iterator over a mock message. yes it's a real module, yes it's in the Net::DBus::Test::MockMessage fam, and yes I'm gonna walk you through every single method. no skipping, no cap. β¨
πΈ NAME πΈ
Net::DBus::Test::MockIterator β Iterator over a mock message. that's it, that's the whole vibe. π
π¦ SYNOPSIS π¦
π Creating a new message
my $msg = new Net::DBus::Test::MockMessage
my $iterator = $msg->iterator;
$iterator->append_boolean(1);
$iterator->append_byte(123);
π Reading from a message
my $msg = ...get it from somewhere...
my $iter = $msg->iterator();
my $i = 0;
while ($iter->has_next()) {
$iter->next();
$i++;
if ($i == 1) {
my $val = $iter->get_boolean();
} elsif ($i == 2) {
my $val = $iter->get_byte();
}
}
see how that works? append stuff on one side, walk it back on the other. iconic behavior honestly. π₯
β DESCRIPTION β
So this module is literally the "mock" counterpart to the Net::DBus::Binding::Iterator object, and it's capable of iterating over mock message objects. very demure, very mindful. π§
big important note: you do not create instances of this module directly. nope. you get them via the "iterator" method on the Net::DBus::Test::MockMessage module. periodt. π
π METHODS π
π $res = $iter->has_next()
Determines if there are any more fields in the message itertor to be read. Returns a positive value if there are more fields, zero otherwise. basically a little vibe check before you keep going. π«Ά
π $success = $iter->next()
Skips the iterator onto the next field in the message. Returns a positive value if the current field pointer was successfully advanced, zero otherwise. hit it and quit it. β
π the read/write pairs β boolean, byte, string & friends π
okay so these all come in little getter/setter duos, and honestly? obsessed with the symmetry. π
my $val = $iter->get_boolean()/$iter->append_boolean($val);β Read or write a boolean value from/to the message iteratormy $val = $iter->get_byte()/$iter->append_byte($val);β Read or write a single byte value from/to the message iterator.my $val = $iter->get_string()/$iter->append_string($val);β Read or write a UTF-8 string value from/to the message iteratormy $val = $iter->get_object_path()/$iter->append_object_path($val);β Read or write a UTF-8 string value, whose contents is a valid object path, from/to the message iteratormy $val = $iter->get_signature()/$iter->append_signature($val);β Read or write a UTF-8 string, whose contents is a valid type signature, value from/to the message iteratormy $val = $iter->get_int16()/$iter->append_int16($val);β Read or write a signed 16 bit value from/to the message iteratormy $val = $iter->get_uint16()/$iter->append_uint16($val);β Read or write an unsigned 16 bit value from/to the message iteratormy $val = $iter->get_int32()/$iter->append_int32($val);β Read or write a signed 32 bit value from/to the message iteratormy $val = $iter->get_uint32()/$iter->append_uint32($val);β Read or write an unsigned 32 bit value from/to the message iteratormy $val = $iter->get_int64()/$iter->append_int64($val);β Read or write a signed 64 bit value from/to the message iterator. An error will be raised if this build of Perl does not support 64 bit integers πmy $val = $iter->get_uint64()/$iter->append_uint64($val);β Read or write an unsigned 64 bit value from/to the message iterator. An error will be raised if this build of Perl does not support 64 bit integers πmy $val = $iter->get_double()/$iter->append_double($val);β Read or write a double precision floating point value from/to the message iteratormy $val = $iter->get_unix_fd()/$iter->append_unix_fd($val);β Read or write a unix_fd value from/to the message iterator
heads up bestie: those two 64-bit ones will raise an error if your Perl build doesn't support 64 bit integers. not a drill. π
π my $value = $iter->get() / my $value = $iter->get($type)
Get the current value pointed to by this iterator. If the optional $type parameter is supplied, the wire type will be compared with the desired type & a warning output if their differ. The $type value must be one of the "Net::DBus::Binding::Message::TYPE*" constants. β¨
π my $hashref = $iter->get_dict()
If the iterator currently points to a dictionary value, unmarshalls and returns the value as a hash reference.
π my $hashref = $iter->get_array()
If the iterator currently points to an array value, unmarshalls and returns the value as a array reference.
π my $hashref = $iter->get_variant()
If the iterator currently points to a variant value, unmarshalls and returns the value contained in the variant.
π my $hashref = $iter->get_struct()
If the iterator currently points to an struct value, unmarshalls and returns the value as a array reference. The values in the array correspond to members of the struct.
π $iter->append($value) / $iter->append($value, $type)
Appends a value to the message associated with this iterator. The value is marshalled into wire format, according to the following rules π
- If the
$valueis an instance ofNet::DBus::Binding::Value, the embedded data type is used. - If the
$typeparameter is supplied, that is taken to represent the data type. The type must be one of the"Net::DBus::Binding::Message::TYPE_*"constants. - Otherwise, the data type is chosen to be a string, dict or array according to the perl data types SCALAR, HASH or ARRAY.
three rules, no ambiguity, slay. π
π my $type = $iter->guess_type($value)
Make a best guess at the on the wire data type to use for marshalling $value. If the value is a hash reference, the dictionary type is returned; if the value is an array reference the array type is returned; otherwise the string type is returned. she's guessing but she's right. πΈ
π my $sig = $iter->format_signature($type)
Given a data type representation, construct a corresponding signature string
π $iter->append_array($value, $type)
Append an array of values to the message. The $value parameter must be an array reference, whose elements all have the same data type specified by the $type parameter. matching types or it's not happening bestie. π¦
π $iter->append_struct($value, $type)
Append a struct to the message. The $value parameter must be an array reference, whose elements correspond to members of the structure. The $type parameter encodes the type of each member of the struct.
π $iter->append_dict($value, $type)
Append a dictionary to the message. The $value parameter must be an hash reference. The $type parameter encodes the type of the key and value of the hash.
π $iter->append_variant($value)
Append a value to the message, encoded as a variant type. The $value can be of any type, however, the variant will be encoded as either a string, dictionary or array according to the rules of the "guess_type" method. main character energy, flexible but predictable. π
π my $type = $iter->get_arg_type
Retrieves the type code of the value pointing to by this iterator. The returned code will correspond to one of the constants "Net::DBus::Binding::Message::TYPE_*" π
π my $type = $iter->get_element_type
If the iterator points to an array, retrieves the type code of array elements. The returned code will correspond to one of the constants "Net::DBus::Binding::Message::TYPE_*" π
π BUGS π
It doesn't completely replicate the API of Net::DBus::Binding::Iterator, merely enough to make the high level bindings work in a test scenario. so likeβ¦ it's a mock. adjust expectations accordingly. π
π AUTHOR π
Daniel P. Berrange
π COPYRIGHT π
Copyright (C) 2005-2009 Daniel P. Berrange
π§ SEE ALSO π§
Net::DBus::Test::MockMessage, Net::DBus::Binding::Iterator, <http://www.mockobjects.com/Faq.html>
okay that's the whole page, you ate that bestie π
β¨ β brought to you by perl v5.42.0 and dated 2019-12-17, so go forth and mock those iterators π¦π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms