OLD | NEW |
| (Empty) |
1 # Copyright © 2012 Guillem Jover <guillem@debian.org> | |
2 # | |
3 # This program is free software; you can redistribute it and/or modify | |
4 # it under the terms of the GNU General Public License as published by | |
5 # the Free Software Foundation; either version 2 of the License, or | |
6 # (at your option) any later version. | |
7 # | |
8 # This program is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 # | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | |
16 package Dpkg::BuildEnv; | |
17 | |
18 use strict; | |
19 use warnings; | |
20 | |
21 our $VERSION = '0.01'; | |
22 | |
23 my %env_modified = (); | |
24 my %env_accessed = (); | |
25 | |
26 =encoding utf8 | |
27 | |
28 =head1 NAME | |
29 | |
30 Dpkg::BuildEnv - track build environment | |
31 | |
32 =head1 DESCRIPTION | |
33 | |
34 The Dpkg::BuildEnv module is used by dpkg-buildflags to track the build | |
35 environment variables being used and modified. | |
36 | |
37 =head1 FUNCTIONS | |
38 | |
39 =over 4 | |
40 | |
41 =item $bf->set($varname, $value) | |
42 | |
43 Update the build environment variable $varname with value $value. Record | |
44 it as being accessed and modified. | |
45 | |
46 =cut | |
47 | |
48 sub set { | |
49 my ($varname, $value) = @_; | |
50 $env_modified{$varname} = 1; | |
51 $env_accessed{$varname} = 1; | |
52 $ENV{$varname} = $value; | |
53 } | |
54 | |
55 =item $bf->get($varname) | |
56 | |
57 Get the build environment variable $varname value. Record it as being | |
58 accessed. | |
59 | |
60 =cut | |
61 | |
62 sub get { | |
63 my ($varname) = @_; | |
64 $env_accessed{$varname} = 1; | |
65 return $ENV{$varname}; | |
66 } | |
67 | |
68 =item $bf->has($varname) | |
69 | |
70 Return a boolean indicating whether the environment variable exists. | |
71 Record it as being accessed. | |
72 | |
73 =cut | |
74 | |
75 sub has { | |
76 my ($varname) = @_; | |
77 $env_accessed{$varname} = 1; | |
78 return exists $ENV{$varname}; | |
79 } | |
80 | |
81 =item my @list = $bf->list_accessed() | |
82 | |
83 Returns a list of all environment variables that have been accessed. | |
84 | |
85 =cut | |
86 | |
87 sub list_accessed { | |
88 my @list = sort keys %env_accessed; | |
89 return @list; | |
90 } | |
91 | |
92 =item my @list = $bf->list_modified() | |
93 | |
94 Returns a list of all environment variables that have been modified. | |
95 | |
96 =cut | |
97 | |
98 sub list_modified { | |
99 my @list = sort keys %env_modified; | |
100 return @list; | |
101 } | |
102 | |
103 =back | |
104 | |
105 =cut | |
106 | |
107 1; | |
OLD | NEW |