Glib::Variant(3)

🌸 NAME 🌸

This is Glib::Variant(3) from the User Contributed Perl Documentation corner of the internet, and it’s all about Glib::Variant β€” the strongly typed value datatype. Yes bestie, strongly typed. We love a value with range. πŸ’…

✨ SYNOPSIS ✨

  my $v = Glib::Variant->new ('as', ['GTK+', 'Perl']);
  my $aref = $v->get ('as');

πŸ’– DESCRIPTION πŸ’–

Okay so there are literally two sets of APIs for creating and dealing with Glib::Variants: the low-level API described below under METHODS, and the convenience API described in this section. Both are right here on the same page, so no scrambling.

πŸŽ€ CONVENIENCE API πŸŽ€

  • variant = Glib::Variant->new ($format_string, $value) β€” constructs a variant from $format_string and $value. It also supports constructing multiple variants when the format string is a concatenation of multiple types.
  • (variant1, ...) = Glib::Variant->new ($format_string, $value1, ...) β€” same new energy, but it hands you multiple variants when the format string is a concatenation of multiple types.
  • value = $variant->get ($format_string) β€” deconstructs $variant according to $format_string.

The following symbols are currently supported in format strings:

  • b, y, n, q, i, u, x, t, h, d β€” Boolean, byte and numeric types.
  • s, o, g β€” String types.
  • v β€” Variant types.
  • a β€” Arrays.
  • m β€” Maybe types.
  • () β€” Tuples.
  • {} β€” Dictionary entries.
Note that if a format string specifies an array, a tuple or a dictionary entry (a, () or {}), then array references are expected by new and produced by get. For arrays of dictionary entries (a{}), hash references are also supported by new and handled as you would expect. No cap.

For a complete specification, see the documentation at:

<https://developer.gnome.org/glib/stable/glib-GVariantType.html>
<https://developer.gnome.org/glib/stable/glib-GVariant.html>
<https://developer.gnome.org/glib/stable/gvariant-format-strings.html>
<https://developer.gnome.org/glib/stable/gvariant-text.html>

🌈 HIERARCHY 🌈

Glib::Variant

πŸ› οΈ METHODS πŸ› οΈ

