Skip Menu |

This queue is for tickets about the Linux-Distribution CPAN distribution.

Report information
The Basics
Id: 16232
Status: resolved
Priority: 0/
Queue: Linux-Distribution

People
Owner: Nobody in particular
Requestors: cosimo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.11
Fixed in: (no value)



Subject: Linux::Distribution patch to implement distribution_version()
Hi! I'm sending you a new version of Distribution.pm (0.12?) that implements a TODO item. A basic `distribution_version()' function. Hope you include it in the next version of Linux::Distribution. Thank you. -- Cosimo
package Linux::Distribution; use 5.006000; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( distribution_name distribution_version ); our $VERSION = '0.12'; our %release_files = ( 'gentoo-release' => 'gentoo', 'fedora-release' => 'fedora', 'turbolinux-release' => 'turbolinux', 'mandrake-release' => 'mandrake', 'mandrakelinux-release' => 'mandrakelinux', 'debian_version' => 'debian', 'debian_release' => 'debian', 'SuSE-release' => 'suse', 'knoppix-version' => 'knoppix', 'yellowdog-release' => 'yellowdog', 'slackware-version' => 'slackware', 'slackware-release' => 'slackware', 'redhat-release' => 'redhat', 'redhat_version' => 'redhat', 'conectiva-release' => 'conectiva', 'immunix-release' => 'immunix', 'tinysofa-release' => 'tinysofa', 'trustix-release' => 'trustix', 'adamantix_version' => 'adamantix', 'yoper-release' => 'yoper', 'arch-release' => 'arch', 'libranet_version' => 'libranet', 'va-release' => 'va-linux' ); if ($^O ne 'linux') { require Carp; Carp::croak 'you are trying to use a linux specific module on a different OS'; } sub distribution_name { foreach (keys %release_files) { return $release_files{$_} if ! -l "/etc/$_" && -f _; } undef } sub distribution_version { my $file = ''; my $version = ''; foreach (keys %release_files) { $file = "/etc/$_"; last if ! -l $file && -f _; } if( $file && open(RELEASE, '<' . $file) ) { chomp($version = <RELEASE>); if( $version =~ /\b(\d+\.\d+)\b/ # 7.3 || $version =~ /\b(\d+)\b/ ) { # 4 $version = $1; } close RELEASE; } $version; } 1; __END__ =head1 NAME Linux::Distribution - Perl extension to guess on what linux distribution we are running on. =head1 SYNOPSIS use Linux::Distribution qw(distribution_name distribution_version); if(my $distro = distribution_name) { my $version = distribution_version || 'unknown'; print "you are running $distro v$version\n"; } else { print "distribution unknown\n"; } =head1 DESCRIPTION This is a simple module that try to guess on what linux distribution we are running looking for release's files in /etc. It currently recognize slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet and gentoo. =head2 EXPORT None by default. =head1 AUTHOR Alberto Re, E<lt>kerberus@accidia.netE<gt> =head1 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available. =cut
From: cosimo [...] cpan.org
[COSIMO - Thu Dec 1 06:12:33 2005]: Show quoted text
> Hi! > I'm sending you a new version of Distribution.pm (0.12?) > that implements a TODO item. A basic `distribution_version()' > function. > Hope you include it in the next version of Linux::Distribution. > Thank you.
There is also the updated test file! -- Cosimo
# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Linux-Distribution.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 3; BEGIN { use_ok('Linux::Distribution') }; if(isnt(Linux::Distribution::distribution_name(), undef, "Checking your distro...")) { diag("It seems that we are running on " . Linux::Distribution::distribution_name) } if(isnt(Linux::Distribution::distribution_version(), undef, "Checking your distro version...")) { diag("It seems that distribution version is " . Linux::Distribution::distribution_version) } ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script.
Hello, Linux::Distribution 0.13 now implements version() and it's LSB compatible. Thanks for your interest