File Coverage

blib/lib/Dpkg/Build/Env.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 5 5 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             # Copyright © 2012 Guillem Jover
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 .
15              
16             package Dpkg::Build::Env;
17              
18 537     537   75570 use strict;
  537         565  
  537         16648  
19 537     537   3199 use warnings;
  537         1084  
  537         142301  
20              
21             our $VERSION = '0.01';
22              
23             my %env_modified = ();
24             my %env_accessed = ();
25              
26             =encoding utf8
27              
28             =head1 NAME
29              
30             Dpkg::Build::Env - track build environment
31              
32             =head1 DESCRIPTION
33              
34             The Dpkg::Build::Env module is used by dpkg-buildflags to track the build
35             environment variables being used and modified.
36              
37             =head1 FUNCTIONS
38              
39             =over 4
40              
41             =item set($varname, $value)
42              
43             Update the build environment variable $varname with value $value. Record
44             it as being accessed and modified.
45              
46             =cut
47              
48             sub set {
49 4     4 1 13 my ($varname, $value) = @_;
50 4         9 $env_modified{$varname} = 1;
51 4         10 $env_accessed{$varname} = 1;
52 4         23 $ENV{$varname} = $value;
53             }
54              
55             =item get($varname)
56              
57             Get the build environment variable $varname value. Record it as being
58             accessed.
59              
60             =cut
61              
62             sub get {
63 342     342 1 609 my $varname = shift;
64 342         565 $env_accessed{$varname} = 1;
65 342         1122 return $ENV{$varname};
66             }
67              
68             =item has($varname)
69              
70             Return a boolean indicating whether the environment variable exists.
71             Record it as being accessed.
72              
73             =cut
74              
75             sub has {
76 520     520 1 832 my $varname = shift;
77 520         918 $env_accessed{$varname} = 1;
78 520         1573 return exists $ENV{$varname};
79             }
80              
81             =item @list = list_accessed()
82              
83             Returns a list of all environment variables that have been accessed.
84              
85             =cut
86              
87             sub list_accessed {
88 4     4 1 118 my @list = sort keys %env_accessed;
89 4         19 return @list;
90             }
91              
92             =item @list = list_modified()
93              
94             Returns a list of all environment variables that have been modified.
95              
96             =cut
97              
98             sub list_modified {
99 4     4 1 15 my @list = sort keys %env_modified;
100 4         18 return @list;
101             }
102              
103             =back
104              
105             =head1 CHANGES
106              
107             =head2 Version 0.xx
108              
109             This is a private module.
110              
111             =cut
112              
113             1;