Blame lib/Perl/OSType.pm

Packit 65f819
use strict;
Packit 65f819
use warnings;
Packit 65f819
Packit 65f819
package Perl::OSType;
Packit 65f819
# ABSTRACT: Map Perl operating system names to generic types
Packit 65f819
Packit 65f819
our $VERSION = '1.010';
Packit 65f819
Packit 65f819
require Exporter;
Packit 65f819
our @ISA = qw(Exporter);
Packit 65f819
Packit 65f819
our %EXPORT_TAGS = ( all => [qw( os_type is_os_type )] );
Packit 65f819
Packit 65f819
our @EXPORT_OK = @{ $EXPORT_TAGS{all} };
Packit 65f819
Packit 65f819
# originally taken from Module::Build by Ken Williams et al.
Packit 65f819
my %OSTYPES = qw(
Packit 65f819
  aix         Unix
Packit 65f819
  bsdos       Unix
Packit 65f819
  beos        Unix
Packit 65f819
  bitrig      Unix
Packit 65f819
  dgux        Unix
Packit 65f819
  dragonfly   Unix
Packit 65f819
  dynixptx    Unix
Packit 65f819
  freebsd     Unix
Packit 65f819
  linux       Unix
Packit 65f819
  haiku       Unix
Packit 65f819
  hpux        Unix
Packit 65f819
  iphoneos    Unix
Packit 65f819
  irix        Unix
Packit 65f819
  darwin      Unix
Packit 65f819
  machten     Unix
Packit 65f819
  midnightbsd Unix
Packit 65f819
  minix       Unix
Packit 65f819
  mirbsd      Unix
Packit 65f819
  next        Unix
Packit 65f819
  openbsd     Unix
Packit 65f819
  netbsd      Unix
Packit 65f819
  dec_osf     Unix
Packit 65f819
  nto         Unix
Packit 65f819
  svr4        Unix
Packit 65f819
  svr5        Unix
Packit 65f819
  sco         Unix
Packit 65f819
  sco_sv      Unix
Packit 65f819
  unicos      Unix
Packit 65f819
  unicosmk    Unix
Packit 65f819
  solaris     Unix
Packit 65f819
  sunos       Unix
Packit 65f819
  cygwin      Unix
Packit 65f819
  msys        Unix
Packit 65f819
  os2         Unix
Packit 65f819
  interix     Unix
Packit 65f819
  gnu         Unix
Packit 65f819
  gnukfreebsd Unix
Packit 65f819
  nto         Unix
Packit 65f819
  qnx         Unix
Packit 65f819
  android     Unix
Packit 65f819
Packit 65f819
  dos         Windows
Packit 65f819
  MSWin32     Windows
Packit 65f819
Packit 65f819
  os390       EBCDIC
Packit 65f819
  os400       EBCDIC
Packit 65f819
  posix-bc    EBCDIC
Packit 65f819
  vmesa       EBCDIC
Packit 65f819
Packit 65f819
  MacOS       MacOS
Packit 65f819
  VMS         VMS
Packit 65f819
  vos         VOS
Packit 65f819
  riscos      RiscOS
Packit 65f819
  amigaos     Amiga
Packit 65f819
  mpeix       MPEiX
Packit 65f819
);
Packit 65f819
Packit 65f819
sub os_type {
Packit 65f819
    my ($os) = @_;
Packit 65f819
    $os = $^O unless defined $os;
Packit 65f819
    return $OSTYPES{$os} || q{};
Packit 65f819
}
Packit 65f819
Packit 65f819
sub is_os_type {
Packit 65f819
    my ( $type, $os ) = @_;
Packit 65f819
    return unless $type;
Packit 65f819
    $os = $^O unless defined $os;
Packit 65f819
    return os_type($os) eq $type;
Packit 65f819
}
Packit 65f819
Packit 65f819
1;
Packit 65f819
Packit 65f819
=pod
Packit 65f819
Packit 65f819
=encoding UTF-8
Packit 65f819
Packit 65f819
=head1 NAME
Packit 65f819
Packit 65f819
Perl::OSType - Map Perl operating system names to generic types
Packit 65f819
Packit 65f819
=head1 VERSION
Packit 65f819
Packit 65f819
version 1.010
Packit 65f819
Packit 65f819
=head1 SYNOPSIS
Packit 65f819
Packit 65f819
  use Perl::OSType ':all';
Packit 65f819
Packit 65f819
  $current_type = os_type();
Packit 65f819
  $other_type = os_type('dragonfly'); # gives 'Unix'
