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 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'lib/Config.pm6') 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(); } } -- cgit v1.1