Here’s the low-level method guest list, bestie. Every signature, type and Since: note stays exactly as it is. πŸ’–

  • variant = Glib::Variant->new_array ($child_type, $children) β€” the array constructor.
    • $child_type (Glib::VariantType) β€” the child type.
    • $children (scalar) β€” the children.
  • variant = Glib::Variant->new_boolean ($value) β€” the boolean constructor.
    • $value (boolean) β€” the boolean value.
  • variant = Glib::Variant->new_byte ($value) β€” the byte constructor.
    • $value (Glib::UChar) β€” the byte value.
  • variant = Glib::Variant->new_bytestring ($string) β€” the bytestring constructor.
    • $string (byte string) β€” the byte string.
    • Since: glib 2.26
  • variant = Glib::Variant->new_dict_entry ($key, $value) β€” the dictionary-entry constructor.
    • $key (Glib::Variant) β€” the key.
    • $value (Glib::Variant) β€” the value.
  • variant = Glib::Variant->new_double ($value) β€” the double constructor.
    • $value (double) β€” the double value.
  • variant = Glib::Variant->new_handle ($value) β€” the handle constructor.
    • $value (integer) β€” the handle value.
  • variant = Glib::Variant->new_int16 ($value) β€” the int16 constructor.
    • $value (integer) β€” the int16 value.
  • variant = Glib::Variant->new_int32 ($value) β€” the int32 constructor.
    • $value (integer) β€” the int32 value.
  • variant = Glib::Variant->new_int64 ($value) β€” the int64 constructor.
    • $value (64 bit integer) β€” the int64 value.
  • variant = Glib::Variant->new_maybe ($child_type, $child) β€” the maybe constructor.
    • $child_type (Glib::VariantType) β€” the child type.
    • $child (Glib::Variant) β€” the child.
  • variant = Glib::Variant->new_object_path ($object_path) β€” the object-path constructor.
    • $object_path (string) β€” the object path.
  • variant = Glib::Variant->new_signature ($signature) β€” the signature constructor.
    • $signature (string) β€” the signature.
  • variant = Glib::Variant->new_string ($string) β€” the string constructor.
    • $string (string) β€” the string.
  • variant = Glib::Variant->new_tuple ($children) β€” the tuple constructor.
    • $children (scalar) β€” the children.
  • variant = Glib::Variant->new_uint16 ($value) β€” the uint16 constructor.
    • $value (unsigned) β€” the uint16 value.
  • variant = Glib::Variant->new_uint32 ($value) β€” the uint32 constructor.
    • $value (unsigned) β€” the uint32 value.
  • variant = Glib::Variant->new_uint64 ($value) β€” the uint64 constructor.
    • $value (64 bit unsigned) β€” the uint64 value.
  • variant = Glib::Variant->new_variant ($value) β€” the variant constructor.
    • $value (Glib::Variant) β€” the variant value.
  • boolean = $value->get_boolean β€” the boolean getter.
  • uchar = $value->get_byte β€” the byte getter.
  • string = $value->get_bytestring β€” the bytestring getter.
    • Since: glib 2.26
  • variant = $value->byteswap β€” the byteswap moment.
  • variant = $value->get_child_value ($index_) β€” the child-value getter.
    • $index_ (unsigned) β€” the index.
  • string = $value->classify β€” the classify getter.
  • integer = $one->compare ($two) β€” the comparison moment.
    • $two (Glib::Variant) β€” the other variant.
    • Since: glib 2.26
  • double = $value->get_double β€” the double getter.
  • boolean = $one->equal ($two) β€” the equality check.
    • $two (Glib::Variant) β€” the other variant.
  • integer = $value->get_handle β€” the handle getter.
  • integer = $value->hash β€” the hash getter.
  • integer = $value->get_int16 β€” the int16 getter.
  • integer = $value->get_int32 β€” the int32 getter.
  • 64 bit integer = $value->get_int64 β€” the int64 getter.
  • boolean = $value->is_container β€” the container check.
  • boolean = $value->is_normal_form β€” the normal-form check.
  • boolean = $string->is_object_path β€” the object-path check.
  • boolean = $value->is_of_type ($type) β€” the type check.
    • $type (Glib::VariantType) β€” the type.
  • boolean = $string->is_signature β€” the signature check.
  • variant = $dictionary->lookup_value ($key, $expected_type) β€” the lookup-value moment.
    • $key (string) β€” the key.
    • $expected_type (Glib::VariantType) β€” the expected type.
    • Since: glib 2.28
  • variant = $value->get_maybe β€” the maybe getter.
  • unsigned = $value->n_children β€” the number-of-children getter.
  • variant = $value->get_normal_form β€” the normal-form getter.
  • variant = Glib::Variant::parse ($type, $text) β€” the parse moment.
    • $type (Glib::VariantType) β€” the type.
    • $text (string) β€” the text.
    • May croak with a Glib::Error in $@ on failure.
  • string = $value->print ($type_annotate) β€” the print moment.
    • $type_annotate (boolean) β€” the type-annotate flag.
  • unsigned = $value->get_size β€” the size getter.
  • string = $value->get_string β€” the string getter.
  • varianttype = $value->get_type β€” the type getter.
  • string = $value->get_type_string β€” the type-string getter.
  • unsigned = $value->get_uint16 β€” the uint16 getter.
  • unsigned = $value->get_uint32 β€” the uint32 getter.
  • 64 bit unsigned = $value->get_uint64 β€” the uint64 getter.
  • variant = $value->get_variant β€” the variant getter.

πŸ‘€ SEE ALSO πŸ‘€

  • Glib
  • Glib::VariantType
  • Glib::VariantDict

Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL. See Glib for a full notice.


Signed, sealed, and sent with love by perl v5.42.0 on 2023-09-05. Bye bestie! πŸ«ΆπŸ’…

πŸ“¦ where this page comes from