1
package Image::RenRot::Util;
7
########################################################################################
9
########################################################################################
16
use vars qw(@ISA @EXPORT);
19
@EXPORT = qw(trim bool2str str2bool loadpkg);
21
########################################################################################
22
# Usage : trim($value)
23
# Purpose : removes heading and trailing spaces
24
# Returns : trimmed $value
25
# Parameters : $value string
26
# Throws : no exceptions
31
$value =~ s/^\s*//; # heading
32
$value =~ s/\s*$//; # trailing
36
########################################################################################
37
# Usage : bool2str($var)
38
# Purpose : converts boolean value to human readable string
39
# Returns : string "Yes" or "No"
41
# Throws : no exceptions
43
# See Also : str2bool()
52
########################################################################################
53
# Usage : str2bool($var)
54
# Purpose : converts given string to a boolean value
55
# Returns : number 1 or 0
56
# Parameters : one of "1", "Yes", "True", "On", "0", "No", "False" or "Off"
57
# Throws : no exceptions
59
# See Also : bool2str()
61
my $value = trim(shift);
62
if ($value =~ m/^(0|No|False|Off|Disable)$/i) {
64
} elsif ($value =~ m/^(1|Yes|True|On|Enable)$/i) {
70
########################################################################################
71
# Usage : loadpkg($pkg)
72
# Purpose : checks availability of given package (renrot could be depend of it)
73
# Returns : nothing in case the package available and undef if not
74
# Parameters : $pkg - string with package name
75
# Throws : no exceptions
80
return undef unless eval "require $pkg";
83
########################################################################################