Sys-OsRelease
view release on metacpan or search on metacpan
lib/Sys/OsRelease.pm view on Meta::CPAN
if (exists $self->{_config}{accessor}{$name}) {
my $method_name = $class."::".$name;
## no critic (TestingAndDebugging::ProhibitNoStrict)
no strict 'refs';
undef *{$method_name};
delete $self->{_config}{accessor}{$name};
}
return;
}
1;
=pod
=encoding UTF-8
=head1 NAME
Sys::OsRelease - read operating system details from standard /etc/os-release file
=head1 VERSION
version 0.3.1
=head1 SYNOPSIS
non-object-oriented:
Sys::OsRelease->init();
my $id = Sys::OsRelease->id();
my $id_like = Sys::OsRelease->id_like();
object-oriented:
my $osrelease = Sys::OsRelease->instance();
my $id = $osrelease->id();
my $id_like = $osrelease->id_like();
=head1 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.
=head2 The os-release Standard
FreeDesktop.Org's os-release standard is at L<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 HOME_URL DOCUMENTATION_URL SUPPORT_URL BUG_REPORT_URL PRIVACY_POLICY_URL LOGO ANSI_COLOR
DEFAULT_HOSTNAME SYSEXT_LEVEL
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.
=head1 METHODS
=head2 Class methods
I<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 C<Sys::OsRelease->instance()> .
=over 1
=item init([key => value, ...])
initializes the singleton instance without returning a value.
Parameters are passed to the instance() method.
This method is for cases where method calls will be via the class name, and the program
doesn't need a reference to the instance.
Under normal circumstances no parameters are needed. See instance() for possible parameters.
=item new([key => value, ...])
initializes the singleton instance and returns a reference to it.
Parameters are passed to the instance() method.
This is equivalent to using the instance() method, made available if new() sounds more comfortable.
Under normal circumstances no parameters are needed. See instance() for possible parameters.
=item instance([key => value, ...])
initializes the singleton instance and returns a reference to it.
Under normal circumstances no parameters are needed. Possible optional parameters are as follows:
=over 1
=item common_id
supplies an arrayref to use as a list of additional common strings which should be recognized by the platform()
method, if they occur in the ID_LIKE attribute in the os-release file. By default, "debian" and "fedora" are
regonized by platform() as common names and it will return them instead of the system's ID attribute.
=item search_path
supplies an arrayref of strings with directories to use as the search path for the os-release file.
=item file_name
supplies a string with the basename of the file to look for the os-release file.
Obviously the default file name is "os-release".
Under normal circumstances there is no need to set this.
lib/Sys/OsRelease.pm view on Meta::CPAN
from the standard) this is usually from the ID field.
On systems that use the ID_LIKE field, systems that claim to be like "debian" or "fedora" (always in lower case)
will return those names for the platform.
The list of recognized common platforms can be modified by passing a "common_id" parameter to instance()/new()
with an arrayref containing additional names to recognize as common. For example, "centos" is another possibility.
It was not included in the default because CentOS is discontinued. Both Rocky Linux and Alma Linux have
ID_LIKE fields of "rhel centos fedora", which will match "fedora" with the default setting, but could be configured
via "common_id" to recognize "centos" since it's listed first in ID_LIKE.
On systems where an os-release file doesn't exist or isn't found, the platform string will fall back to Perl's
$Config{osname} setting for the system.
=item osrelease_path()
returns the path where os-release was found.
The default search path is /etc, /usr/lib and /run/host as defined by the standard.
The search path can be replaced by providing a "search_path" parameter to instance()/new() with an arrayref
containing the directories to search. This feature is currently only used for testing purposes.
=item found_attrs()
returns a list of attribute names found in the os-release file, empty if os-release doesn't exist on the platform.
=item has_attr(name)
returns a boolean which is true if the attribute named by the string parameter exists in the os-release data for the
current system.
The attribute name is case insensitive.
=item get(name)
is a read-only accessor which returns the value of the os-release attribute named by the string parameter,
or undef if it doesn't exist.
=item has_config(name)
returns a boolean which is true if Sys::OsRelease contains a configuration setting named by the string parameter.
=item config(name, [value])
is a read/write accessor for the configuration setting named by the string parameter "name".
If no value parameter is provided, it returns the value of the parameter, or undef if it doesn't exist.
If a value parameter is provided, it assigns that to the configuration setting and returns the same value.
=back
=head2 Auto-generated Accessor Methods
For convenience, I<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 I<name()>, I<id()>,
I<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 I<Sys::OsRelease> namespace. Use the I<found_attrs()>,
I<has_attr()> and I<get()> methods to detect and access non-standard attributes.
The current full list is at the os-release standard
L<https://www.freedesktop.org/software/systemd/man/latest/os-release.html>
which includes descriptions of each attribute.
=over 1
=item name()
=item id()
=item id_like()
=item pretty_name()
=item cpe_name()
=item variant()
=item variant_id()
=item version()
=item version_id()
=item version_codename()
=item build_id()
=item image_id()
=item image_version()
=item release_type()
=item home_url()
=item documentation_url()
=item support_url()
=item bug_report_url()
=item privacy_policy_url()
=item support_end()
=item logo()
=item ansi_color()
=item ansi_color_reverse()
=item vendor_name()
=item vendor_url()
=item experiment()
=item experiment_url()
=item default_hostname()
=item architecture()
=item sysext_level()
=item confext_level()
=item sysext_scope()
=item confext_scope()
=item portable_prefixes()
=item portable_scope()
=back
=head1 SEE ALSO
FreeDesktop.Org's os-release standard: L<https://www.freedesktop.org/software/systemd/man/os-release.html>
GitHub repository for Sys::OsRelease: L<https://github.com/ikluft/Sys-OsRelease>
Related modules:
=over 1
=item L<Sys::OsPackage>
installs Perl modules, for example as dependencies of a script, via OS packages if available or otherwise via CPAN -
uses Sys::OsRelease to determine OS type
=item L<System::Info>
system information collected from multiple sources including system architecture, hardware, OS release data
=back
=head1 BUGS AND LIMITATIONS
Please report bugs via GitHub at L<https://github.com/ikluft/Sys-OsRelease/issues>
Patches and enhancements may be submitted via a pull request at L<https://github.com/ikluft/Sys-OsRelease/pulls>
=head1 LICENSE INFORMATION
Copyright (c) 2022 by Ian Kluft
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 L<https://www.perlfoundation.org/arti...
=head1 AUTHOR
Ian Kluft <https://github.com/ikluft>
=head1 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)
=cut
__END__
# POD documentation
( run in 0.786 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )