BuildFeatures.pm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright © 2007 Frank Lichtenheld <djpig@debian.org>
  2. # Copyright © 2010-2011 Raphaël Hertzog <hertzog@debian.org>
  3. # Copyright © 2010-2011 Bill Allombert <ballombe@debian.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. package Dpkg::BuildFeatures;
  18. use strict;
  19. use warnings;
  20. our $VERSION = "0.01";
  21. use Dpkg::Control::Info;
  22. =encoding utf8
  23. =head1 NAME
  24. Dpkg::BuildFeatures - parse the Build-Features control field
  25. =head1 DESCRIPTION
  26. The Dpkg::BuildFeatures object can be used to query the options
  27. stored in the Build-Features control field.
  28. =head1 FUNCTIONS
  29. =over 4
  30. =item my $bf = Dpkg::BuildFeatures->new($controlfile)
  31. Create a new Dpkg::BuildFeatures object. It will be initialized based
  32. on the value of the Build-Features control field. If $controlfile is omitted, it
  33. loads debian/control.
  34. =cut
  35. sub new {
  36. my ($this, $controlfile) = @_;
  37. my $class = ref($this) || $this;
  38. my $control = Dpkg::Control::Info->new($controlfile);
  39. my $src_fields = $control->get_source();
  40. my %buildfeats;
  41. if (defined($src_fields->{'Build-Features'})) {
  42. my @buildfeats = split(/\s*,\s*/m, $src_fields->{'Build-Features'});
  43. %buildfeats = map { $_ => 1 } @buildfeats;
  44. }
  45. my $self = { options => \%buildfeats };
  46. bless $self, $class;
  47. return $self;
  48. }
  49. =item $bf->has($option)
  50. Returns a boolean indicating whether the option is stored in the object.
  51. =cut
  52. sub has {
  53. my ($self, $key) = @_;
  54. return exists $self->{'options'}{$key};
  55. }
  56. =back
  57. =head1 AUTHOR
  58. Bill Allombert <ballombe@debian.org>
  59. =cut
  60. 1;