Vars.pm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. our $VERSION = "0.01";
  19. use Dpkg::ErrorHandling;
  20. use Dpkg::Gettext;
  21. use base qw(Exporter);
  22. our @EXPORT = qw($sourcepackage set_source_package);
  23. our $sourcepackage;
  24. sub check_package_name {
  25. my $name = shift || '';
  26. $name =~ m/[^-+.0-9a-z]/o &&
  27. error(_g("source package name `%s' contains illegal character `%s'"),
  28. $name, $&);
  29. $name =~ m/^[0-9a-z]/o ||
  30. error(_g("source package name `%s' starts with non-alphanum"), $name);
  31. }
  32. sub set_source_package {
  33. my $v = shift;
  34. check_package_name($v);
  35. if (defined($sourcepackage)) {
  36. $v eq $sourcepackage ||
  37. error(_g("source package has two conflicting values - %s and %s"),
  38. $sourcepackage, $v);
  39. } else {
  40. $sourcepackage = $v;
  41. }
  42. }
  43. 1;