Sidef

 view release on metacpan or  search on metacpan

lib/Sidef/Sys/Sys.pm  view on Meta::CPAN

package Sidef::Sys::Sys;

use utf8;
use 5.016;
use parent qw(
  Sidef::Object::Object
);

use Sidef::Types::Bool::Bool;

sub new {
    CORE::bless {}, __PACKAGE__;
}

sub exit {
    my ($self, $code) = @_;
    CORE::exit($code // 0);
}

sub kill {
    my ($self, $signal, @list) = @_;
    Sidef::Types::Number::Number->new(CORE::kill("$signal", map { CORE::int($_) } @list));
}

sub wait {
    my ($self) = @_;
    Sidef::Types::Number::Number->new(CORE::wait);
}

sub fork {
    my ($self) = @_;
    Sidef::Types::Number::Number->new(CORE::fork() // return undef);
}

sub alarm {
    my ($self, $sec) = @_;

    state $x = require Time::HiRes;
    (Time::HiRes::alarm($sec)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

sub ualarm {
    my ($self, $sec) = @_;

    state $x = require Time::HiRes;
    (Time::HiRes::ualarm($sec)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

*micro_alarm = \&ualarm;

sub sleep {
    my ($self, $sec) = @_;

    state $x = require Time::HiRes;
    (Time::HiRes::sleep($sec)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

sub nanosleep {
    my ($self, $sec) = @_;

    state $x = require Time::HiRes;
    (Time::HiRes::nanosleep($sec)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

*nano_sleep = \&nanosleep;

sub usleep {
    my ($self, $sec) = @_;

    state $x = require Time::HiRes;
    (Time::HiRes::usleep($sec)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

*micro_sleep = \&usleep;

sub osname {
    my ($self) = @_;
    Sidef::Types::String::String->new($^O);
}

*os = \&osname;

sub user {
    my ($self) = @_;
    Sidef::Types::String::String->new(CORE::getlogin);
}

*getlogin = \&user;

sub umask {
    my ($self, $mode) = @_;

    if (defined($mode)) {
        return Sidef::Types::Number::Number->new(CORE::umask($mode));
    }

    Sidef::Types::Number::Number->new(CORE::umask);
}

sub ref {
    my ($self, $obj) = @_;
    Sidef::Types::String::String->new(CORE::ref $obj);
}

sub defined {
    my ($self, $obj) = @_;
    (defined $obj) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

sub class_name {
    my ($self, $obj) = @_;
    my $ref = CORE::ref($obj);

    my $rindex = rindex($ref, '::');
    Sidef::Types::String::String->new($rindex == -1 ? $ref : substr($ref, $rindex + 2));
}

sub sidef {
    my ($self) = @_;

    state $x = require File::Spec;
    Sidef::Types::String::String->new(File::Spec->rel2abs($0));
}

sub die {
    my ($self, @args) = @_;
    CORE::die(@args, "\n");
}

*raise = \¨

sub warn {
    my ($self, @args) = @_;
    CORE::warn(@args, "\n");
}

sub print {
    my ($self, @args) = @_;
    (CORE::print(@args)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

sub printf {
    my ($self, @args) = @_;
    (CORE::printf(@args)) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

sub printh {
    my ($self, $fh, @args) = @_;

    if (CORE::ref($fh) eq 'GLOB') {
        return (CORE::print {$fh} @args) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
    }

    $fh->print(@args);
}

sub println {
    my ($self, @args) = @_;
    (CORE::say @args) ? (Sidef::Types::Bool::Bool::TRUE) : (Sidef::Types::Bool::Bool::FALSE);
}

*say = \&println;

sub scanln {
    my ($self, $text) = @_;
    $self->read($text, 'Sidef::Types::String::String');
}

*readln   = \&scanln;
*readline = \&scanln;

sub read {
    my ($self, $type, $opt_arg) = @_;

    my $message = '';

    if (defined($opt_arg)) {
        $message = "$type";
        $type    = $opt_arg;
    }



( run in 0.812 second using v1.01-cache-2.11-cpan-f03e8824b8d )