Env.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. package Dpkg::Build::Env;
  16. use strict;
  17. use warnings;
  18. our $VERSION = '0.01';
  19. my %env_modified = ();
  20. my %env_accessed = ();
  21. =encoding utf8
  22. =head1 NAME
  23. Dpkg::Build::Env - track build environment
  24. =head1 DESCRIPTION
  25. The Dpkg::Build::Env module is used by dpkg-buildflags to track the build
  26. environment variables being used and modified.
  27. =head1 FUNCTIONS
  28. =over 4
  29. =item $bf->set($varname, $value)
  30. Update the build environment variable $varname with value $value. Record
  31. it as being accessed and modified.
  32. =cut
  33. sub set {
  34. my ($varname, $value) = @_;
  35. $env_modified{$varname} = 1;
  36. $env_accessed{$varname} = 1;
  37. $ENV{$varname} = $value;
  38. }
  39. =item $bf->get($varname)
  40. Get the build environment variable $varname value. Record it as being
  41. accessed.
  42. =cut
  43. sub get {
  44. my $varname = shift;
  45. $env_accessed{$varname} = 1;
  46. return $ENV{$varname};
  47. }
  48. =item $bf->has($varname)
  49. Return a boolean indicating whether the environment variable exists.
  50. Record it as being accessed.
  51. =cut
  52. sub has {
  53. my $varname = shift;
  54. $env_accessed{$varname} = 1;
  55. return exists $ENV{$varname};
  56. }
  57. =item @list = $bf->list_accessed()
  58. Returns a list of all environment variables that have been accessed.
  59. =cut
  60. sub list_accessed {
  61. my @list = sort keys %env_accessed;
  62. return @list;
  63. }
  64. =item @list = $bf->list_modified()
  65. Returns a list of all environment variables that have been modified.
  66. =cut
  67. sub list_modified {
  68. my @list = sort keys %env_modified;
  69. return @list;
  70. }
  71. =back
  72. =head1 CHANGES
  73. =head2 Version 0.xx
  74. This is a private module.
  75. =cut
  76. 1;