| File: | Dpkg/BuildEnv.pm |
| Coverage: | 100.0% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 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 - 29 | =head1 NAME Dpkg::BuildEnv - track build environment =head1 DESCRIPTION The Dpkg::BuildEnv module is used by dpkg-buildflags to track the build environment variables being used and modified. B<Note>: This is a private module, its API can change at any time. =cut | ||||||
| 30 | |||||||
| 31 | package Dpkg::BuildEnv 0.01; | ||||||
| 32 | |||||||
| 33 | 366 366 366 | 813 308 4834 | use strict; | ||||
| 34 | 366 366 366 | 885 109 41055 | use warnings; | ||||
| 35 | |||||||
| 36 | my %env_modified = (); | ||||||
| 37 | my %env_accessed = (); | ||||||
| 38 | |||||||
| 39 - 48 | =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 | ||||||
| 49 | |||||||
| 50 | sub set { | ||||||
| 51 | 12 | 1 | 20 | my ($varname, $value) = @_; | |||
| 52 | 12 | 21 | $env_modified{$varname} = 1; | ||||
| 53 | 12 | 10 | $env_accessed{$varname} = 1; | ||||
| 54 | 12 | 80 | $ENV{$varname} = $value; | ||||
| 55 | } | ||||||
| 56 | |||||||
| 57 - 62 | =item get($varname) Get the build environment variable $varname value. Record it as being accessed. =cut | ||||||
| 63 | |||||||
| 64 | sub get { | ||||||
| 65 | 1479 | 1 | 1195 | my $varname = shift; | |||
| 66 | 1479 | 1271 | $env_accessed{$varname} = 1; | ||||
| 67 | 1479 | 3006 | return $ENV{$varname}; | ||||
| 68 | } | ||||||
| 69 | |||||||
| 70 - 75 | =item has($varname) Return a boolean indicating whether the environment variable exists. Record it as being accessed. =cut | ||||||
| 76 | |||||||
| 77 | sub has { | ||||||
| 78 | 2184 | 1 | 1549 | my $varname = shift; | |||
| 79 | 2184 | 2012 | $env_accessed{$varname} = 1; | ||||
| 80 | 2184 | 3161 | return exists $ENV{$varname}; | ||||
| 81 | } | ||||||
| 82 | |||||||
| 83 - 87 | =item @list = list_accessed() Returns a list of all environment variables that have been accessed. =cut | ||||||
| 88 | |||||||
| 89 | sub list_accessed { | ||||||
| 90 | 12 | 1 | 39 | my @list = sort keys %env_accessed; | |||
| 91 | 12 | 38 | return @list; | ||||
| 92 | } | ||||||
| 93 | |||||||
| 94 - 98 | =item @list = list_modified() Returns a list of all environment variables that have been modified. =cut | ||||||
| 99 | |||||||
| 100 | sub list_modified { | ||||||
| 101 | 12 | 1 | 26 | my @list = sort keys %env_modified; | |||
| 102 | 12 | 33 | return @list; | ||||
| 103 | } | ||||||
| 104 | |||||||
| 105 | =back | ||||||
| 106 | |||||||
| 107 - 113 | =head1 CHANGES =head2 Version 0.xx This is a private module. =cut | ||||||
| 114 | |||||||
| 115 | 1; | ||||||