Vars.pm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. package Dpkg::Vars;
  13. use strict;
  14. use warnings;
  15. use Dpkg::ErrorHandling;
  16. use Dpkg::Gettext;
  17. use base qw(Exporter);
  18. our @EXPORT = qw($sourcepackage set_source_package);
  19. our $sourcepackage;
  20. sub check_package_name {
  21. my $name = shift || '';
  22. $name =~ m/[^-+.0-9a-z]/o &&
  23. error(_g("source package name `%s' contains illegal character `%s'"),
  24. $name, $&);
  25. $name =~ m/^[0-9a-z]/o ||
  26. error(_g("source package name `%s' starts with non-alphanum"), $name);
  27. }
  28. sub set_source_package {
  29. my $v = shift;
  30. check_package_name($v);
  31. if (defined($sourcepackage)) {
  32. $v eq $sourcepackage ||
  33. error(_g("source package has two conflicting values - %s and %s"),
  34. $sourcepackage, $v);
  35. } else {
  36. $sourcepackage = $v;
  37. }
  38. }
  39. 1;