File Coverage

File:Dpkg/Build/Env.pm
Coverage:100.0%

linestmtbrancondsubpodtimecode
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
18
92
92
92
186
37
934
use strict;
19
92
92
92
137
81
8952
use warnings;
20
21our $VERSION = '0.01';
22
23my %env_modified = ();
24my %env_accessed = ();
25
26=encoding utf8
27
28 - 46
=head1 NAME

Dpkg::Build::Env - track build environment

=head1 DESCRIPTION

The Dpkg::Build::Env module is used by dpkg-buildflags to track the build
environment variables being used and modified.

=head1 FUNCTIONS

=over 4

=item set($varname, $value)

Update the build environment variable $varname with value $value. Record
it as being accessed and modified.

=cut
47
48sub set {
49
4
1
4
    my ($varname, $value) = @_;
50
4
4
    $env_modified{$varname} = 1;
51
4
4
    $env_accessed{$varname} = 1;
52
4
13
    $ENV{$varname} = $value;
53}
54
55 - 60
=item get($varname)

Get the build environment variable $varname value. Record it as being
accessed.

=cut
61
62sub get {
63
345
1
179
    my $varname = shift;
64
345
236
    $env_accessed{$varname} = 1;
65
345
411
    return $ENV{$varname};
66}
67
68 - 73
=item has($varname)

Return a boolean indicating whether the environment variable exists.
Record it as being accessed.

=cut
74
75sub has {
76
620
1
354
    my $varname = shift;
77
620
395
    $env_accessed{$varname} = 1;
78
620
611
    return exists $ENV{$varname};
79}
80
81 - 85
=item @list = list_accessed()

Returns a list of all environment variables that have been accessed.

=cut
86
87sub list_accessed {
88
4
1
8
    my @list = sort keys %env_accessed;
89
4
7
    return @list;
90}
91
92 - 96
=item @list = list_modified()

Returns a list of all environment variables that have been modified.

=cut
97
98sub list_modified {
99
4
1
6
    my @list = sort keys %env_modified;
100
4
7
    return @list;
101}
102
103=back
104
105 - 111
=head1 CHANGES

=head2 Version 0.xx

This is a private module.

=cut
112
1131;