---
name: "Glib::Variant"
section: "3pm"
platform: "linux"
package: "glib-perl"
version: "1.329.4-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Glib::Variant"
---

# Glib::Variant(3pm)

strongly typed value datatype

## NAME

Glib::Variant -  strongly typed value datatype

## SYNOPSIS

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

## DESCRIPTION

There are two sets of APIs for creating and dealing with `"Glib::Variant"`s: the low-level API described below under "METHODS", and the convenience API described in this section.

### CONVENIENCE API

- variant = Glib::Variant-\>new ($format\_string, $value)

  - (variant1, ...) = Glib::Variant-\>new ($format\_string, $value1, ...)

  Constructs a variant from `$format_string` and `$value`.  Also supports constructing 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:

```
  +------------------------------+---------------------------------+
  |            Symbol            |             Meaning             |
  +------------------------------+---------------------------------+
  | 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.

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

### variant = Glib::Variant-\>new\_array ($child\_type, $children)

- •

  `$child_type` (Glib::VariantType)

- •

  `$children` (scalar)

### variant = Glib::Variant-\>new\_boolean ($value)

- •

  `$value` (boolean)

### variant = Glib::Variant-\>new\_byte ($value)

- •

  `$value` (Glib::UChar)

### variant = Glib::Variant-\>new\_bytestring ($string)

- •

  `$string` (byte string)

Since: glib 2.26

### variant = Glib::Variant-\>new\_dict\_entry ($key, $value)

- •

  `$key` (Glib::Variant)

- •

  `$value` (Glib::Variant)

### variant = Glib::Variant-\>new\_double ($value)

- •

  `$value` (double)

### variant = Glib::Variant-\>new\_handle ($value)

- •

  `$value` (integer)

### variant = Glib::Variant-\>new\_int16 ($value)

- •

  `$value` (integer)

### variant = Glib::Variant-\>new\_int32 ($value)

- •

  `$value` (integer)

### variant = Glib::Variant-\>new\_int64 ($value)

- •

  `$value` (64 bit integer)

### variant = Glib::Variant-\>new\_maybe ($child\_type, $child)

- •

  `$child_type` (Glib::VariantType)

- •

  `$child` (Glib::Variant)

### variant = Glib::Variant-\>new\_object\_path ($object\_path)

- •

  `$object_path` (string)

### variant = Glib::Variant-\>new\_signature ($signature)

- •

  `$signature` (string)

### variant = Glib::Variant-\>new\_string ($string)

- •

  `$string` (string)

### variant = Glib::Variant-\>new\_tuple ($children)

- •

  `$children` (scalar)

### variant = Glib::Variant-\>new\_uint16 ($value)

- •

  `$value` (unsigned)

### variant = Glib::Variant-\>new\_uint32 ($value)

- •

  `$value` (unsigned)

### variant = Glib::Variant-\>new\_uint64 ($value)

- •

  `$value` (64 bit unsigned)

### variant = Glib::Variant-\>new\_variant ($value)

- •

  `$value` (Glib::Variant)

### boolean = $value-\>get\_boolean

### uchar = $value-\>get\_byte

### string = $value-\>get\_bytestring

Since: glib 2.26

### variant = $value-\>byteswap

### variant = $value-\>get\_child\_value ($index\_)

- •

  `$index_` (unsigned)

### string = $value-\>classify

### integer = $one-\>compare ($two)

- •

  `$two` (Glib::Variant)

Since: glib 2.26

### double = $value-\>get\_double

### boolean = $one-\>equal ($two)

- •

  `$two` (Glib::Variant)

### integer = $value-\>get\_handle

### integer = $value-\>hash

### integer = $value-\>get\_int16

### integer = $value-\>get\_int32

### 64 bit integer = $value-\>get\_int64

### boolean = $value-\>is\_container

### boolean = $value-\>is\_normal\_form

### boolean = $string-\>is\_object\_path

### boolean = $value-\>is\_of\_type ($type)

- •

  `$type` (Glib::VariantType)

### boolean = $string-\>is\_signature

### variant = $dictionary-\>lookup\_value ($key, $expected\_type)

- •

  `$key` (string)

- •

  `$expected_type` (Glib::VariantType)

Since: glib 2.28

### variant = $value-\>get\_maybe

### unsigned = $value-\>n\_children

### variant = $value-\>get\_normal\_form

### variant = Glib::Variant::parse ($type, $text)

- •

  `$type` (Glib::VariantType)

- •

  `$text` (string)

May croak with a Glib::Error in $@ on failure.

### string = $value-\>print ($type\_annotate)

- •

  `$type_annotate` (boolean)

### unsigned = $value-\>get\_size

### string = $value-\>get\_string

### varianttype = $value-\>get\_type

### string = $value-\>get\_type\_string

### unsigned = $value-\>get\_uint16

### unsigned = $value-\>get\_uint32

### 64 bit unsigned = $value-\>get\_uint64

### variant = $value-\>get\_variant

## SEE ALSO

Glib, Glib::VariantType, Glib::VariantDict

## COPYRIGHT

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

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