From c40e6ae736f82f133d89b9b60cd6ff23c7690c6a Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 27 Apr 2017 15:01:23 +0200 Subject: Update method sigs, type checking and tests --- lib/Config.pm6 | 28 +++++++++------------------ lib/Config/Exception/UnknownTypeException.pm6 | 13 ------------- lib/Config/Type.pm6 | 8 -------- 3 files changed, 9 insertions(+), 40 deletions(-) delete mode 100644 lib/Config/Exception/UnknownTypeException.pm6 delete mode 100644 lib/Config/Type.pm6 (limited to 'lib') 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 ->; -- cgit v1.1