aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-07-02 03:50:25 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-07-02 03:50:25 +0200
commit94534a9c8c84769148e4f85aec0540608f44898b (patch)
treee0c8ec82911197eb5f99e89b4d2fc38d47d90a20
parent4c7c8bc3889b84454d40248bee98a79544ca4369 (diff)
Implement raiph's our-scalar suggestion
This moves the actual Log role to Log::Abstract, but the user-facing interface remains the same due to some EXPORT magic. This little bit of magic makes manual inclusion of Log::Level redundant as well. The suggestion itself concerns a new addition to the module, $Log::instance. This is a "shared" variable in that one part of your program can set it, and others parts can use it wherever. This is potentially favourable over using $*LOG, especially in multi-threaded programs.
-rw-r--r--META6.json3
-rw-r--r--lib/Log.rakumod34
-rw-r--r--lib/Log/Abstract.rakumod56
3 files changed, 68 insertions, 25 deletions
diff --git a/META6.json b/META6.json
index 4a84d53..836f696 100644
--- a/META6.json
+++ b/META6.json
@@ -10,8 +10,9 @@
"perl": "6.d",
"provides": {
"Log": "lib/Log.rakumod",
+ "Log::Abstract": "lib/Log/Abstract.rakumod",
"Log::Level": "lib/Log/Level.rakumod"
},
"source-url": "https://home.tyil.nl/git/raku/Log/",
"version": "0.1.1"
-} \ No newline at end of file
+}
diff --git a/lib/Log.rakumod b/lib/Log.rakumod
index 542a732..c818217 100644
--- a/lib/Log.rakumod
+++ b/lib/Log.rakumod
@@ -2,32 +2,18 @@
use v6.d;
+use Log::Abstract;
use Log::Level;
-unit role Log;
-
-# Methods for handling plain string messages.
-multi method emergency (Str:D $) { * }
-multi method alert (Str:D $) { * }
-multi method critical (Str:D $) { * }
-multi method error (Str:D $) { * }
-multi method warning (Str:D $) { * }
-multi method notice (Str:D $) { * }
-multi method info (Str:D $) { * }
-multi method debug (Str:D $) { * }
-
-# Methods for handling formatted messages.
-multi method emergency (Str:D $, *@) { * }
-multi method alert (Str:D $, *@) { * }
-multi method critical (Str:D $, *@) { * }
-multi method error (Str:D $, *@) { * }
-multi method warning (Str:D $, *@) { * }
-multi method notice (Str:D $, *@) { * }
-multi method info (Str:D $, *@) { * }
-multi method debug (Str:D $, *@) { * }
-
-# Method for configuration
-multi method add-output (IO::Handle:D $, Int() $ where Log::Level::Emergency ≤ * ≤ Log::Level::Debug, Callable $?) { * }
+sub EXPORT
+{
+ %(
+ 'Log' => Log::Abstract,
+ 'Log::Level' => Log::Level,
+ )
+}
+
+our $instance;
=begin pod
diff --git a/lib/Log/Abstract.rakumod b/lib/Log/Abstract.rakumod
new file mode 100644
index 0000000..645c13a
--- /dev/null
+++ b/lib/Log/Abstract.rakumod
@@ -0,0 +1,56 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use Log::Level;
+
+unit role Log::Abstract;
+
+# Methods for handling plain string messages.
+multi method emergency (Str:D $) { * }
+multi method alert (Str:D $) { * }
+multi method critical (Str:D $) { * }
+multi method error (Str:D $) { * }
+multi method warning (Str:D $) { * }
+multi method notice (Str:D $) { * }
+multi method info (Str:D $) { * }
+multi method debug (Str:D $) { * }
+
+# Methods for handling formatted messages.
+multi method emergency (Str:D $, *@) { * }
+multi method alert (Str:D $, *@) { * }
+multi method critical (Str:D $, *@) { * }
+multi method error (Str:D $, *@) { * }
+multi method warning (Str:D $, *@) { * }
+multi method notice (Str:D $, *@) { * }
+multi method info (Str:D $, *@) { * }
+multi method debug (Str:D $, *@) { * }
+
+# Method for configuration
+multi method add-output (IO::Handle:D $, Int() $ where Log::Level::Emergency ≤ * ≤ Log::Level::Debug, Callable $?) { * }
+
+=begin pod
+
+=NAME Log::Abstract
+=VERSION 0.1.1
+=AUTHOR Patrick Spek <p.spek@tyil.nl>
+
+=begin LICENSE
+Copyright © 2020
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation, version 3.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program. If not, see http://www.gnu.org/licenses/.
+=end LICENSE
+
+=end pod
+
+# vim: ft=raku noet sw=8 ts=8