diff options
author | Patrick Spek <p.spek@tyil.nl> | 2020-07-12 10:37:34 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2020-07-12 10:37:34 +0200 |
commit | 0d1737fb2ab52cf56ddf2146e5ff910dfc66d7b4 (patch) | |
tree | 2101379f64cf4b922b604ce847e72f4d207317c7 | |
parent | 5bb23ec4cd01cafa5b8a5a8db0b038376099a956 (diff) | |
download | config-parser-toml-0d1737fb2ab52cf56ddf2146e5ff910dfc66d7b4.tar.gz config-parser-toml-0d1737fb2ab52cf56ddf2146e5ff910dfc66d7b4.tar.bz2 |
Modernize the module
-rw-r--r-- | META6.json | 4 | ||||
-rw-r--r-- | lib/Config/Parser/toml.pm6 | 21 | ||||
-rw-r--r-- | lib/Config/Parser/toml.rakumod | 20 | ||||
-rw-r--r-- | t/01-read.t | 5 | ||||
-rw-r--r-- | t/02-write.t | 12 |
5 files changed, 30 insertions, 32 deletions
@@ -1,7 +1,7 @@ { "perl": "6", "name": "Config::Parser::toml", - "version": "1.0.0", + "version": "1.0.1", "auth": "github:scriptkitties", "description": "TOML parser for Config", "license": "GPL-3.0", @@ -10,7 +10,7 @@ "Config::TOML" ], "provides": { - "Config::Parser::toml": "lib/Config/Parser/toml.pm6" + "Config::Parser::toml": "lib/Config/Parser/toml.rakumod" }, "authors": [ "Patrick Spek <p.spek@tyil.work>" diff --git a/lib/Config/Parser/toml.pm6 b/lib/Config/Parser/toml.pm6 deleted file mode 100644 index 7d63593..0000000 --- a/lib/Config/Parser/toml.pm6 +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/env false - -use v6.c; - -use Config::Parser; -use Config::TOML; - -class Config::Parser::toml is Config::Parser -{ - method read(Str $path --> Hash) - { - from-toml(slurp $path); - } - - method write(Str $path, Hash $config --> Bool) - { - spurt $path, to-toml($config); - - True; - } -} diff --git a/lib/Config/Parser/toml.rakumod b/lib/Config/Parser/toml.rakumod new file mode 100644 index 0000000..62fbc8c --- /dev/null +++ b/lib/Config/Parser/toml.rakumod @@ -0,0 +1,20 @@ +#! /usr/bin/env false + +use v6.d; + +use Config::Parser; +use Config::TOML; + +unit class Config::Parser::toml is Config::Parser; + +method read(IO() $path --> Hash) +{ + from-toml($path.slurp); +} + +method write(IO() $path, Hash $config --> Bool) +{ + $path.spurt(to-toml($config)); + + True; +} diff --git a/t/01-read.t b/t/01-read.t index fa5a75b..5c15087 100644 --- a/t/01-read.t +++ b/t/01-read.t @@ -5,13 +5,12 @@ use Test; use lib "lib"; use Config; -use Config::Parser::toml; plan 4; my $config = Config.new(); -ok $config.read("t/files/config.toml"), "File reading throws no error"; +ok $config.read('t/files/config.toml'.IO), "File reading throws no error"; subtest "Contents match" => { plan 2; @@ -20,7 +19,7 @@ subtest "Contents match" => { is $config.get("header.b"), "b", "b = b"; }; -ok $config.read("t/files/merge.toml"), "File merging throws no error"; +ok $config.=read('t/files/merge.toml'.IO), "File merging throws no error"; subtest "Contents match after merging" => { plan 4; diff --git a/t/02-write.t b/t/02-write.t index 5eb7d92..7034302 100644 --- a/t/02-write.t +++ b/t/02-write.t @@ -1,18 +1,18 @@ #! /usr/bin/env perl6 use v6.c; -use Test; -use lib "lib"; use Config; -use Config::Parser::toml; use File::Temp; +use Test; + +use Config::Parser::toml; plan 4; my $config = Config.new(); -$config.read({ +$config.=read({ first => { a => "a", b => "b" @@ -25,10 +25,10 @@ $config.read({ my ($filename, $fh) = tempfile; -ok $config.write($filename, "Config::Parser::toml"), "Write succeeded"; +ok $config.write($filename.IO, Config::Parser::toml), "Write succeeded"; is slurp("t/files/write.toml"), slurp($filename), "Written config is correct"; -ok $config.write($filename, "Config::Parser::toml"), "Write over non-empty file"; +ok $config.write($filename.IO, Config::Parser::toml), "Write over non-empty file"; is slurp("t/files/write.toml"), slurp($filename), "Written config is still correct"; |