Vars.pm 1.5 KB

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