From ea314d2f45c40a006c0104157013ab4b857f665f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 20:35:28 +0200 Subject: Adding upstream version 1.22.4. Signed-off-by: Daniel Baumann --- scripts/Dpkg/Package.pm | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 scripts/Dpkg/Package.pm (limited to 'scripts/Dpkg/Package.pm') diff --git a/scripts/Dpkg/Package.pm b/scripts/Dpkg/Package.pm new file mode 100644 index 0000000..4741a6f --- /dev/null +++ b/scripts/Dpkg/Package.pm @@ -0,0 +1,96 @@ +# Copyright © 2006 Frank Lichtenheld +# Copyright © 2007-2009, 2012-2013 Guillem Jover +# Copyright © 2007 Raphaël Hertzog +# +# 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 . + +=encoding utf8 + +=head1 NAME + +Dpkg::Package - package properties handling + +=head1 DESCRIPTION + +This module provides functions to parse and validate package properties. + +B: 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; -- cgit v1.2.3