NAME

Sys::OsRelease - read operating system details from standard /etc/os-release file

VERSION

version 0.4.6

SYNOPSIS

non-object-oriented (Perl 5.22 and later):

use Sys::OsRelease;

Sys::OsRelease->init();
my $id = Sys::OsRelease->id();
my $id_like = Sys::OsRelease->id_like();

object-oriented (Perl 5.22 and later):

use Sys::OsRelease;

my $osrelease = Sys::OsRelease->instance();
my $id = $osrelease->id();
my $id_like = $osrelease->id_like();

non-object-oriented (Perl up to 5.20):

use Sys::OsRelease::Lite;

Sys::OsRelease::Lite->init();
my $id = Sys::OsRelease::Lite->id();
my $id_like = Sys::OsRelease::Lite->id_like();

object-oriented (Perl up to 5.20):

use Sys::OsRelease::Lite;

my $osrelease = Sys::OsRelease::Lite->instance();
my $id = $osrelease->id();
my $id_like = $osrelease->id_like();

DESCRIPTION

Sys::OsRelease is a helper library to read the /etc/os-release file, as defined by FreeDesktop.Org. The os-release file is used to define an operating system environment. It has been in widespread use among Linux distributions since 2017 and BSD variants since 2020. It was started on Linux systems which use the systemd software, but then spread to other Linux, BSD and Unix-based systems. Its purpose is to identify the system to any software which needs to know. It differentiates between Unix-based operating systems and even between Linux distributions.

Sys::OsRelease is implemented with a singleton model, meaning there is only one instance of the class. Instead of instantiating an object with new(), the instance() class method returns the one and only instance. The first time it's called, it instantiates it. On following calls, it returns a reference to the singleton instance.

This module maintains minimal prerequisites, and only those which are usually included with Perl. (Suggestions of new features and code will have to follow this rule.) That is intended to be acceptable for establishing system or container environments which contain Perl programs. It can also be used for installing or configuring software that needs to know about the system environment.

The os-release Standard

FreeDesktop.Org's os-release standard is at https://www.freedesktop.org/software/systemd/man/os-release.html.

Current attributes recognized by Sys::OsRelease are: NAME ID ID_LIKE PRETTY_NAME CPE_NAME VARIANT VARIANT_ID VERSION VERSION_ID VERSION_CODENAME BUILD_ID IMAGE_ID IMAGE_VERSION RELEASE_TYPE HOME_URL DOCUMENTATION_URL SUPPORT_URL BUG_REPORT_URL PRIVACY_POLICY_URL SUPPORT_END LOGO ANSI_COLOR ANSI_COLOR_REVERSE VENDOR_NAME VENDOR_URL EXPERIMENT EXPERIMENT_URL DEFAULT_HOSTNAME ARCHITECTURE SYSEXT_LEVEL CONFEXT_LEVEL SYSEXT_SCOPE CONFEXT_SCOPE PORTABLE_PREFIXES PORTABLE_SCOPE

If other attributes are found in the os-release file, they will be accepted. Folded to lower case, the attribute names are used as keys in an internal hash structure.

Sys::OsRelease or Sys::OsRelease::Lite?

Due to restrictions of the Dist::Zilla build environment and its dependencies, Sys::OsRelease 0.4.0 had to follow an increase in the minimum Perl version from 5.10 to 5.22. For systems with Perl older than 5.22, see below about Sys::OsRelease::Lite which repackages Sys::OsRelease without the Dist::Zilla version limitation in order to retain support for legacy Perl installations.

Sys::OsRelease::Lite is the same module in all but name. A release script filters the source code of Sys::OsRelease to change its name. Then Sys::OsRelease::Lite is built with ExtUtils::MakeMaker to maintain compatibility back to Perl 5.10. The two are released in parallel with the same version number.

METHODS

Class methods

Sys::OsRelease uses a singleton model. So there is only one instance. Class methods manage the singleton instance, or import those methods to another cooperating class' namespace.

Class methods must be called using the class name, like Sys::OsRelease-instance()> .

Instance methods

Object methods, including auto-generated accessors described above, access the data from the singleton instance, either read from an os-release file or empty to indicate no os-release file was found on the system.

Instance methods may be called either via the class name or a reference to the singleton instance. Each of these functions can determine whether they were called as a class or object method, and obtain the reference to the singleton instance if needed.

Auto-generated Accessor Methods

For convenience, Sys::OsRelease generates read-only accessor methods for each of the standard attribute names, converted to lower case. For example, from the list above they are name(), id(), id_like(), etc. The auto-generated methods do not require any parameters, and ignore any if provided.

Accessor methods are not generated for non-standard atttributes because it would be unreliable to try to call methods named for transient data that may or may not exist on a given platform, and for the possibility they could conflict with existing functions in the Sys::OsRelease namespace. Use the found_attrs(), has_attr() and get() methods to detect and access non-standard attributes.

The current full list is at the os-release standard https://www.freedesktop.org/software/systemd/man/latest/os-release.html which includes descriptions of each attribute.

SEE ALSO

FreeDesktop.Org's os-release standard: https://www.freedesktop.org/software/systemd/man/os-release.html

GitHub repository for Sys::OsRelease: https://github.com/ikluft/Sys-OsRelease

Related modules:

BUGS AND LIMITATIONS

Please report bugs via GitHub at https://github.com/ikluft/Sys-OsRelease/issues

Patches and enhancements may be submitted via a pull request at https://github.com/ikluft/Sys-OsRelease/pulls

LICENSE INFORMATION

This module is distributed in the hope that it will be useful, but it is provided “as is” and without any express or implied warranties. For details, see the full text of the license in the file LICENSE or at https://www.perlfoundation.org/artistic-license-20.html.

AUTHOR

Ian Kluft <https://github.com/ikluft>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2022-2026 by Ian Kluft.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)