| Glib::version(3pm) | User Contributed Perl Documentation | Glib::version(3pm) |
Glib::version - Library Versioning Utilities
# require at least version 1.021 of the Glib module
use Glib '1.021';
# g_set_application_name() was introduced in GLib 2.2.0, and
# first supported by version 1.040 of the Glib Perl module.
if ($Glib::VERSION >= 1.040 and Glib->CHECK_VERSION (2,2,0)) {
Glib::set_application_name ('My Cool Program');
}
Both the Glib module and the GLib C library are works-in-progress, and their interfaces grow over time. As more features are added to each, and your code uses those new features, you will introduce version-specific dependencies, and naturally, you'll want to be able to code around them. Enter the versioning API.
For simple Perl modules, a single version number is sufficient; however, Glib is a binding to another software library, and this introduces some complexity. We have three versions that fully specify the API available to you.
$Glib::VERSION
use Glib 1.040; # require at least version 1.040
Glib::MAJOR_VERSION
Glib::MINOR_VERSION
Glib::MICRO_VERSION
Glib->CHECK_VERSION($maj,$min,$mic)
Glib::major_version
Glib::minor_version
Glib::micro_version
Where do you use which version? It depends entirely on what you're doing. Let's explain by example:
if ($Glib::VERSION >= 1.040 && Glib->CHECK_VERSION (2,2,0)) {
# it's available, and we can call it!
Glib::set_application_name ('My Cool Application');
}
Now what happens if you installed the Perl module when your system had glib 2.0.6, and you upgraded glib to 2.4.1? Wouldn't g_set_application_name() be available? Well, it's there, under the hood, but the bindings were compiled when it wasn't there, so you won't be able to call it! That's why we check the "bound" or compile-time version. By the way, to enable support for the new function, you'd need to reinstall (or upgrade) the Perl module.
if (Glib::major_version == 2 &&
Glib::minor_version == 2 &&
Glib::micro_version == 1) {
# work around bug that exists only in glib 2.2.1.
}
In practice, such situations are very rare.
Provides a mechanism for checking the version information that Glib was compiled against. Essentially equvilent to the macro GLIB_CHECK_VERSION.
Shorthand to fetch as a list the glib version for which Glib was compiled. See "Glib::MAJOR_VERSION", etc.
Provides access to the version information that Glib was compiled against. Essentially equivalent to the #define's GLIB_MAJOR_VERSION.
Provides access to the version information that Glib was compiled against. Essentially equivalent to the #define's GLIB_MICRO_VERSION.
Provides access to the version information that Glib was compiled against. Essentially equivalent to the #define's GLIB_MINOR_VERSION.
Provides access to the version information that Glib is linked against. Essentially equivalent to the global variable glib_major_version.
Provides access to the version information that Glib is linked against. Essentially equivalent to the global variable glib_micro_version.
Provides access to the version information that Glib is linked against. Essentially equivalent to the global variable glib_minor_version.
Glib
Copyright (C) 2003-2011 by the gtk2-perl team.
This software is licensed under the LGPL. See Glib for a full notice.
| 2024-10-14 | perl v5.40.0 |