Glib::Type(3)
π NAME π
Glib::Type β Utilities for dealing with the GLib Type system
Also, for the record, this is Glib::Type(3) from User Contributed Perl Documentation β folding that manual name in right here so we donβt have to copy the header line like a robot. π
πΈ DESCRIPTION πΈ
Okay so this package defines several utilities for dealing with the GLib type system from Perl. Because there are some fundamental differences in how the GLib and Perl type systems work, a fair amount of the binding magic leaks out β and you can find most of that in the Glib::Type::register* functions, which register new types with the GLib type system. No cap.
Most of the rest of the functions provide introspection functionality, like listing properties and values and other cool stuff thatβs used mainly by Glibβs reference documentation generator (see Glib::GenPod). Itβs giving backstage-pass energy. β¨
π METHODS π
Hereβs the method roll call, bestie β same order, same facts, extra sparkle. π¦
π¦ list = Glib::Type->list_ancestors ($package)
$package(string) β the package whose ancestry weβre checking.
List the ancestry of package, as seen by the GLib type system. The important difference is that GLibβs type system implements only single inheritance, whereas Perlβs @ISA allows multiple inheritance. So yeah, GLib is monogamous about inheritance. π
This returns the package names of the ancestral types in reverse order, with the root of the tree at the end of the list. Root at the end β periodt.
See also list_interfaces ().
π list = Glib::Type->list_interfaces ($package)
$package(string) β the package weβre snooping on.
List the GInterfaces implemented by the type associated with package. The interfaces are returned as package names. Slay.
β list = Glib::Type->list_signals ($package)
$package(string) β the package whose signals we want.
List the signals associated with package. This lists only the signals for package, not any of its parents β no inherited sneakiness here. The signals are returned as a list of anonymous hashes which mirror the GSignalQuery structure defined in the C API reference.
Each hash has these keys:
signal_idβ Numeric id of a signal. Itβs rare that youβll need this in Gtk2-Perl.signal_nameβ Name of the signal, such as what youβd pass tosignal_connect.itypeβ The instance type for which this signal is defined.signal_flagsβGSignalFlagsdescribing this signal.return_typeβ The return type expected from handlers for this signal. Ifundefor not present, then no return is expected. The type name is mapped to the corresponding Perl package name if it is known; otherwise you get the raw C name straight from GLib.param_typesβ The types of the parameters passed to any callbacks connected to the emission of this signal. The list does not include the instance, which is always first, and the user data fromsignal_connect, which is always last (unless the signal was connected withswap, which swaps the instance and the data, but you get the point).
π§ list = Glib::Type->list_values ($package)
$package(string) β the enum or flags package to inspect.
List the legal values for the GEnum or GFlags type $package. If $package is not a package name registered with the bindings, this name is passed on to g_type_from_name() to see if itβs a registered flags or enum type that just hasnβt been registered with the bindings by gperl_register_fundamental() (see Glib::xsapi). If $package is not the name of an enum or flags type, this function will croak. Like, actually croak β not a vibe. π
Returns the values as a list of hashes, one hash for each value, containing the value, name and nickname, eg. for Glib::SignalFlags:
{ value => 8,
name => 'G_SIGNAL_NO_RECURSE',
nick => 'no-recurse'
}
π«Ά string = Glib::Type->package_from_cname ($cname)
$cname(string) β the C type name to translate.
Convert a C type name to the corresponding Perl package name. If no package is registered to that type, returns $cname. Simple, iconic, done.
π Glib::Type->register ($parent_class, $new_class, ...)
$parent_class(package) β type from which to derive$new_class(package) β name of new type...(list) β arguments for creation
Register a new type with the GLib type system.
This is a traffic-cop function. If $parent_type derives from Glib::Object, this passes the arguments through to register_object. If $parent_type is Glib::Flags or Glib::Enum, this strips $parent_type and passes the remaining args on to register_enum or register_flags. See those functionsβ documentation for more information.
π Glib::Type->register_enum ($name, ...)
$name(string) β package name for new enum type...(list) β new enumβs values; see description.
Register and initialize a new Glib::Enum type with the provided values. This creates a type properly registered GLib so that it can be used for property and signal parameter or return types created with Glib::Type->register or Glib::Object::Subclass. Itβs giving official paperwork but make it cute. π
The list of values is used to create the nicknames that are used in general Perl code; the actual numeric values used at the C level are automatically assigned, starting with 1. If you need to specify a particular numeric value for a nick, use an array reference containing the nickname and the numeric value, instead. You may mix and match the two styles. Obsessed with flexibility.
Glib::Type->register_enum ('MyFoo::Bar',
'value-one', # assigned 1
'value-two', # assigned 2
['value-three' => 15 ], # explicit 15
['value-four' => 35 ], # explicit 35
'value-five', # assigned 5
);
If you use the array-ref form, beware: the code performs no validation for unique values. So like, donβt duplicate your faves and expect a warning, bestie. π
π¦ Glib::Type->register_flags ($name, ...)
$name(string) β package name of new flags type...(list) β flag values, see discussion.
Register and initialize a new Glib::Flags type with the provided values. This creates a type properly registered GLib so that it can be used for property and signal parameter or return types created with Glib::Type->register or Glib::Object::Subclass. Main character type registration energy. π
The list of values is used to create the nicknames that are used in general Perl code; the actual numeric values used at the C level are automatically assigned, of the form 1<<i, starting with i = 0. If you need to specify a particular numeric value for a nick, use an array reference containing the nickname and the numeric value, instead. You may mix and match the two styles.
Glib::Type->register_flags ('MyFoo::Baz',
'value-one', # assigned 1<<0
'value-two', # assigned 1<<1
['value-three' => 1<<10 ], # explicit 1<<10
['value-four' => 0x0f ], # explicit 0x0f
'value-five', # assigned 1<<4
);
If you use the array-ref form, beware: the code performs no validation for unique values. Same warning, same energy. π
π Glib::Type->register_object ($parent_package, $new_package, ...)
$parent_package(string) β name of the parent package, which must be a derivative ofGlib::Object.$new_package(string) β usually__PACKAGE__....(list) β key/value pairs controlling how the class is created.
Register new_package as an officially GLib-sanctioned derivative of the (GObject derivative) parent_package. This automatically sets up an @ISA entry for you, and creates a new GObjectClass under the hood. We love a class that comes pre-assembled. β¨
The ... parameters are key/value pairs, currently supporting:
signals => HASHREFβ Thesignalskey contains a hash, keyed by signal names, which describes how to set up the signals fornew_package.
If the value is a code reference, the named signal must exist somewhere in parent_package or its ancestry; the code reference will be used to override the class closure for that signal. This is the officially sanctioned way to override virtual methods on Glib::Objects. The value may be a string rather than a code reference, in which case the sub with that name in new_package will be used. (The function should not be inherited.)
If the value is a hash reference, the key will be the name of a new signal created with the properties defined in the hash. All of the properties are optional, with defaults provided:
class_closure => subroutine or undefβ Use this code reference (or sub name) as the class closure (that is, the default handler for the signal). If not specified,do_signal_name, in the current package, is used.return_type => package name or undefβ Return type for the signal. If not specified, then the signal has void return.param_types => ARRAYREFβ Reference to a list of parameter types (package names), omitting the instance and user data. Callbacks connected to this signal will receive the instance object as the first argument, followed by arguments with the types listed here, and finally by any user data that was supplied when the callback was connected. Not specifying this key is equivalent to supplying an empty list, which actually means instance and maybe data.flags => Glib::SignalFlagsβ Flags describing this signalβs properties. See the GObject C API referenceβs description ofGSignalFlagsfor a complete description.accumulator => subroutine or undefβ The signal accumulator is a special callback that can be used to collect return values of the various callbacks that are called during a signal emission. Generally, you can omit this parameter; custom accumulators are used to do things like stopping signal propagation by return value or creating a list of returns, etc. See βSIGNALSβ inGlib::Object::Subclassfor details.
properties => ARRAYREFβ Array ofGlib::ParamSpecobjects, each describing an object property to add to the new type. These properties are available for use by all code that can access the object, regardless of implementation language. SeeGlib::ParamSpec. This list may be empty; if it is not, the functionsGET_PROPERTYandSET_PROPERTYin$new_packagewill be called to get and set the values. Note that an object property is just a mechanism for getting and setting a value β it implies no storage. As a convenience, however,Glib::Objectprovides fallbacks forGET_PROPERTYandSET_PROPERTYwhich use the property nicknames as hash keys in the object variable for storage.
Additionally, you may specify ParamSpecs as a describing hash instead of as an object; this form allows you to supply explicit getter and setter methods which override GET_PROPERY and SET_PROPERTY. The getter and setter are both optional in the hash form. For example:
Glib::Type->register_object ('Glib::Object', 'Foo',
properties => [
# specified normally
Glib::ParamSpec->string (...),
# specified explicitly
{
pspec => Glib::ParamSpec->int (...),
set => sub {
my ($object, $newval) = @_;
...
},
get => sub {
my ($object) = @_;
...
return $val;
},
},
]
);
okay so bestie, the tea on this is β β you can mix the two declaration styles as much as you want, no cap, they're literally besties too π. And if you already have your own little get_foo / set_foo methods holding the actual operative code for a property, then the get/set form is such a handy way to go straight to that β like a shortcut to your own function, iykyk π
π
interfaces => ARRAYREF
This one's an array of interface package names that the new object implements π¦. If you're sitting there like "wait, interfaces?" β interfaces are the GObject way of doing multiple inheritance, periodt. So in Perl land, the package names get prepended to @ISA, and certain inheritable-and-overrideable ALLCAPS methods get automatically called whenever they're needed β¨.
Which methods exactly? That depends on the interface, bestie. Like, Gtk2::CellEditable for example uses START_EDITING, EDITING_DONE, and REMOVE_WIDGET π β those three, that's the whole vibe.
π SEE ALSO
Glibβ your other bestie, go say hi π«Ά
π COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team.
This software is licensed under the LGPL. See Glib for a full notice πβ¨
and that's the page, bestie!! π«Ά mwah π this was generated by perl v5.42.0 and stamped 2023-09-05, so likeβ¦ if it ever feels stale, that's why π go forth and register objects responsibly, ily π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms