Vars.pm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 along
  11. # with this program; if not, write to the Free Software Foundation, Inc.,
  12. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  13. package Dpkg::Vars;
  14. use strict;
  15. use warnings;
  16. use Dpkg::ErrorHandling qw(error);
  17. use Dpkg::Gettext;
  18. use Exporter;
  19. our @ISA = qw(Exporter);
  20. our @EXPORT = qw($sourcepackage set_source_package);
  21. our $sourcepackage;
  22. sub check_package_name {
  23. my $name = shift || '';
  24. $name =~ m/[^-+.0-9a-z]/o &&
  25. error(_g("source package name `%s' contains illegal character `%s'"),
  26. $name, $&);
  27. $name =~ m/^[0-9a-z]/o ||
  28. error(_g("source package name `%s' starts with non-alphanum"), $name);
  29. }
  30. sub set_source_package {
  31. my $v = shift;
  32. check_package_name($v);
  33. if (defined($sourcepackage)) {
  34. $v eq $sourcepackage ||
  35. error(_g("source package has two conflicting values - %s and %s"),
  36. $sourcepackage, $v);
  37. } else {
  38. $sourcepackage = $v;
  39. }
  40. }
  41. 1;