SystemQuery
=title module Zef::Utils::SystemQuery
=subtitle Utility subroutines for resolving declarative logic based dependencies
Synopsis
use Zef::Utils::SystemQuery;
my @depends = (
{
"name" => {
"by-distro.name" => {
"mswin32" => "Windows::Dependency",
"" => "NonWindows::Dependency"
},
},
},
);
my @resolved-depends := system-collapse(@depends);
say @resolved-depends.raku;
# [{:name("Windows::Dependency")},] # on windows systems
# [{:name("NonWindows::Dependency")},] # on non-windows systems
Description
Provides facilities for resolving dependencies that use declarative logic.
Subroutines
sub system-collapse
our sub system-collapse($data)
Traverses an Array
or Hash
$data
, collapsing the blocks of declarative logic and returns the
otherwise same data structure.
Declarative logic current supports three main query forms:
# by-env-exists.$FOO - selects "yes" key %*ENV{$FOO} exists, else the "no" key
"by-env-exists.FOO" : {
"yes" : "Env::Exists",
"no" : "Env::DoesNotExists"
}
# by-env.$FOO - selects the value of %*ENV{$FOO} as the key, else the "" key if there is no matching key
"by-env.FOO" : {
"SomeValue" : "Env::FOO::SomeValue",
"" : "Env::FOO::DefaultValue"
}
# by-[distro|kernel|raku|vm].$FOO - selects the value of e.g. $*DISTRO.name as the key, else the "" key if there is no matching key
# where $FOO is e.g. $*DISTRO.^methods (or $*KERNEL.^methods, $*RAKU.^methods, $*VM.^methods)
"by-distro.name" : {
"macosx" : "OSX::Dependency",
"" : "NonOSX::Dependency"
}
Note that e.g. $*DISTRO.name
(and thus the by-[distro|kernel|raku|vm].$FOO
form) depends on potentially Raku
backend
specific stuff -- for instance libuv based backends would have similar e.g. $*DISTRO
values, but on the JVM $*DISTRO.name
might return "linux" when MoarVM returns "debian". When using this query form you will want to test on multiple systems.