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:
METHODS
This package provides the following methods:
call
call(Str $name, Str @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 4
-
# given: synopsis package main; my @call = $os->call($^X, '-V:osname'); # ("osname='linux';", 0)
find
find(Str $name, Str @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() (Bool)
The is_bsd method returns true if the OS is either "freebsd"
or "openbsd"
, and otherwise returns false.
Since 2.80
is_cyg
is_cyg() (Bool)
The is_cyg method returns true if the OS is either "cygwin"
or "msys"
, and otherwise returns false.
Since 2.80
is_dos
is_dos() (Bool)
The is_dos method returns true if the OS is either "mswin32"
or "dos"
or "os2"
, and otherwise returns false.
Since 2.80
is_lin
is_lin() (Bool)
The is_lin method returns true if the OS is "linux"
, and otherwise returns false.
Since 2.80
is_mac
is_mac() (Bool)
The is_mac method returns true if the OS is either "macos"
or "darwin"
, and otherwise returns false.
Since 2.80
is_non
is_non() (Bool)
The is_non method returns true if the OS is not recognized, and if recognized returns false.
Since 2.80
is_sun
is_sun() (Bool)
The is_sun method returns true if the OS is either "solaris"
or "sunos"
, and otherwise returns false.
Since 2.80
is_vms
is_vms() (Bool)
The is_vms method returns true if the OS is "vms"
, and otherwise returns false.
Since 2.80
is_win
is_win() (Bool)
The is_win method returns true if the OS is either "mswin32"
or "dos"
or "os2"
, and otherwise returns false.
Since 2.80
name
name() (Str)
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(Str $data) (Str)
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() (Str)
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
where
where(Str $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", # ]
which
which(Str $file) (Str)
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"
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2000, Al Newkirk.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.