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