From a793618e14fb5710e82b7327e7e0b5eb9527191b Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 20 Sep 2024 20:13:39 +0900 Subject: [PATCH] a Sys module for quick accessing info about current system. This would probably be just a wrapper of Config though. --- lib/App/Perlbrew/Sys.pm | 22 ++++++++++++++++++++++ lib/App/perlbrew.pm | 3 +++ t/sys.t | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 lib/App/Perlbrew/Sys.pm create mode 100644 t/sys.t diff --git a/lib/App/Perlbrew/Sys.pm b/lib/App/Perlbrew/Sys.pm new file mode 100644 index 00000000..3bdb33aa --- /dev/null +++ b/lib/App/Perlbrew/Sys.pm @@ -0,0 +1,22 @@ +package App::Perlbrew::Sys; +use strict; +use warnings; +use Config; + +sub osname { + $Config{osname} +} + +sub archname { + $Config{archname} +} + +sub os { + $Config{osname} +} + +sub arch { + (split(/-/, $Config{archname}, 2))[0] +} + +1; diff --git a/lib/App/perlbrew.pm b/lib/App/perlbrew.pm index f9ffa4bd..f546af0b 100644 --- a/lib/App/perlbrew.pm +++ b/lib/App/perlbrew.pm @@ -28,6 +28,7 @@ use App::Perlbrew::Util qw( files_are_the_same uniq find_similar_tokens looks_li use App::Perlbrew::Path (); use App::Perlbrew::Path::Root (); use App::Perlbrew::HTTP qw( http_download http_get ); +use App::Perlbrew::Sys; ### global variables @@ -225,6 +226,8 @@ sub parse_cmdline { ); } +sub sys { App::Perlbrew::Sys:: } + sub root { my ( $self, $new_root ) = @_; diff --git a/t/sys.t b/t/sys.t new file mode 100644 index 00000000..a1ad597d --- /dev/null +++ b/t/sys.t @@ -0,0 +1,14 @@ +use Test2::V0; + +use App::perlbrew; + +subtest 'sys', sub { + my $o = App::perlbrew->new(); + is $o->can("sys"), T(); + is $o->sys->os(), D(); + is $o->sys->arch(), D(); + is $o->sys->osname(), D(); + is $o->sys->archname(), D(); +}; + +done_testing;