Packit 65f819
Packit 65f819
=head1 DESCRIPTION
Packit 65f819
Packit d4fe86
=for :stopwords Unix Win32 Windows
Packit d4fe86
Packit 65f819
Modules that provide OS-specific behaviors often need to know if
Packit 65f819
the current operating system matches a more generic type of
Packit 65f819
operating systems. For example, 'linux' is a type of 'Unix' operating system
Packit 65f819
and so is 'freebsd'.
Packit 65f819
Packit 65f819
This module provides a mapping between an operating system name as given by
Packit 65f819
C<$^O> and a more generic type.  The initial version is based on the OS type
Packit 65f819
mappings provided in L<Module::Build> and L<ExtUtils::CBuilder>.  (Thus,
Packit 65f819
Microsoft operating systems are given the type 'Windows' rather than 'Win32'.)
Packit 65f819
Packit 65f819
=head1 USAGE
Packit 65f819
Packit 65f819
No functions are exported by default. The export tag ":all" will export
Packit 65f819
all functions listed below.
Packit 65f819
Packit 65f819
=head2 os_type()
Packit 65f819
Packit 65f819
  $os_type = os_type();
Packit 65f819
  $os_type = os_type('MSWin32');
Packit 65f819
Packit 65f819
Returns a single, generic OS type for a given operating system name.  With no
Packit 65f819
arguments, returns the OS type for the current value of C<$^O>.  If the
Packit 65f819
operating system is not recognized, the function will return the empty string.
Packit 65f819
Packit 65f819
=head2 is_os_type()
Packit 65f819
Packit 65f819
  $is_windows = is_os_type('Windows');
Packit 65f819
  $is_unix    = is_os_type('Unix', 'dragonfly');
Packit 65f819
Packit 65f819
Given an OS type and OS name, returns true or false if the OS name is of the
Packit 65f819
given type.  As with C<os_type>, it will use the current operating system as a
Packit 65f819
default if no OS name is provided.
Packit 65f819
Packit 65f819
=head1 SEE ALSO
Packit 65f819
Packit 65f819
=over 4
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
L<Devel::CheckOS>
Packit 65f819
Packit 65f819
=back
Packit 65f819
Packit 65f819
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
Packit 65f819
Packit 65f819
=head1 SUPPORT
Packit 65f819
Packit 65f819
=head2 Bugs / Feature Requests
Packit 65f819
Packit 65f819
Please report any bugs or feature requests through the issue tracker
Packit 65f819
at L<https://github.com/Perl-Toolchain-Gang/Perl-OSType/issues>.
Packit 65f819
You will be notified automatically of any progress on your issue.
Packit 65f819
Packit 65f819
=head2 Source Code
Packit 65f819
Packit 65f819
This is open source software.  The code repository is available for
Packit 65f819
public review and contribution under the terms of the license.
Packit 65f819
Packit 65f819
L<https://github.com/Perl-Toolchain-Gang/Perl-OSType>
Packit 65f819
Packit 65f819
  git clone https://github.com/Perl-Toolchain-Gang/Perl-OSType.git
Packit 65f819
Packit 65f819
=head1 AUTHOR
Packit 65f819
Packit 65f819
David Golden <dagolden@cpan.org>
Packit 65f819
Packit 65f819
=head1 CONTRIBUTORS
Packit 65f819
Packit 65f819
=for stopwords Chris 'BinGOs' Williams David Golden Graham Ollis Jonas B. Nielsen Owain G. Ainsworth Paul Green Piotr Roszatycki
Packit 65f819
Packit 65f819
=over 4
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
David Golden <xdg@xdg.me>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Graham Ollis <plicease@cpan.org>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Jonas B. Nielsen <jonasbn@hoarfrost.local>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Owain G. Ainsworth <oga@nicotinebsd.org>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Paul Green <Paul.Green@stratus.com>
Packit 65f819
Packit 65f819
=item *
Packit 65f819
Packit 65f819
Piotr Roszatycki <piotr.roszatycki@gmail.com>
Packit 65f819
Packit 65f819
=back
Packit 65f819
Packit 65f819
=head1 COPYRIGHT AND LICENSE
Packit 65f819
Packit 65f819
This software is copyright (c) 2016 by David Golden.
Packit 65f819
Packit 65f819
This is free software; you can redistribute it and/or modify it under
Packit 65f819
the same terms as the Perl 5 programming language system itself.
Packit 65f819
Packit 65f819
=cut
Packit 65f819
Packit 65f819
__END__
Packit 65f819
Packit 65f819
Packit 65f819
# vim: ts=4 sts=4 sw=4 et: