package OS; =head1 NAME OS.pm - Module OS detection modules and platform abstraction. =head1 VERSION 2.6.1 =head1 DESCRIPTION Provides modules to query, show, and handle run on different operating systems, standardizing that to some degree. =head1 PUBLIC DATA =head2 @OS::OS: @OS::OS contains information about the current operating system, in the form of an array returned by POSIX::uname(). The values are: =over 4 =item * $OS::OS[0] - $sysname, e.g. "Windows NT". =item * $OS::OS[1] - $nodename (aka hostname or %COMPUTERNAME%), e.g. "BUILD_SVR_042". =item * $OS::OS[2] - $release, e.g. "5.1". =item * $OS::OS[3] - $version, e.g. "Build 2600 (Service Pack 2)". =item * $OS::OS[4] - $machine, e.g. "x86". =back =head2 $OS::PS This is the directory separator character, a '/' in Unix-like systems, or a '\' on Windows. =head1 PUBLIC FUNCTIONS =cut require Exporter; use strict; use POSIX qw(uname); use Msg; # The next line avoids problems with 'use strict'. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use vars qw(@OS $PS); # Initialization processing occurs in the BEGIN block. BEGIN { # Keep $VERSION value the same as at the top of this file. $VERSION = "2.6.1"; # Exported variable initialization. @OS = POSIX::uname(); $PS = ($OS[0] =~ /Windows/) ? "\\" : "/"; } # Package interface standards. By default, any export can be blocked. @ISA = qw(Exporter); @EXPORT = qw($PS @OS); @EXPORT_OK = qw(IsMac IsUnix IsWindows Show); # Prototypes for public functions. sub IsMac(); sub IsUnix(); sub IsWindows(); sub Show(); #============================================================================== # Internal Functions #============================================================================== #============================================================================== # Public Functions #============================================================================== #------------------------------------------------------------------------------ =head2 IsMac() IsMac () returns 1 if the operating system based on the Apple Darwin kernel. =head3 Description-IsMac Determines if the OS is Mac. =head3 Parameters-IsMac None =head3 Returns-IsMac Returns 1 if running on a Mac. =cut #------------------------------------------------------------------------------ sub IsMac () { return 1 if ($OS::OS[0] =~ /(Darwin)/i); return 0; } #------------------------------------------------------------------------------ =head2 IsUnix() IsUnix () returns 1 if operating system is Unix or Linux, 0 otherwise. =head3 Description-IsUnix Determines if the OS is Unix-like (including Linux). =head3 Parameters-IsUnix None =head3 Returns-IsUnix Returns 1 if running on a Unix-like operating system, including Linux. =cut #------------------------------------------------------------------------------ sub IsUnix () { return 1 if ($OS::OS[0] =~ /(Unix|Linux)/i); return 0; } #------------------------------------------------------------------------------ =head2 IsWindows() IsUnix () returns 1 if operating system is Windows, 0 otherwise. =head3 Description-IsWindows Determines if the OS is Windows. =head3 Parameters-IsWindows None =head3 Returns-IsWindows Returns 1 if running on a Win-like operating system, including Linux. =cut #------------------------------------------------------------------------------ sub IsWindows () { return 1 if ($OS::OS[0] =~ /Windows/i); return 0; } #------------------------------------------------------------------------ =head2 Show() Show () Displays operating system info in @OS::OS, as given by POSIX::uname(). Also displays the path separator charater in $OS::PS, e.g. '\' or '/'. =head3 Parameters-Show None =cut #------------------------------------------------------------------------------ sub Show () { $Msg->info("Operating System Info: \$sysname = $OS[0] \$nodename = $OS[1] \$release = $OS[2] \$version = $OS[3] \$machine = $OS[4] Path Separator = [$PS]\n\n"); } #------------------------------------------------------------------------------ # Return package load success. 1;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19278 | trina | "Forking branch Main of perforce-software-sdp to trina-sdp." | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/lib/OS.pm | |||||
#2 | 15856 | C. Thomas Tyler |
Replaced the big license comment block with a shortened form referencing the LICENSE file included with the SDP package, and also by the URL for the license file in The Workshop. |
||
#1 | 10148 | C. Thomas Tyler | Promoted the Perforce Server Deployment Package to The Workshop. |