aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-27 15:01:23 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-07-25 02:16:21 +0200
commit14370ef0978b3955852afb9159ae7414471f6324 (patch)
tree4ee13ad2ee3e2c2c3a6b86621918ae09ab3c2ac2 /lib
parentcda7a1812e05220de069d44dd8be40e855fb4bd7 (diff)
Update method sigs, type checking and tests
Diffstat (limited to 'lib')
-rw-r--r--lib/Config.pm628
-rw-r--r--lib/Config/Exception/UnknownTypeException.pm613
-rw-r--r--lib/Config/Type.pm68
3 files changed, 9 insertions, 40 deletions
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index a13f589..ad350bf 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -5,9 +5,7 @@ use v6.c;
use Hash::Merge;
use Config::Exception::MissingParserException;
-use Config::Exception::UnknownTypeException;
use Config::Exception::FileNotFoundException;
-use Config::Type;
use Config::Parser;
class Config is export
@@ -54,30 +52,22 @@ class Config is export
#| Get the name of the parser module to use for the
#| given path.
- method get-parser(Str $path, Str $parser = "")
+ method get-parser(Str $path, Str $parser = "" --> Str)
{
- if ($parser ne "") {
- return $parser;
- }
-
- if ($!parser ne "") {
- return $!parser;
- }
+ return $parser if $parser ne "";
+ return $!parser if $!parser ne "";
+ say $!parser;
my $type = self.get-parser-type($path);
- Config::Exception::UnknownTypeException.new(
- file => $path
- ).throw() if $type eq Config::Type::unknown;
-
"Config::Parser::" ~ $type;
}
#| Get the type of parser required for the given path.
- method get-parser-type(Str $path)
+ method get-parser-type(Str $path --> Str)
{
given ($path) {
- when .ends-with(".yml") { return Config::Type::yaml; };
+ when .ends-with(".yml") { return "yaml"; };
}
my $file = $path;
@@ -87,10 +77,10 @@ class Config is export
}
if (defined($file.index("."))) {
- return $file.split(".")[*-1];
+ return $file.split(".")[*-1].lc;
}
- return Config::Type::unknown;
+ return "";
}
#| Check wether a given key exists.
@@ -139,7 +129,7 @@ class Config is export
CATCH {
when X::CompUnit::UnsatisfiedDependency {
Config::Exception::MissingParserException.new(
- parser => $parser
+ parser => $!parser
).throw();
}
}
diff --git a/lib/Config/Exception/UnknownTypeException.pm6 b/lib/Config/Exception/UnknownTypeException.pm6
deleted file mode 100644
index 095572b..0000000
--- a/lib/Config/Exception/UnknownTypeException.pm6
+++ /dev/null
@@ -1,13 +0,0 @@
-#! /usr/bin/env false
-
-use v6.c;
-
-class Config::Exception::UnknownTypeException is Exception
-{
- has Str $.file;
-
- method message()
- {
- "Could not deduce loader type for $!file."
- }
-}
diff --git a/lib/Config/Type.pm6 b/lib/Config/Type.pm6
deleted file mode 100644
index f348985..0000000
--- a/lib/Config/Type.pm6
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /usr/bin/env false
-
-use v6.c;
-
-enum Config::Type <
- unknown
- yaml
->;