NAME

Venus::Os - OS Class

ABSTRACT

OS Class for Perl 5

SYNOPSIS

package main;

use Venus::Os;

my $os = Venus::Os->new;

# bless({...}, 'Venus::Os')

# my $name = $os->name;

# "linux"

DESCRIPTION

This package provides methods for determining the current operating system, as well as finding and executing files.

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

METHODS

This package provides the following methods:

call

call(string $name, string @args) (any)

The call method attempts to find the path to the program specified via "which" and dispatches to "mkcall" in Venus::Path and returns the result. Any exception throw is supressed and will return undefined if encountered.

Since 2.80

call example 1
# given: synopsis

package main;

my $app = $os->is_win ? 'perl.exe' : 'perl';

my $call = $os->call($app, '-V:osname');

# "osname='linux';"
call example 2
# given: synopsis

package main;

my $app = $os->is_win ? 'perl.exe' : 'perl';

my @call = $os->call($app, '-V:osname');

# ("osname='linux';", 0)
call example 3
# given: synopsis

package main;

my $call = $os->call('nowhere');

# undef
call example 4
# given: synopsis

package main;

my @call = $os->call($^X, '-V:osname');

# ("osname='linux';", 0)
call example 5
# given: synopsis

package main;

my @call = $os->call($^X, 't/data/sun');

# ("", 1)

find

find(string $name, string @paths) (arrayref)

The find method searches the paths provided for a file matching the name provided and returns all the files found as an arrayref. Returns a list in list context.

Since 2.80

find example 1
# given: synopsis

package main;

my $find = $os->find('cmd', 't/path/user/bin');

# ["t/path/user/bin/cmd"]
find example 2
# given: synopsis

package main;

my $find = $os->find('cmd', 't/path/user/bin', 't/path/usr/bin');

# ["t/path/user/bin/cmd", "t/path/usr/bin/cmd"]
find example 3
# given: synopsis

package main;

my $find = $os->find('zzz', 't/path/user/bin', 't/path/usr/bin');

# []

is_bsd

is_bsd() (boolean)

The is_bsd method returns true if the OS is either "freebsd" or "openbsd", and otherwise returns false.

Since 2.80

is_bsd example 1
# given: synopsis

package main;

# on linux

my $is_bsd = $os->is_bsd;

# false
is_bsd example 2
# given: synopsis

package main;

# on freebsd

my $is_bsd = $os->is_bsd;

# true
is_bsd example 3
# given: synopsis

package main;

# on openbsd

my $is_bsd = $os->is_bsd;

# true

is_cyg

is_cyg() (boolean)

The is_cyg method returns true if the OS is either "cygwin" or "msys", and otherwise returns false.

Since 2.80

is_cyg example 1
# given: synopsis

package main;

# on linux

my $is_cyg = $os->is_cyg;

# false
is_cyg example 2
# given: synopsis

package main;

# on cygwin

my $is_cyg = $os->is_cyg;

# true
is_cyg example 3
# given: synopsis

package main;

# on msys

my $is_cyg = $os->is_cyg;

# true

is_dos

is_dos() (boolean)

The is_dos method returns true if the OS is either "mswin32" or "dos" or "os2", and otherwise returns false.

Since 2.80

is_dos example 1
# given: synopsis

package main;

# on linux

my $is_dos = $os->is_dos;

# false
is_dos example 2
# given: synopsis

package main;

# on mswin32

my $is_dos = $os->is_dos;

# true
is_dos example 3
# given: synopsis

package main;

# on dos

my $is_dos = $os->is_dos;

# true
is_dos example 4
# given: synopsis

package main;

# on os2

my $is_dos = $os->is_dos;

# true

is_lin

is_lin() (boolean)

The is_lin method returns true if the OS is "linux", and otherwise returns false.

Since 2.80

is_lin example 1
# given: synopsis

package main;

# on linux

my $is_lin = $os->is_lin;

# true
is_lin example 2
# given: synopsis

package main;

# on macos

my $is_lin = $os->is_lin;

# false
is_lin example 3
# given: synopsis

package main;

# on mswin32

my $is_lin = $os->is_lin;

# false

is_mac

is_mac() (boolean)

The is_mac method returns true if the OS is either "macos" or "darwin", and otherwise returns false.

Since 2.80

is_mac example 1
# given: synopsis

package main;

# on linux

my $is_mac = $os->is_mac;

# false
is_mac example 2
# given: synopsis

package main;

# on macos

my $is_mac = $os->is_mac;

# true
is_mac example 3
# given: synopsis

package main;

# on darwin

my $is_mac = $os->is_mac;

# true

is_non

is_non() (boolean)

The is_non method returns true if the OS is not recognized, and if recognized returns false.

Since 2.80

is_non example 1
# given: synopsis

package main;

# on linux

my $is_non = $os->is_non;

# false
is_non example 2
# given: synopsis

package main;

# on aix

my $is_non = $os->is_non;

# true

is_sun

is_sun() (boolean)

The is_sun method returns true if the OS is either "solaris" or "sunos", and otherwise returns false.

Since 2.80

is_sun example 1
# given: synopsis

package main;

# on linux

my $is_sun = $os->is_sun;

# false
is_sun example 2
# given: synopsis

package main;

# on solaris

my $is_sun = $os->is_sun;

# true
is_sun example 3
# given: synopsis

package main;

# on sunos

my $is_sun = $os->is_sun;

# true

is_vms

is_vms() (boolean)

