dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / Dpkg / Build / Env.pm
CommitLineData
1479465f
GJ
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
16package Dpkg::Build::Env;
17
18use strict;
19use warnings;
20
21our $VERSION = '0.01';
22
23my %env_modified = ();
24my %env_accessed = ();
25
26=encoding utf8
27
28=head1 NAME
29
30Dpkg::Build::Env - track build environment
31
32=head1 DESCRIPTION
33
34The Dpkg::Build::Env module is used by dpkg-buildflags to track the build
35environment variables being used and modified.
36
37=head1 FUNCTIONS
38
39=over 4
40
41=item $bf->set($varname, $value)
42
43Update the build environment variable $varname with value $value. Record
44it as being accessed and modified.
45
46=cut
47
48sub 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
57Get the build environment variable $varname value. Record it as being
58accessed.
59
60=cut
61
62sub get {
63 my $varname = shift;
64 $env_accessed{$varname} = 1;
65 return $ENV{$varname};
66}
67
68=item $bf->has($varname)
69
70Return a boolean indicating whether the environment variable exists.
71Record it as being accessed.
72
73=cut
74
75sub has {
76 my $varname = shift;
77 $env_accessed{$varname} = 1;
78 return exists $ENV{$varname};
79}
80
81=item @list = $bf->list_accessed()
82
83Returns a list of all environment variables that have been accessed.
84
85=cut
86
87sub list_accessed {
88 my @list = sort keys %env_accessed;
89 return @list;
90}
91
92=item @list = $bf->list_modified()
93
94Returns a list of all environment variables that have been modified.
95
96=cut
97
98sub list_modified {
99 my @list = sort keys %env_modified;
100 return @list;
101}
102
103=back
104
105=head1 CHANGES
106
107=head2 Version 0.xx
108
109This is a private module.
110
111=cut
112
1131;