~ubuntu-branches/ubuntu/vivid/renrot/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/Image/RenRot/Util.pm

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2014-10-06 14:04:27 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141006140427-ax0dwq886zjo2x3r
Tags: 1.2.0-0.1
* Non-maintainer upload
* New upstream version 1.2.0 (Closes: #402702, #729630, #539346)
* Don't depend on versioned libjpeg-progs (Closes: #764215)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Image::RenRot::Util;
 
2
 
 
3
#
 
4
# vim: ts=2 sw=2 et :
 
5
#
 
6
 
 
7
########################################################################################
 
8
###                               COMMON HELPERS                                     ###
 
9
########################################################################################
 
10
 
 
11
use strict;
 
12
use warnings;
 
13
require 5.006;
 
14
require Exporter;
 
15
 
 
16
use vars qw(@ISA @EXPORT);
 
17
 
 
18
@ISA = qw(Exporter);
 
19
@EXPORT = qw(trim bool2str str2bool loadpkg);
 
20
 
 
21
########################################################################################
 
22
# Usage      : trim($value)
 
23
# Purpose    : removes heading and trailing spaces
 
24
# Returns    : trimmed $value
 
25
# Parameters : $value string
 
26
# Throws     : no exceptions
 
27
# Comments   : none
 
28
# See Also   : N/A
 
29
sub trim($) {
 
30
  my $value = shift;
 
31
  $value =~ s/^\s*//; # heading
 
32
  $value =~ s/\s*$//; # trailing
 
33
  return $value;
 
34
}
 
35
 
 
36
########################################################################################
 
37
# Usage      : bool2str($var)
 
38
# Purpose    : converts boolean value to human readable string
 
39
# Returns    : string "Yes" or "No"
 
40
# Parameters : 0 or 1
 
41
# Throws     : no exceptions
 
42
# Comments   : none
 
43
# See Also   : str2bool()
 
44
sub bool2str($) {
 
45
  if (shift == 0) {
 
46
    return "No";
 
47
  } else {
 
48
    return "Yes";
 
49
  }
 
50
}
 
51
 
 
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
 
58
# Comments   : none
 
59
# See Also   : bool2str()
 
60
sub str2bool($) {
 
61
  my $value = trim(shift);
 
62
  if ($value =~ m/^(0|No|False|Off|Disable)$/i) {
 
63
    return 0;
 
64
  } elsif ($value =~ m/^(1|Yes|True|On|Enable)$/i) {
 
65
    return 1;
 
66
  }
 
67
  return $value;
 
68
}
 
69
 
 
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
 
76
# Comments   : none
 
77
# See Also   : n/a
 
78
sub loadpkg($) {
 
79
  my $pkg = shift;
 
80
  return undef unless eval "require $pkg";
 
81
}
 
82
 
 
83
########################################################################################
 
84
1;  # end