aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md15
-rw-r--r--META6.json9
-rw-r--r--README.md89
-rw-r--r--README.rakudoc23
-rw-r--r--lib/IO/Path/XDG.rakumod119
5 files changed, 249 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d74a60..15056c9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,5 +5,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).
+## [0.2.0] - 2020-04-25
+
+### Added
+
+- `xdg-config-dirs` has been added, which will return a sequence of IO::Path
+ objects to refer to all configuration dirs an application *should* check for
+ user defined configuration.
+
+- `xdg-data-dirs` has been added, which will return a sequence of IO::Path
+ objects to refer to all user specific data files.
+
+### Changed
+
+- References to Perl 6 have been updated to refer to Raku instead.
+
## [0.1.0] - 2019-09-12
- Initial release
diff --git a/META6.json b/META6.json
index ee9fd3a..8ef9e37 100644
--- a/META6.json
+++ b/META6.json
@@ -4,7 +4,6 @@
"Patrick Spek <p.spek@tyil.work>"
],
"depends": [
-
],
"description": "Convenience functions for working with the XDG Base Directory Specification",
"license": "AGPL-3.0",
@@ -12,14 +11,12 @@
"name": "IO::Path::XDG",
"perl": "6.d",
"provides": {
- "IO::Path::XDG": "lib/IO/Path/XDG.pm6"
+ "IO::Path::XDG": "lib/IO/Path/XDG.rakumod"
},
"resources": [
-
],
- "source-url": "https://gitlab.com/tyil/perl6-io-path-xdg",
+ "source-url": "https://home.tyil.nl/git/raku/IO::Path::XDG/",
"tags": [
-
],
- "version": "0.1.0"
+ "version": "0.2.0"
} \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5ca1652
--- /dev/null
+++ b/README.md
@@ -0,0 +1,89 @@
+### sub xdg-config-dirs
+
+```perl6
+sub xdg-config-dirs(
+ Bool:D :$home = Bool::True
+) returns Iterable
+```
+
+Retrieve the value of XDG_CONFIG_DIRS as a sequence of IO::Path objects. If this variable is not set, it will use the default value of /etc/xdg. These directories should be read in order to retrieve configuration files.
+
+class Bool:D :$home = Bool::True
+--------------------------------
+
+When set to true, this sequence will start with the XDG_CONFIG_HOME value (or its default).
+
+### sub xdg-config-home
+
+```perl6
+sub xdg-config-home() returns IO::Path
+```
+
+Returns an IO::Path for $XDG_CONFIG_HOME, if it exists as environment variable. Otherwise, return the default value, $HOME/.config. This directory should contain user-specific configuration files.
+
+### sub xdg-cache-home
+
+```perl6
+sub xdg-cache-home() returns IO::Path
+```
+
+Returns an IO::Path for $XDG_CACHE_HOME, if it exists as environment variable. Otherwise, return the default value, $HOME/.cache. This directory should contain user-specific, non-essential (cached) data.
+
+### sub xdg-data-dirs
+
+```perl6
+sub xdg-data-dirs(
+ Bool:D :$home = Bool::True
+) returns Iterable
+```
+
+Retrieve the value of XDG_DATA_DIRS as a sequence of IO::Path objects. If this variable is not set, it will use the default values of /usr/local/share and /usr/share. These directories should be read in order to retrieve user specific data files.
+
+class Bool:D :$home = Bool::True
+--------------------------------
+
+When set to true, this sequence will start with the XDG_DATA_HOME value (or its default).
+
+### sub xdg-data-home
+
+```perl6
+sub xdg-data-home() returns IO::Path
+```
+
+Returns an IO::Path for $XDG_DATA_HOME, if it exists as environment variable. Otherwise, return the default value, $HOME/.local/share. This directory should contain user-specific data files.
+
+### sub xdg-runtime-dir
+
+```perl6
+sub xdg-runtime-dir() returns IO::Path
+```
+
+Returns an IO::Path for $XDG_RUNTIME_DIR, if it exists as environment variable. Otherwise, return an IO::Path to a temporary directory. This directory should contain user-specific runtime files and other file objects.
+
+NAME
+====
+
+IO::Path::XDG
+
+AUTHOR
+======
+
+Patrick Spek <p.spek@tyil.work>
+
+VERSION
+=======
+
+0.2.0
+
+Synopsis
+========
+
+Description
+===========
+
+Examples
+========
+
+See also
+========
+
diff --git a/README.rakudoc b/README.rakudoc
new file mode 100644
index 0000000..99f4dbe
--- /dev/null
+++ b/README.rakudoc
@@ -0,0 +1,23 @@
+=begin pod
+
+=NAME IO::Path::XDG
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+=VERSION 0.0.0
+
+=head1 Description
+
+Convenience functions for working with the XDG Base Directory Specification
+
+=head1 Installation
+
+Install this module through L<zef|https://github.com/ugexe/zef>:
+
+=begin code :lang<sh>
+zef install IO::Path::XDG
+=end code
+
+=head1 License
+
+This module is distributed under the terms of the AGPL-3.0.
+
+=end pod
diff --git a/lib/IO/Path/XDG.rakumod b/lib/IO/Path/XDG.rakumod
new file mode 100644
index 0000000..54c1941
--- /dev/null
+++ b/lib/IO/Path/XDG.rakumod
@@ -0,0 +1,119 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+unit module IO::Path::XDG;
+
+#| Retrieve the value of XDG_CONFIG_DIRS as a sequence of IO::Path objects. If
+#| this variable is not set, it will use the default value of /etc/xdg. These
+#| directories should be read in order to retrieve configuration files.
+sub xdg-config-dirs (
+ #| When set to true, this sequence will start with the XDG_CONFIG_HOME
+ #| value (or its default).
+ Bool:D :$home = True,
+
+ --> Iterable
+) is export {
+ (
+ (xdg-config-home if $home),
+ (%*ENV<XDG_CONFIG_DIRS> // '/etc/xdg')
+ .split(':')
+ .map(*.IO)
+ .Slip,
+ )
+}
+
+#| Returns an IO::Path for $XDG_CONFIG_HOME, if it exists as environment
+#| variable. Otherwise, return the default value, $HOME/.config. This directory
+#| should contain user-specific configuration files.
+sub xdg-config-home (
+ --> IO::Path
+) is export {
+ return %*ENV<XDG_CONFIG_HOME>.IO if %*ENV<XDG_CONFIG_HOME>:exists;
+
+ $*HOME.add(".config");
+}
+
+#| Returns an IO::Path for $XDG_CACHE_HOME, if it exists as environment
+#| variable. Otherwise, return the default value, $HOME/.cache. This directory
+#| should contain user-specific, non-essential (cached) data.
+sub xdg-cache-home (
+ --> IO::Path
+) is export {
+ return %*ENV<XDG_CACHE_HOME>.IO if %*ENV<XDG_CACHE_HOME>:exists;
+
+ $*HOME.IO.add(".cache");
+}
+
+#| Retrieve the value of XDG_DATA_DIRS as a sequence of IO::Path objects. If
+#| this variable is not set, it will use the default values of /usr/local/share
+#| and /usr/share. These directories should be read in order to retrieve user
+#| specific data files.
+sub xdg-data-dirs (
+ #| When set to true, this sequence will start with the XDG_DATA_HOME
+ #| value (or its default).
+ Bool:D :$home = True,
+
+ --> Iterable
+) is export {
+ (
+ (xdg-data-home if $home),
+ (%*ENV<XDG_DATA_DIRS> // '/usr/local/share:/usr/share')
+ .split(':')
+ .map(*.IO)
+ .Slip
+ )
+}
+
+#| Returns an IO::Path for $XDG_DATA_HOME, if it exists as environment
+#| variable. Otherwise, return the default value, $HOME/.local/share. This
+#| directory should contain user-specific data files.
+sub xdg-data-home (
+ --> IO::Path
+) is export {
+ return %*ENV<XDG_DATA_HOME>.IO if %*ENV<XDG_DATA_HOME>:exists;
+
+ $*HOME.add(".local/share");
+}
+
+#| Returns an IO::Path for $XDG_RUNTIME_DIR, if it exists as environment
+#| variable. Otherwise, return an IO::Path to a temporary directory. This
+#| directory should contain user-specific runtime files and other file objects.
+sub xdg-runtime-dir (
+ --> IO::Path
+) is export {
+ return %*ENV<XDG_RUNTIME_DIR>.IO if %*ENV<XDG_RUNTIME_DIR>:exists;
+
+ # XDG_RUNTIME_DIR is the only XDG basedir variant that does not come with
+ # defaults. However, there are a number of de facto standard locations to
+ # make use of. Try them, and return whichever hits first that also seems to
+ # exist on the user's system.
+ [
+ "/var/run".IO.add(+$*USER),
+ "/var/run".IO.add(~$*USER),
+ $*HOME.add(".local/run"),
+ $*TMPDIR,
+ $*CWD,
+ ]
+ .grep(*.d)
+ .first
+ .add($*PID)
+}
+
+=begin pod
+
+=NAME IO::Path::XDG
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+=VERSION 0.2.0
+
+=head1 Synopsis
+
+=head1 Description
+
+=head1 Examples
+
+=head1 See also
+
+=end pod
+
+# vim: ft=raku noet