| 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 | =encoding utf8 | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Dpkg::BuildEnv - track build environment | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | The Dpkg::BuildEnv module is used by dpkg-buildflags to track the build | ||
| 25 | environment variables being used and modified. | ||
| 26 | |||
| 27 | B<Note>: This is a private module, its API can change at any time. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | package Dpkg::BuildEnv 0.01; | ||
| 32 | |||
| 33 | 26 | ▶ | use v5.36; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | |||
| 35 | 26 | my %env_modified = (); | |
| 36 | 26 | my %env_accessed = (); | |
| 37 | |||
| 38 | =head1 FUNCTIONS | ||
| 39 | |||
| 40 | =over 4 | ||
| 41 | |||
| 42 | =item set($varname, $value) | ||
| 43 | |||
| 44 | Update the build environment variable $varname with value $value. Record | ||
| 45 | it as being accessed and modified. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | 4 | ▶ | sub set { |
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||
| 50 | 4 | my ($varname, $value) = @_; | |
| 51 | 4 | $env_modified{$varname} = 1; | |
| 52 | 4 | $env_accessed{$varname} = 1; | |
| 53 | 4 | $ENV{$varname} = $value; | |
| 54 | } | ||
| 55 | |||
| 56 | =item $value = get($varname) | ||
| 57 | |||
| 58 | Get the build environment variable $varname value. Record it as being | ||
| 59 | accessed. | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | 490 | ▶ | sub get { |
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||
| 64 | 490 | my $varname = shift; | |
| 65 | 490 | $env_accessed{$varname} = 1; | |
| 66 | 490 | return $ENV{$varname}; | |
| 67 | } | ||
| 68 | |||
| 69 | =item $bool = has($varname) | ||
| 70 | |||
| 71 | Return a boolean indicating whether the environment variable exists. | ||
| 72 | Record it as being accessed. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | 558 | ▶ | sub has { |
|
Subroutine
has: called CC=1 SCAR=0.0
Pod
documented
| |||
| 77 | 558 | my $varname = shift; | |
| 78 | 558 | $env_accessed{$varname} = 1; | |
| 79 | 558 | return exists $ENV{$varname}; | |
| 80 | } | ||
| 81 | |||
| 82 | =item @list = list_accessed() | ||
| 83 | |||
| 84 | Returns a list of all environment variables that have been accessed. | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | 4 | ▶ | sub list_accessed { |
|
Subroutine
list_accessed: called CC=1 SCAR=0.0
Pod
documented
| |||
| 89 | 4 | my @list = sort keys %env_accessed; | |
| 90 | 4 | return @list; | |
| 91 | } | ||
| 92 | |||
| 93 | =item @list = list_modified() | ||
| 94 | |||
| 95 | Returns a list of all environment variables that have been modified. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | 4 | ▶ | sub list_modified { |
|
Subroutine
list_modified: called CC=1 SCAR=0.0
Pod
documented
| |||
| 100 | 4 | my @list = sort keys %env_modified; | |
| 101 | 4 | return @list; | |
| 102 | } | ||
| 103 | |||
| 104 | =back | ||
| 105 | |||
| 106 | =head1 CHANGES | ||
| 107 | |||
| 108 | =head2 Version 0.xx | ||
| 109 | |||
| 110 | This is a private module. | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | 26 | 1; | |