/BackupManager/Config.pm

http://github.com/sukria/Backup-Manager · Perl · 57 lines · 35 code · 20 blank · 2 comment · 2 complexity · a5906daeb542675ba14472dfabbec100 MD5 · raw file

  1. #!/usr/bin/perl
  2. package BackupManager::Config;
  3. =head1 NAME
  4. BackupManager::Config - BackupManager's configuration module
  5. =head1 DESCRIPTION
  6. Basically, it's a Getopt wrapper and a conffile reader.
  7. =cut
  8. use strict;
  9. use warnings;
  10. =head1 FUNCTIONS
  11. =head2 getopt()
  12. Comes from debconf, thanks joeyh ;)
  13. first arg : $usage (text to be written on STDERR if help is needed).
  14. @_ : GetOpt args.
  15. =cut
  16. our $usage;
  17. sub getopt ($@) {
  18. my ($_usage, @args) = (@_);
  19. $usage = $_usage;
  20. my $showusage=sub { # closure
  21. print STDERR $_usage."\n";
  22. exit 1;
  23. };
  24. # don't load big Getopt::Long unless really necessary.
  25. return unless grep { $_ =~ /^-/ } @ARGV;
  26. require Getopt::Long;
  27. Getopt::Long::GetOptions(
  28. 'help|h', $showusage,
  29. @args,
  30. ) || $showusage->();
  31. }
  32. =head1 AUTHOR
  33. Alexis Sukrieh <sukria@sukria.net>
  34. =cut
  35. 1;