<commit_before># The Kernel class and its methods, underlying $*KERNEL, are a work in progress.
# It is very hard to capture data about a changing universe in a stable API.
# If you find errors for your hardware or OS distribution, please report them
# with the values that you expected and how to get them in your situation.

class Kernel does Systemic {
    has Str $.release;
    has Str $!hardware;
    has Str $!arch;
    has Int $!bits;
    has Bool $!has_uname;

    method !uname($opt) {
        $!has_uname //= ("/bin/uname", "/usr/bin/uname").first({ .IO.e && .IO.x }).so;
        $!has_uname ?? qqx/uname $opt/.chomp !! 'unknown';
    }

    submethod BUILD(:$!auth = "unknown" --> Nil) { }

    method name {
        $!name //= do {
            given $*DISTRO.name {
                when 'mswin32' {
                    'win32'
                }
                when 'browser' {
                    'browser';
                }
                default {
                    lc self!uname('-s');
                }
            }
        }
    }

    method version {
        $!version //= Version.new( do {
            given $*DISTRO.name {
                when 'freebsd' {
                    self!uname('-r'); # -K -U not introduced until 10.0
                }
                when 'macosx' {
                    my $unamev = self!uname('-v');
                    $unamev ~~ m/^Darwin \s+ Kernel \s+ Version \s+ (<[\d\.]>+)/
                      ?? ~$0
                      !! $unamev.chomp;
                }
                default {
                    given $.name {
                        when 'linux' {
                            # somewhat counter-intuitively the '-r' is what
                            # most people think of the kernel version
                            self!uname('-r');
                        }
                        default {
                            self!uname('-v');
                        }
                    }
                }
            }
        } );
    }

    method release {
        $!release //= do {
            given $*DISTRO.name {
                when any <openbsd netbsd dragonfly> { # needs adapting
                    self!uname('-r');
                }
                default {
                    self!uname('-v');
                }
            }
        }
    }

    method hardware {
        $!hardware //= do {
            given $*DISTRO.name {
                default {
                    self!uname('-m');
                }
            }
        }
    }

    method arch {
        $!arch //= do {
            given $*DISTRO.name {
                when 'raspbian' {
                    self!uname('-m');
                }
                default {
                    self!uname('-p');<commit_msg>Refactor $*KERNEL internal use of uname<commit_after># The Kernel class and its methods, underlying $*KERNEL, are a work in progress.
# It is very hard to capture data about a changing universe in a stable API.
# If you find errors for your hardware or OS distribution, please report them
# with the values that you expected and how to get them in your situation.

class Kernel does Systemic {
    has Str $.release;
    has Str $!hardware;
    has Str $!arch;
    has Int $!bits;

#?if moar
    has $!uname;
    method !uname {
        $!uname ?? $!uname !! ($!uname := nqp::uname())
    }
#?endif

    method !uname-s {
#?if moar
        nqp::atpos_s(self!uname, nqp::const::UNAME_SYSNAME)
#?endif
#?if !moar
        try shell('uname -s', :out, :!err).out.slurp(:close).chomp;
#?endif
    }

    method !uname-r {
#?if moar
        nqp::atpos_s(self!uname, nqp::const::UNAME_RELEASE)
#?endif
#?if !moar
        try shell('uname -r', :out, :!err).out.slurp(:close).chomp;
#?endif
    }

    method !uname-v {
#?if moar
        nqp::atpos_s(self!uname, nqp::const::UNAME_VERSION)
#?endif
#?if !moar
        try shell('uname -v', :out, :!err).out.slurp(:close).chomp;
#?endif
    }

    method !uname-m {
#?if moar
        nqp::atpos_s(self!uname, nqp::const::UNAME_MACHINE)
#?endif
#?if !moar
        try shell('uname -m', :out, :!err).out.slurp(:close).chomp;
#?endif
    }

    method !uname-p {
        # TODO: find a way to get this without shelling out
        try shell("uname -p", :out, :!err).out.slurp(:close).chomp;
    }

    submethod BUILD(:$!auth = "unknown" --> Nil) { }

    method name {
        $!name //= do {
            given $*DISTRO.name {
                when 'mswin32' {
                    'win32'
                }
                when 'browser' {
                    'browser';
                }
                default {
                    lc self!uname-s();
                }
            }
        }
    }

    method version {
        # it doesn't make sense to return a Version object here, but its currently enforced by roast
        # TODO: remove Version checks from roast? and check ecosystem for fallout.
        $!version //= Version.new(self!uname-v());
    }

    method release {
        # somewhat counter-intuitively the UNAME_RELEASE is what
        # most people think of the kernel version
        $!release //= self!uname-r();
    }

    method hardware {
        $!hardware //= self!uname-m();
    }

    method arch {
        $!arch //= do {
            given $*DISTRO.name {
                when 'raspbian' {
                    self!uname-m();
                }
                default {
                    self!uname-p();
{'fraction_non_alphanumeric': 0.12623671674606082, 'fraction_numerical': 0.0021986075485525836, 'mean_word_length': 1.2917716204869858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '725512', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1607, 'n_words': 439}