man: Add dpkg-build-api behavior for Rules-Requires-Root field defaults
[dpkg.git] / scripts / Dpkg / Package.pm
blob4741a6f457f8884ec1dce2a16c19e567265dddbe
1 # Copyright © 2006 Frank Lichtenheld <djpig@debian.org>
2 # Copyright © 2007-2009, 2012-2013 Guillem Jover <guillem@debian.org>
3 # Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 =encoding utf8
20 =head1 NAME
22 Dpkg::Package - package properties handling
24 =head1 DESCRIPTION
26 This module provides functions to parse and validate package properties.
28 B<Note>: This is a private module, its API can change at any time.
30 =cut
32 package Dpkg::Package 0.01;
34 use strict;
35 use warnings;
37 our @EXPORT = qw(
38 pkg_name_is_illegal
40 get_source_name
41 set_source_name
44 use Exporter qw(import);
46 use Dpkg::ErrorHandling;
47 use Dpkg::Gettext;
49 sub pkg_name_is_illegal($) {
50 my $name = shift // '';
52 if ($name eq '') {
53 return g_('may not be empty string');
55 if ($name =~ m/[^-+.0-9a-z]/op) {
56 return sprintf(g_("character '%s' not allowed"), ${^MATCH});
58 if ($name !~ m/^[0-9a-z]/o) {
59 return g_('must start with an alphanumeric character');
62 return;
65 # XXX: Eventually the following functions should be moved as methods for
66 # Dpkg::Source::Package.
68 my $source_name;
70 sub get_source_name {
71 return $source_name;
74 sub set_source_name {
75 my $name = shift;
77 my $err = pkg_name_is_illegal($name);
78 error(g_("source package name '%s' is illegal: %s"), $name, $err) if $err;
80 if (not defined $source_name) {
81 $source_name = $name;
82 } elsif ($name ne $source_name) {
83 error(g_('source package has two conflicting values - %s and %s'),
84 $source_name, $name);
88 =head1 CHANGES
90 =head2 Version 0.xx
92 This is a private module.
94 =cut