Skip to content
Snippets Groups Projects
Commit 6e421593 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added booleanize() function

parent 8f01ff27
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,8 @@ our (@ISA,@EXPORT,@EXPORT_OK); ...@@ -33,6 +33,8 @@ our (@ISA,@EXPORT,@EXPORT_OK);
isUsername isUsername
isIP isIP
isNumber isNumber
booleanize
); );
@EXPORT_OK = qw( @EXPORT_OK = qw(
); );
...@@ -174,5 +176,38 @@ sub isNumber ...@@ -174,5 +176,38 @@ sub isNumber
} }
# Booleanize the variable depending on its contents
sub booleanize
{
my $var = shift;
# Check if we're defined
if (!isVariable($var)) {
return undef;
}
# If we're a number
if (my $val = isNumber($var)) {
if ($val == 0) {
return 0;
} else {
return 1;
}
}
# Nuke whitespaces
$var =~ s/\s//g;
# Allow true, on, set, enabled, 1
if ($var =~ /^(?:true|on|set|enabled|1|yes)$/i) {
return 1;
}
# Invalid or unknown
return 0;
}
1; 1;
# vim: ts=4 # vim: ts=4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment