aboutsummaryrefslogtreecommitdiff
path: root/IdaliusConfig.pm
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-09-21 14:18:31 +1200
committerDavid Phillips <david@sighup.nz>2018-09-21 14:18:31 +1200
commitf2812c477b230a1407381bfbbb393119c7280076 (patch)
tree1ffd362839130c8e9299b4169903bdb1334de6f5 /IdaliusConfig.pm
parent3b2be99aa12addab406d05c886b59b85b1ae4380 (diff)
downloadidalius-f2812c477b230a1407381bfbbb393119c7280076.tar.xz
Refactor config assertions
Diffstat (limited to 'IdaliusConfig.pm')
-rw-r--r--IdaliusConfig.pm28
1 files changed, 11 insertions, 17 deletions
diff --git a/IdaliusConfig.pm b/IdaliusConfig.pm
index 4a8b42f..21c4efa 100644
--- a/IdaliusConfig.pm
+++ b/IdaliusConfig.pm
@@ -14,35 +14,29 @@ sub config_describe {
return "$plugin -> $parm";
}
-sub assert_scalar {
- my ($config, $plugin, $parm) = @_;
+sub assert_common {
+ my ($config, $plugin, $parm, $human_type, $ref_type) = @_;
my $ref = $config->{$parm};
my $name = config_describe($plugin, $parm);
- die "Error: Configuration \"$name\" must be scalar" unless
+ die "Error: Configuration \"$name\" must be of type $human_type" unless
defined $ref
- and ref($ref) eq "";
+ and ref($ref) eq $ref_type;
}
-sub assert_list {
+sub assert_scalar {
my ($config, $plugin, $parm) = @_;
- my $ref = $config->{$parm};
- my $name = config_describe($plugin, $parm);
+ assert_common($config, $plugin, $parm, "scalar", "");
+}
- die "Error: Configuration \"$name\" must be list" unless
- defined $ref
- and ref($ref) eq "ARRAY";
+sub assert_list {
+ my ($config, $plugin, $parm) = @_;
+ assert_common($config, $plugin, $parm, "list", "ARRAY");
}
sub assert_dict {
my ($config, $plugin, $parm) = @_;
- my $ref = $config->{$parm};
- my $name = config_describe($plugin, $parm);
-
- die "Error: Configuration \"$name\" must be dictionary" unless
- defined $ref
- and ref($ref) eq "HASH";
-
+ assert_common($config, $plugin, $parm, "dictionary", "HASH");
}
# Check presence and/or sanity of config parameters for the bot's core