Vars.pm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright © 2007 Raphaël Hertzog <hertzog@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 <http://www.gnu.org/licenses/>.
  15. package Dpkg::Vars;
  16. use strict;
  17. use warnings;
  18. use Dpkg::ErrorHandling;
  19. use Dpkg::Gettext;
  20. use base qw(Exporter);
  21. our @EXPORT = qw($sourcepackage set_source_package);
  22. our $sourcepackage;
  23. sub check_package_name {
  24. my $name = shift || '';
  25. $name =~ m/[^-+.0-9a-z]/o &&
  26. error(_g("source package name `%s' contains illegal character `%s'"),
  27. $name, $&);
  28. $name =~ m/^[0-9a-z]/o ||
  29. error(_g("source package name `%s' starts with non-alphanum"), $name);
  30. }
  31. sub set_source_package {
  32. my $v = shift;
  33. check_package_name($v);
  34. if (defined($sourcepackage)) {
  35. $v eq $sourcepackage ||
  36. error(_g("source package has two conflicting values - %s and %s"),
  37. $sourcepackage, $v);
  38. } else {
  39. $sourcepackage = $v;
  40. }
  41. }
  42. 1;