The is_vms method returns true if the OS is "vms", and otherwise returns false.

Since 2.80

is_vms example 1
# given: synopsis

package main;

# on linux

my $is_vms = $os->is_vms;

# false
is_vms example 2
# given: synopsis

package main;

# on vms

my $is_vms = $os->is_vms;

# true

is_win

is_win() (boolean)

The is_win method returns true if the OS is either "mswin32" or "dos" or "os2", and otherwise returns false.

Since 2.80

is_win example 1
# given: synopsis

package main;

# on linux

my $is_win = $os->is_win;

# false
is_win example 2
# given: synopsis

package main;

# on mswin32

my $is_win = $os->is_win;

# true
is_win example 3
# given: synopsis

package main;

# on dos

my $is_win = $os->is_win;

# true
is_win example 4
# given: synopsis

package main;

# on os2

my $is_win = $os->is_win;

# true

name

name() (string)

The name method returns the OS name.

Since 2.80

name example 1
# given: synopsis

package main;

# on linux

my $name = $os->name;

# "linux"

# same as $^O

paths

paths() (arrayref)

The paths method returns the paths specified by the "PATH" environment variable as an arrayref of unique paths. Returns a list in list context.

Since 2.80

paths example 1
# given: synopsis

package main;

my $paths = $os->paths;

# [
#   "/root/local/bin",
#   "/root/bin",
#   "/usr/local/sbin",
#   "/usr/local/bin",
#   "/usr/sbin:/usr/bin",
# ]

quote

quote(string $data) (string)

The quote method accepts a string and returns the OS-specific quoted version of the string.

Since 2.91

quote example 1
# given: synopsis

package main;

# on linux

my $quote = $os->quote("hello \"world\"");

# "'hello \"world\"'"
quote example 2
# given: synopsis

package main;

# on linux

my $quote = $os->quote('hello \'world\'');

# "'hello '\\''world'\\'''"
quote example 3
# given: synopsis

package main;

# on mswin32

my $quote = $os->quote("hello \"world\"");

# "\"hello \\"world\\"\""
quote example 4
# given: synopsis

package main;

# on mswin32

my $quote = $os->quote('hello "world"');

# '"hello \"world\""'

type

type() (string)

The type method returns a string representing the "test" method, which identifies the OS, that would return true if called, based on the name of the OS.

Since 2.80

type example 1
# given: synopsis

package main;

# on linux

my $type = $os->type;

# "is_lin"
type example 2
# given: synopsis

package main;

# on macos

my $type = $os->type;

# "is_mac"
type example 3
# given: synopsis

package main;

# on mswin32

my $type = $os->type;

# "is_win"
type example 4
# given: synopsis

package main;

# on openbsd

my $type = $os->type;

# "is_bsd"
type example 5
# given: synopsis

package main;

# on cygwin

my $type = $os->type;

# "is_cyg"
type example 6
# given: synopsis

package main;

# on dos

my $type = $os->type;

# "is_win"
type example 7
# given: synopsis

package main;

# on solaris

my $type = $os->type;

# "is_sun"
type example 8
# given: synopsis

package main;

# on vms

my $type = $os->type;

# "is_vms"

where

where(string $file) (arrayref)

The where method searches the paths defined by the PATH environment variable for a file matching the name provided and returns all the files found as an arrayref. Returns a list in list context. This method doesn't check (or care) if the files found are actually executable.

Since 2.80

where example 1
# given: synopsis

package main;

my $where = $os->where('cmd');

# [
#   "t/path/user/local/bin/cmd",
#   "t/path/user/bin/cmd",
#   "t/path/usr/bin/cmd",
#   "t/path/usr/local/bin/cmd",
#   "t/path/usr/local/sbin/cmd",
#   "t/path/usr/sbin/cmd"
# ]
where example 2
# given: synopsis

package main;

my $where = $os->where('app1');

# [
#   "t/path/user/local/bin/app1",
#   "t/path/usr/bin/app1",
#   "t/path/usr/sbin/app1"
# ]
where example 3
# given: synopsis

package main;

my $where = $os->where('app2');

# [
#   "t/path/user/local/bin/app2",
#   "t/path/usr/bin/app2",
# ]
where example 4
# given: synopsis

package main;

my $where = $os->where('app3');

# [
#   "t/path/user/bin/app3",
#   "t/path/usr/sbin/app3"
# ]
where example 5
# given: synopsis

package main;

my $where = $os->where('app4');

# [
#   "t/path/user/local/bin/app4",
#   "t/path/usr/local/bin/app4",
#   "t/path/usr/local/sbin/app4",
# ]
where example 6
# given: synopsis

package main;

my $where = $os->where('app5');

# []

which

which(string $file) (string)

The which method returns the first match from the result of calling the "where" method with the arguments provided.

Since 2.80

which example 1
# given: synopsis

package main;

my $which = $os->which('cmd');

# "t/path/user/local/bin/cmd",
which example 2
# given: synopsis

package main;

my $which = $os->which('app1');

# "t/path/user/local/bin/app1"
which example 3
# given: synopsis

package main;

my $which = $os->which('app2');

# "t/path/user/local/bin/app2"
which example 4
# given: synopsis

package main;

my $which = $os->which('app3');

# "t/path/user/bin/app3"
which example 5
# given: synopsis

package main;

my $which = $os->which('app4');

# "t/path/user/local/bin/app4"
which example 6
# given: synopsis

package main;

my $which = $os->which('app5');

# undef

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2000, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.