test: Move test_data_file() to test.h
[dpkg.git] / scripts / Dpkg / BuildEnv.pm
blob98ff3fda60885cb69970c3c8279f1dc36f62d29b
1 # Copyright © 2012 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
16 =encoding utf8
18 =head1 NAME
20 Dpkg::BuildEnv - track build environment
22 =head1 DESCRIPTION
24 The Dpkg::BuildEnv module is used by dpkg-buildflags to track the build
25 environment variables being used and modified.
27 B<Note>: This is a private module, its API can change at any time.
29 =cut
31 package Dpkg::BuildEnv 0.01;
33 use strict;
34 use warnings;
36 my %env_modified = ();
37 my %env_accessed = ();
39 =head1 FUNCTIONS
41 =over 4
43 =item set($varname, $value)
45 Update the build environment variable $varname with value $value. Record
46 it as being accessed and modified.
48 =cut
50 sub set {
51 my ($varname, $value) = @_;
52 $env_modified{$varname} = 1;
53 $env_accessed{$varname} = 1;
54 $ENV{$varname} = $value;
57 =item get($varname)
59 Get the build environment variable $varname value. Record it as being
60 accessed.
62 =cut
64 sub get {
65 my $varname = shift;
66 $env_accessed{$varname} = 1;
67 return $ENV{$varname};
70 =item has($varname)
72 Return a boolean indicating whether the environment variable exists.
73 Record it as being accessed.
75 =cut
77 sub has {
78 my $varname = shift;
79 $env_accessed{$varname} = 1;
80 return exists $ENV{$varname};
83 =item @list = list_accessed()
85 Returns a list of all environment variables that have been accessed.
87 =cut
89 sub list_accessed {
90 my @list = sort keys %env_accessed;
91 return @list;
94 =item @list = list_modified()
96 Returns a list of all environment variables that have been modified.
98 =cut
100 sub list_modified {
101 my @list = sort keys %env_modified;
102 return @list;
105 =back
107 =head1 CHANGES
109 =head2 Version 0.xx
111 This is a private module.
113 =cut