PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/perl/Choicetool/OS/Environment.pm

#
Perl | 95 lines | 51 code | 23 blank | 21 comment | 1 complexity | 926402e50669ef8b31f21022ec8285bc MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- perl -*-
  2. #
  3. # Environment.pm
  4. #
  5. # Copyright (C) 2008, 2009 Francesco Salvestrini
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. package Choicetool::OS::Environment;
  22. use 5.8.0;
  23. use warnings;
  24. use strict;
  25. use diagnostics;
  26. use Choicetool::Base::Debug;
  27. use Choicetool::Base::Trace;
  28. BEGIN {
  29. use Exporter ();
  30. our ($VERSION, @ISA, @EXPORT);
  31. @ISA = qw(Exporter);
  32. @EXPORT = qw(&environment_get
  33. &environment_set
  34. &environment_remove
  35. &environment_clear
  36. &environment_foreach);
  37. }
  38. sub environment_foreach ($)
  39. {
  40. my $callback_ref = shift;
  41. assert(defined($callback_ref));
  42. for my $key (keys(%ENV)) {
  43. $callback_ref->($key, $ENV{$key});
  44. }
  45. }
  46. sub environment_get ($)
  47. {
  48. my $variable = shift;
  49. assert(defined($variable));
  50. return $ENV{$variable};
  51. }
  52. sub environment_remove ($)
  53. {
  54. my $variable = shift;
  55. assert(defined($variable));
  56. delete $ENV{$variable};
  57. return 1;
  58. }
  59. sub environment_set ($)
  60. {
  61. my $variable = shift;
  62. my $value = shift;
  63. assert(defined($variable));
  64. #assert(defined($value));
  65. $ENV{$variable} = $value;
  66. return 1;
  67. }
  68. sub environment_clear ($)
  69. {
  70. %ENV = ();
  71. }
  72. 1;