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