<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright Â© 2007-2009 RaphaÃ«l Hertzog &lt;hertzog@debian.org&gt;
#
# 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 &lt;https://www.gnu.org/licenses/&gt;.

=encoding utf8

=head1 NAME

Dpkg::Control::FieldsCore - manage (list of official) control fields

=head1 DESCRIPTION

The modules contains a list of field names with associated meta-data explaining
in which type of control information they are allowed. The types are the
CTRL_* constants exported by L&lt;Dpkg::Control&gt;.

=cut

package Dpkg::Control::FieldsCore 1.02;

use strict;
use warnings;

our @EXPORT = qw(
    field_capitalize
    field_is_official
    field_is_allowed_in
    field_transfer_single
    field_transfer_all
    field_parse_binary_source
    field_list_src_dep
    field_list_pkg_dep
    field_get_dep_type
    field_get_sep_type
    field_ordered_list
    field_register
    field_insert_after
    field_insert_before
    FIELD_SEP_UNKNOWN
    FIELD_SEP_SPACE
    FIELD_SEP_COMMA
    FIELD_SEP_LINE
);

use Exporter qw(import);

use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Control::Types;

use constant {
    ALL_PKG =&gt; CTRL_TMPL_PKG | CTRL_REPO_PKG | CTRL_DEB | CTRL_FILE_STATUS,
    ALL_SRC =&gt; CTRL_TMPL_SRC | CTRL_REPO_SRC | CTRL_DSC,
    ALL_FILE_MANIFEST =&gt; CTRL_FILE_BUILDINFO | CTRL_FILE_CHANGES,
    ALL_CHANGES =&gt; CTRL_FILE_CHANGES | CTRL_CHANGELOG,
    ALL_COPYRIGHT =&gt; CTRL_COPYRIGHT_HEADER | CTRL_COPYRIGHT_FILES | CTRL_COPYRIGHT_LICENSE,
};

use constant {
    FIELD_SEP_UNKNOWN =&gt; 0,
    FIELD_SEP_SPACE =&gt; 1,
    FIELD_SEP_COMMA =&gt; 2,
    FIELD_SEP_LINE =&gt; 4,
};

# The canonical list of fields.

# Note that fields used only in dpkg's available file are not listed.
# Deprecated fields of dpkg's status file are also not listed.
our %FIELDS = (
    'acquire-by-hash' =&gt; {
        name =&gt; 'Acquire-By-Hash',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'architecture' =&gt; {
        name =&gt; 'Architecture',
        allowed =&gt; (ALL_PKG | ALL_SRC | ALL_FILE_MANIFEST | CTRL_TESTS) &amp; (~CTRL_TMPL_SRC),
        separator =&gt; FIELD_SEP_SPACE,
    },
    'architectures' =&gt; {
        name =&gt; 'Architectures',
        allowed =&gt; CTRL_REPO_RELEASE,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'auto-built-package' =&gt; {
        name =&gt; 'Auto-Built-Package',
        allowed =&gt; ALL_PKG &amp; ~CTRL_TMPL_PKG,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'binary' =&gt; {
        name =&gt; 'Binary',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
        # XXX: This field values are separated either by space or comma
        # depending on the context.
        separator =&gt; FIELD_SEP_SPACE | FIELD_SEP_COMMA,
    },
    'binary-only' =&gt; {
        name =&gt; 'Binary-Only',
        allowed =&gt; ALL_CHANGES,
    },
    'binary-only-changes' =&gt; {
        name =&gt; 'Binary-Only-Changes',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'breaks' =&gt; {
        name =&gt; 'Breaks',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 7,
    },
    'bugs' =&gt; {
        name =&gt; 'Bugs',
        allowed =&gt; (ALL_PKG | CTRL_TMPL_SRC | CTRL_FILE_VENDOR) &amp; (~CTRL_TMPL_PKG),
    },
    'build-architecture' =&gt; {
        name =&gt; 'Build-Architecture',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'build-conflicts' =&gt; {
        name =&gt; 'Build-Conflicts',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 4,
    },
    'build-conflicts-arch' =&gt; {
        name =&gt; 'Build-Conflicts-Arch',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 5,
    },
    'build-conflicts-indep' =&gt; {
        name =&gt; 'Build-Conflicts-Indep',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 6,
    },
    'build-date' =&gt; {
        name =&gt; 'Build-Date',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'build-depends' =&gt; {
        name =&gt; 'Build-Depends',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 1,
    },
    'build-depends-arch' =&gt; {
        name =&gt; 'Build-Depends-Arch',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 2,
    },
    'build-depends-indep' =&gt; {
        name =&gt; 'Build-Depends-Indep',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 3,
    },
    'build-essential' =&gt; {
        name =&gt; 'Build-Essential',
        allowed =&gt; ALL_PKG,
    },
    'build-kernel-version' =&gt; {
        name =&gt; 'Build-Kernel-Version',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'build-origin' =&gt; {
        name =&gt; 'Build-Origin',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'build-path' =&gt; {
        name =&gt; 'Build-Path',
        allowed =&gt; CTRL_FILE_BUILDINFO,
    },
    'build-profiles' =&gt; {
        name =&gt; 'Build-Profiles',
        allowed =&gt; CTRL_TMPL_PKG,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'build-tainted-by' =&gt; {
        name =&gt; 'Build-Tainted-By',
        allowed =&gt; CTRL_FILE_BUILDINFO,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'built-for-profiles' =&gt; {
        name =&gt; 'Built-For-Profiles',
        allowed =&gt; ALL_PKG | CTRL_FILE_CHANGES,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'built-using' =&gt; {
        name =&gt; 'Built-Using',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 10,
    },
    'butautomaticupgrades' =&gt; {
        name =&gt; 'ButAutomaticUpgrades',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'changed-by' =&gt; {
        name =&gt; 'Changed-By',
        allowed =&gt; CTRL_FILE_CHANGES,
    },
    'changelogs' =&gt; {
        name =&gt; 'Changelogs',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'changes' =&gt; {
        name =&gt; 'Changes',
        allowed =&gt; ALL_CHANGES,
    },
    'checksums-md5' =&gt; {
        name =&gt; 'Checksums-Md5',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
    },
    'checksums-sha1' =&gt; {
        name =&gt; 'Checksums-Sha1',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
    },
    'checksums-sha256' =&gt; {
        name =&gt; 'Checksums-Sha256',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
    },
    'classes' =&gt; {
        name =&gt; 'Classes',
        allowed =&gt; CTRL_TESTS,
        separator =&gt; FIELD_SEP_COMMA,
    },
    'closes' =&gt; {
        name =&gt; 'Closes',
        allowed =&gt; ALL_CHANGES,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'codename' =&gt; {
        name =&gt; 'Codename',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'comment' =&gt; {
        name =&gt; 'Comment',
        allowed =&gt; ALL_COPYRIGHT,
    },
    'components' =&gt; {
        name =&gt; 'Components',
        allowed =&gt; CTRL_REPO_RELEASE,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'conffiles' =&gt; {
        name =&gt; 'Conffiles',
        allowed =&gt; CTRL_FILE_STATUS,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'config-version' =&gt; {
        name =&gt; 'Config-Version',
        allowed =&gt; CTRL_FILE_STATUS,
    },
    'conflicts' =&gt; {
        name =&gt; 'Conflicts',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 6,
    },
    'copyright' =&gt; {
        name =&gt; 'Copyright',
        allowed =&gt; CTRL_COPYRIGHT_HEADER | CTRL_COPYRIGHT_FILES,
    },
    'date' =&gt; {
        name =&gt; 'Date',
        allowed =&gt; ALL_CHANGES | CTRL_REPO_RELEASE,
    },
    'depends' =&gt; {
        name =&gt; 'Depends',
        allowed =&gt; ALL_PKG | CTRL_TESTS,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 2,
    },
    'description' =&gt; {
        name =&gt; 'Description',
        allowed =&gt; ALL_SRC | ALL_PKG | CTRL_FILE_CHANGES | CTRL_REPO_RELEASE,
    },
    'disclaimer' =&gt; {
        name =&gt; 'Disclaimer',
        allowed =&gt; CTRL_COPYRIGHT_HEADER,
    },
    'directory' =&gt; {
        name =&gt; 'Directory',
        allowed =&gt; CTRL_REPO_SRC,
    },
    'distribution' =&gt; {
        name =&gt; 'Distribution',
        allowed =&gt; ALL_CHANGES,
    },
    'enhances' =&gt; {
        name =&gt; 'Enhances',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 5,
    },
    'environment' =&gt; {
        name =&gt; 'Environment',
        allowed =&gt; CTRL_FILE_BUILDINFO,
        separator =&gt; FIELD_SEP_LINE,
    },
    'essential' =&gt; {
        name =&gt; 'Essential',
        allowed =&gt; ALL_PKG,
    },
    'features' =&gt; {
        name =&gt; 'Features',
        allowed =&gt; CTRL_TESTS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'filename' =&gt; {
        name =&gt; 'Filename',
        allowed =&gt; CTRL_REPO_PKG,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'files' =&gt; {
        name =&gt; 'Files',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | CTRL_FILE_CHANGES | CTRL_COPYRIGHT_FILES,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'format' =&gt; {
        name =&gt; 'Format',
        allowed =&gt; CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST | CTRL_COPYRIGHT_HEADER,
    },
    'homepage' =&gt; {
        name =&gt; 'Homepage',
        allowed =&gt; ALL_SRC | ALL_PKG,
    },
    'installed-build-depends' =&gt; {
        name =&gt; 'Installed-Build-Depends',
        allowed =&gt; CTRL_FILE_BUILDINFO,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 12,
    },
    'installed-size' =&gt; {
        name =&gt; 'Installed-Size',
        allowed =&gt; ALL_PKG &amp; ~CTRL_TMPL_PKG,
    },
    'installer-menu-item' =&gt; {
        name =&gt; 'Installer-Menu-Item',
        allowed =&gt; ALL_PKG,
    },
    'kernel-version' =&gt; {
        name =&gt; 'Kernel-Version',
        allowed =&gt; ALL_PKG,
    },
    'label' =&gt; {
        name =&gt; 'Label',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'license' =&gt; {
        name =&gt; 'License',
        allowed =&gt; ALL_COPYRIGHT,
    },
    'origin' =&gt; {
        name =&gt; 'Origin',
        allowed =&gt; (ALL_PKG | ALL_SRC | CTRL_REPO_RELEASE) &amp; (~CTRL_TMPL_PKG),
    },
    'maintainer' =&gt; {
        name =&gt; 'Maintainer',
        allowed =&gt; CTRL_DEB | CTRL_REPO_PKG | CTRL_FILE_STATUS | ALL_SRC  | ALL_CHANGES,
    },
    'md5sum' =&gt; {
        # XXX: Wrong capitalization due to historical reasons.
        name =&gt; 'MD5sum',
        allowed =&gt; CTRL_REPO_PKG | CTRL_REPO_RELEASE,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'multi-arch' =&gt; {
        name =&gt; 'Multi-Arch',
        allowed =&gt; ALL_PKG,
    },
    'no-support-for-architecture-all' =&gt; {
        name =&gt; 'No-Support-for-Architecture-all',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'notautomatic' =&gt; {
        name =&gt; 'NotAutomatic',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'package' =&gt; {
        name =&gt; 'Package',
        allowed =&gt; ALL_PKG | CTRL_REPO_SRC,
    },
    'package-list' =&gt; {
        name =&gt; 'Package-List',
        allowed =&gt; ALL_SRC &amp; ~CTRL_TMPL_SRC,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'package-type' =&gt; {
        name =&gt; 'Package-Type',
        allowed =&gt; ALL_PKG,
    },
    'parent' =&gt; {
        name =&gt; 'Parent',
        allowed =&gt; CTRL_FILE_VENDOR,
    },
    'pre-depends' =&gt; {
        name =&gt; 'Pre-Depends',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 1,
    },
    'priority' =&gt; {
        name =&gt; 'Priority',
        allowed =&gt; CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
    },
    'protected' =&gt; {
        name =&gt; 'Protected',
        allowed =&gt; ALL_PKG,
    },
    'provides' =&gt; {
        name =&gt; 'Provides',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 9,
    },
    'recommends' =&gt; {
        name =&gt; 'Recommends',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 3,
    },
    'replaces' =&gt; {
        name =&gt; 'Replaces',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 8,
    },
    'restrictions' =&gt; {
        name =&gt; 'Restrictions',
        allowed =&gt; CTRL_TESTS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'rules-requires-root' =&gt; {
        name =&gt; 'Rules-Requires-Root',
        allowed =&gt; CTRL_TMPL_SRC,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'section' =&gt; {
        name =&gt; 'Section',
        allowed =&gt; CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
    },
    'sha1' =&gt; {
        # XXX: Wrong capitalization due to historical reasons.
        name =&gt; 'SHA1',
        allowed =&gt; CTRL_REPO_PKG | CTRL_REPO_RELEASE,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'sha256' =&gt; {
        # XXX: Wrong capitalization due to historical reasons.
        name =&gt; 'SHA256',
        allowed =&gt; CTRL_REPO_PKG | CTRL_REPO_RELEASE,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'size' =&gt; {
        name =&gt; 'Size',
        allowed =&gt; CTRL_REPO_PKG,
        separator =&gt; FIELD_SEP_LINE | FIELD_SEP_SPACE,
    },
    'source' =&gt; {
        name =&gt; 'Source',
        allowed =&gt; (ALL_PKG | ALL_SRC | ALL_CHANGES | CTRL_COPYRIGHT_HEADER | CTRL_FILE_BUILDINFO) &amp;
                   (~(CTRL_REPO_SRC | CTRL_TMPL_PKG)),
    },
    'standards-version' =&gt; {
        name =&gt; 'Standards-Version',
        allowed =&gt; ALL_SRC,
    },
    'static-built-using' =&gt; {
        name =&gt; 'Static-Built-Using',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'union',
        dep_order =&gt; 11,
    },
    'status' =&gt; {
        name =&gt; 'Status',
        allowed =&gt; CTRL_FILE_STATUS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'subarchitecture' =&gt; {
        name =&gt; 'Subarchitecture',
        allowed =&gt; ALL_PKG,
    },
    'suite' =&gt; {
        name =&gt; 'Suite',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'suggests' =&gt; {
        name =&gt; 'Suggests',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
        dependency =&gt; 'normal',
        dep_order =&gt; 4,
    },
    'tag' =&gt; {
        name =&gt; 'Tag',
        allowed =&gt; ALL_PKG,
        separator =&gt; FIELD_SEP_COMMA,
    },
    'task' =&gt; {
        name =&gt; 'Task',
        allowed =&gt; ALL_PKG,
    },
    'test-command' =&gt; {
        name =&gt; 'Test-Command',
        allowed =&gt; CTRL_TESTS,
    },
    'tests' =&gt; {
        name =&gt; 'Tests',
        allowed =&gt; CTRL_TESTS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'tests-directory' =&gt; {
        name =&gt; 'Tests-Directory',
        allowed =&gt; CTRL_TESTS,
    },
    'testsuite' =&gt; {
        name =&gt; 'Testsuite',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
    },
    'testsuite-triggers' =&gt; {
        name =&gt; 'Testsuite-Triggers',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
    },
    'timestamp' =&gt; {
        name =&gt; 'Timestamp',
        allowed =&gt; CTRL_CHANGELOG,
    },
    'triggers-awaited' =&gt; {
        name =&gt; 'Triggers-Awaited',
        allowed =&gt; CTRL_FILE_STATUS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'triggers-pending' =&gt; {
        name =&gt; 'Triggers-Pending',
        allowed =&gt; CTRL_FILE_STATUS,
        separator =&gt; FIELD_SEP_SPACE,
    },
    'uploaders' =&gt; {
        name =&gt; 'Uploaders',
        allowed =&gt; ALL_SRC,
        separator =&gt; FIELD_SEP_COMMA,
    },
    'upstream-name' =&gt; {
        name =&gt; 'Upstream-Name',
        allowed =&gt; CTRL_COPYRIGHT_HEADER,
    },
    'upstream-contact' =&gt; {
        name =&gt; 'Upstream-Contact',
        allowed =&gt; CTRL_COPYRIGHT_HEADER,
    },
    'urgency' =&gt; {
        name =&gt; 'Urgency',
        allowed =&gt; ALL_CHANGES,
    },
    'valid-until' =&gt; {
        name =&gt; 'Valid-Until',
        allowed =&gt; CTRL_REPO_RELEASE,
    },
    'vcs-browser' =&gt; {
        name =&gt; 'Vcs-Browser',
        allowed =&gt; ALL_SRC,
    },
    'vcs-arch' =&gt; {
        name =&gt; 'Vcs-Arch',
        allowed =&gt; ALL_SRC,
    },
    'vcs-bzr' =&gt; {
        name =&gt; 'Vcs-Bzr',
        allowed =&gt; ALL_SRC,
    },
    'vcs-cvs' =&gt; {
        name =&gt; 'Vcs-Cvs',
        allowed =&gt; ALL_SRC,
    },
    'vcs-darcs' =&gt; {
        name =&gt; 'Vcs-Darcs',
        allowed =&gt; ALL_SRC,
    },
    'vcs-git' =&gt; {
        name =&gt; 'Vcs-Git',
        allowed =&gt; ALL_SRC,
    },
    'vcs-hg' =&gt; {
        name =&gt; 'Vcs-Hg',
        allowed =&gt; ALL_SRC,
    },
    'vcs-mtn' =&gt; {
        name =&gt; 'Vcs-Mtn',
        allowed =&gt; ALL_SRC,
    },
    'vcs-svn' =&gt; {
        name =&gt; 'Vcs-Svn',
        allowed =&gt; ALL_SRC,
    },
    'vendor' =&gt; {
        name =&gt; 'Vendor',
        allowed =&gt; CTRL_FILE_VENDOR,
    },
    'vendor-url' =&gt; {
        name =&gt; 'Vendor-Url',
        allowed =&gt; CTRL_FILE_VENDOR,
    },
    'version' =&gt; {
        name =&gt; 'Version',
        allowed =&gt; (ALL_PKG | ALL_SRC | CTRL_FILE_BUILDINFO | ALL_CHANGES | CTRL_REPO_RELEASE) &amp;
                    (~(CTRL_TMPL_SRC | CTRL_TMPL_PKG)),
    },
);

my @src_vcs_fields = qw(
    vcs-browser
    vcs-arch
    vcs-bzr
    vcs-cvs
    vcs-darcs
    vcs-git
    vcs-hg
    vcs-mtn
    vcs-svn
);

my @src_dep_fields = qw(
    build-depends
    build-depends-arch
    build-depends-indep
    build-conflicts
    build-conflicts-arch
    build-conflicts-indep
);
my @bin_dep_fields = qw(
    pre-depends
    depends
    recommends
    suggests
    enhances
    conflicts
    breaks
    replaces
    provides
    built-using
    static-built-using
);

my @src_test_fields = qw(
    testsuite
    testsuite-triggers
);

my @src_checksums_fields = qw(
    checksums-md5
    checksums-sha1
    checksums-sha256
);
my @bin_checksums_fields = qw(
    md5sum
    sha1
    sha256
);

our %FIELD_ORDER = (
    CTRL_TMPL_SRC() =&gt; [
        qw(
            source
            section
            priority
            maintainer
            uploaders
            origin
            bugs
        ),
        @src_vcs_fields,
        qw(
            homepage
            standards-version
            rules-requires-root
        ),
        @src_dep_fields,
        @src_test_fields,
        qw(
            description
        ),
    ],
    CTRL_TMPL_PKG() =&gt; [
        qw(
            package
            package-type
            section
            priority
            architecture
            subarchitecture
            multi-arch
            essential
            protected
            build-essential
            build-profiles
            built-for-profiles
            kernel-version
        ),
        @bin_dep_fields,
        qw(
            homepage
            installer-menu-item
            task
            tag
            description
        ),
    ],
    CTRL_DSC() =&gt; [
        qw(
            format
            source
            binary
            architecture
            version
            origin
            maintainer
            uploaders
            homepage
            description
            standards-version
        ),
        @src_vcs_fields,
        @src_test_fields,
        @src_dep_fields,
        qw(
            package-list
        ),
        @src_checksums_fields,
        qw(
            files
        ),
    ],
    CTRL_DEB() =&gt; [
        qw(
            package
            package-type
            source
            version
            kernel-version
            built-for-profiles
            auto-built-package
            architecture
            subarchitecture
            installer-menu-item
            build-essential
            essential
            protected
            origin
            bugs
            maintainer
            installed-size
        ),
        @bin_dep_fields,
        qw(
            section
            priority
            multi-arch
            homepage
            description
            tag
            task
        ),
    ],
    CTRL_REPO_SRC() =&gt; [
        qw(
            format
            package
            binary
            architecture
            version
            priority
            section
            origin
            maintainer
            uploaders
            homepage
            description
            standards-version
        ),
        @src_vcs_fields,
        @src_test_fields,
        @src_dep_fields,
        qw(
            package-list
            directory
        ),
        @src_checksums_fields,
        qw(
            files
        ),
    ],
    CTRL_REPO_PKG() =&gt; [
        qw(
            package
            package-type
            source
            version
            kernel-version
            built-for-profiles
            auto-built-package
            architecture
            subarchitecture
            installer-menu-item
            build-essential
            essential
            protected
            origin
            bugs
            maintainer
            installed-size
        ),
        @bin_dep_fields,
        qw(
            filename
            size
        ),
        @bin_checksums_fields,
        qw(
            section
            priority
            multi-arch
            homepage
            description
            tag
            task
        ),
    ],
    CTRL_REPO_RELEASE() =&gt; [
        qw(
            origin
            label
            suite
            version
            codename
            changelogs
            date
            valid-until
            notautomatic
            butautomaticupgrades
            acquire-by-hash
            no-support-for-architecture-all
            architectures
            components
            description
        ),
        @bin_checksums_fields
    ],
    CTRL_CHANGELOG() =&gt; [
        qw(
            source
            binary-only
            version
            distribution
            urgency
            maintainer
            timestamp
            date
            closes
            changes
        ),
    ],
    CTRL_COPYRIGHT_HEADER() =&gt; [
        qw(
            format
            upstream-name
            upstream-contact
            source
            disclaimer
            comment
            license
            copyright
        ),
    ],
    CTRL_COPYRIGHT_FILES() =&gt; [
        qw(
            files
            copyright
            license
            comment
        ),
    ],
    CTRL_COPYRIGHT_LICENSE() =&gt; [
        qw(
            license
            comment
        ),
    ],
    CTRL_FILE_BUILDINFO() =&gt; [
        qw(
            format
            source
            binary
            architecture
            version
            binary-only-changes
        ),
        @src_checksums_fields,
        qw(
            build-origin
            build-architecture
            build-kernel-version
            build-date
            build-path
            build-tainted-by
            installed-build-depends
            environment
        ),
    ],
    CTRL_FILE_CHANGES() =&gt; [
        qw(
            format
            date
            source
            binary
            binary-only
            built-for-profiles
            architecture
            version
            distribution
            urgency
            maintainer
            changed-by
            description
            closes
            changes
        ),
        @src_checksums_fields,
        qw(
            files
        ),
    ],
    CTRL_FILE_VENDOR() =&gt; [
        qw(
            vendor
            vendor-url
            bugs
            parent
        ),
    ],
    CTRL_FILE_STATUS() =&gt; [
        # Same as fieldinfos in lib/dpkg/parse.c
        qw(
            package
            essential
            protected
            status
            priority
            section
            installed-size
            origin
            maintainer
            bugs
            architecture
            multi-arch
            source
            version
            config-version
            replaces
            provides
            depends
            pre-depends
            recommends
            suggests
            breaks
            conflicts
            enhances
            conffiles
            description
            triggers-pending
            triggers-awaited
        ),
        # These are allowed here, but not tracked by lib/dpkg/parse.c.
        qw(
            auto-built-package
            build-essential
            built-for-profiles
            built-using
            static-built-using
            homepage
            installer-menu-item
            kernel-version
            package-type
            subarchitecture
            tag
            task
        ),
    ],
    CTRL_TESTS() =&gt; [
        qw(
            test-command
            tests
            tests-directory
            architecture
            restrictions
            features
            classes
            depends
        ),
    ],
);

=head1 FUNCTIONS

=over 4

=item $f = field_capitalize($field_name)

Returns the field name properly capitalized. All characters are lowercase,
except the first of each word (words are separated by a hyphen in field names).

=cut

sub field_capitalize($) {
    my $field = lc(shift);

    # Use known fields first.
    return $FIELDS{$field}{name} if exists $FIELDS{$field};

    # Generic case
    return join '-', map { ucfirst } split /-/, $field;
}

=item $bool = field_is_official($fname)

Returns true if the field is official and known.

=cut

sub field_is_official($) {
    my $field = lc shift;

    return exists $FIELDS{$field};
}

=item $bool = field_is_allowed_in($fname, @types)

Returns true (1) if the field $fname is allowed in all the types listed in
the list. Note that you can use type sets instead of individual types (ex:
CTRL_FILE_CHANGES | CTRL_CHANGELOG).

field_allowed_in(A|B, C) returns true only if the field is allowed in C
and either A or B.

Undef is returned for non-official fields.

=cut

sub field_is_allowed_in($@) {
    my ($field, @types) = @_;
    $field = lc $field;

    return unless exists $FIELDS{$field};

    return 0 if not scalar(@types);
    foreach my $type (@types) {
        next if $type == CTRL_UNKNOWN; # Always allowed
        return 0 unless $FIELDS{$field}{allowed} &amp; $type;
    }
    return 1;
}

=item $new_field = field_transfer_single($from, $to, $field)

If appropriate, copy the value of the field named $field taken from the
$from L&lt;Dpkg::Control&gt; object to the $to L&lt;Dpkg::Control&gt; object.

Official fields are copied only if the field is allowed in both types of
objects. Custom fields are treated in a specific manner. When the target
is not among CTRL_DSC, CTRL_DEB or CTRL_FILE_CHANGES, then they
are always copied as is (the X- prefix is kept). Otherwise they are not
copied except if the target object matches the target destination encoded
in the field name. The initial X denoting custom fields can be followed by
one or more letters among "S" (Source: corresponds to CTRL_DSC), "B"
(Binary: corresponds to CTRL_DEB) or "C" (Changes: corresponds to
CTRL_FILE_CHANGES).

Returns undef if nothing has been copied or the name of the new field
added to $to otherwise.

=cut

sub field_transfer_single($$;$) {
    my ($from, $to, $field) = @_;
    if (not defined $field) {
        warnings::warnif('deprecated',
            'using Dpkg::Control::Fields::field_transfer_single() with an ' .
            'an implicit field argument is deprecated');
        $field = $_;
    }
    my ($from_type, $to_type) = ($from-&gt;get_type(), $to-&gt;get_type());
    $field = field_capitalize($field);

    if (field_is_allowed_in($field, $from_type, $to_type)) {
        $to-&gt;{$field} = $from-&gt;{$field};
        return $field;
    } elsif ($field =~ /^X([SBC]*)-/i) {
        my $dest = $1;
        if (($dest =~ /B/i and $to_type == CTRL_DEB) or
            ($dest =~ /S/i and $to_type == CTRL_DSC) or
            ($dest =~ /C/i and $to_type == CTRL_FILE_CHANGES))
        {
            my $new = $field;
            $new =~ s/^X([SBC]*)-//i;
            $to-&gt;{$new} = $from-&gt;{$field};
            return $new;
        } elsif ($to_type != CTRL_DEB and
		 $to_type != CTRL_DSC and
		 $to_type != CTRL_FILE_CHANGES)
	{
	    $to-&gt;{$field} = $from-&gt;{$field};
	    return $field;
	}
    } elsif (not field_is_allowed_in($field, $from_type)) {
        warning(g_("unknown information field '%s' in input data in %s"),
                $field, $from-&gt;get_option('name') || g_('control information'));
    }
    return;
}

=item @field_list = field_transfer_all($from, $to)

Transfer all appropriate fields from $from to $to. Calls
field_transfer_single() on all fields available in $from.

Returns the list of fields that have been added to $to.

=cut

sub field_transfer_all($$) {
    my ($from, $to) = @_;
    my (@res, $res);
    foreach my $k (keys %$from) {
        $res = field_transfer_single($from, $to, $k);
        push @res, $res if $res and defined wantarray;
    }
    return @res;
}

=item @field_list = field_ordered_list($type)

Returns an ordered list of fields for a given type of control information.
This list can be used to output the fields in a predictable order.
The list might be empty for types where the order does not matter much.

=cut

sub field_ordered_list($) {
    my $type = shift;

    if (exists $FIELD_ORDER{$type}) {
        return map { $FIELDS{$_}{name} } @{$FIELD_ORDER{$type}};
    }
    return ();
}

=item ($source, $version) = field_parse_binary_source($ctrl)

Parse the B&lt;Source&gt; field in a binary package control stanza. The field
contains the source package name where it was built from, and optionally
a space and the source version enclosed in parenthesis if it is different
from the binary version.

Returns a list with the $source name, and the source $version, or undef
or an empty list when $ctrl does not contain a binary package control stanza.
Neither $source nor $version are validated, but that can be done with
Dpkg::Package::pkg_name_is_illegal() and Dpkg::Version::version_check().

=cut

sub field_parse_binary_source($) {
    my $ctrl = shift;
    my $ctrl_type = $ctrl-&gt;get_type();

    if ($ctrl_type != CTRL_REPO_PKG and
        $ctrl_type != CTRL_DEB and
        $ctrl_type != CTRL_FILE_CHANGES and
        $ctrl_type != CTRL_FILE_BUILDINFO and
        $ctrl_type != CTRL_FILE_STATUS) {
        return;
    }

    my ($source, $version);

    # For .changes and .buildinfo the Source field always exists,
    # and there is no Package field.
    if (exists $ctrl-&gt;{'Source'}) {
        $source = $ctrl-&gt;{'Source'};
        if ($source =~ m/^([^ ]+) +\(([^)]*)\)$/) {
            $source = $1;
            $version = $2;
        } else {
            $version = $ctrl-&gt;{'Version'};
        }
    } else {
        $source = $ctrl-&gt;{'Package'};
        $version = $ctrl-&gt;{'Version'};
    }

    return ($source, $version);
}

=item @field_list = field_list_src_dep()

List of fields that contains dependencies-like information in a source
Debian package.

=cut

sub field_list_src_dep() {
    my @list = map {
        $FIELDS{$_}{name}
    } sort {
        $FIELDS{$a}{dep_order} &lt;=&gt; $FIELDS{$b}{dep_order}
    } grep {
        field_is_allowed_in($_, CTRL_DSC) and
        exists $FIELDS{$_}{dependency}
    } keys %FIELDS;
    return @list;
}

=item @field_list = field_list_pkg_dep()

List of fields that contains dependencies-like information in a binary
Debian package. The fields that express real dependencies are sorted from
the stronger to the weaker.

=cut

sub field_list_pkg_dep() {
    my @list = map {
        $FIELDS{$_}{name}
    } sort {
        $FIELDS{$a}{dep_order} &lt;=&gt; $FIELDS{$b}{dep_order}
    } grep {
        field_is_allowed_in($_, CTRL_DEB) and
        exists $FIELDS{$_}{dependency}
    } keys %FIELDS;
    return @list;
}

=item $dep_type = field_get_dep_type($field)

Return the type of the dependency expressed by the given field. Can
either be "normal" for a real dependency field (Pre-Depends, Depends, ...)
or "union" for other relation fields sharing the same syntax (Conflicts,
Breaks, ...). Returns undef for fields which are not dependencies.

=cut

sub field_get_dep_type($) {
    my $field = lc shift;

    return unless exists $FIELDS{$field};
    return $FIELDS{$field}{dependency} if exists $FIELDS{$field}{dependency};
    return;
}

=item $sep_type = field_get_sep_type($field)

Return the type of the field value separator. Can be one of FIELD_SEP_UNKNOWN,
FIELD_SEP_SPACE, FIELD_SEP_COMMA or FIELD_SEP_LINE.

=cut

sub field_get_sep_type($) {
    my $field = lc shift;

    return $FIELDS{$field}{separator} if exists $FIELDS{$field}{separator};
    return FIELD_SEP_UNKNOWN;
}

=item field_register($field, $allowed_types, %opts)

Register a new field as being allowed in control information of specified
types. %opts is optional.

=cut

sub field_register($$;@) {
    my ($field, $types, %opts) = @_;

    $field = lc $field;
    $FIELDS{$field} = {
        name =&gt; field_capitalize($field),
        allowed =&gt; $types,
        %opts
    };

    return;
}

=item $bool = field_insert_after($type, $ref, @fields)

Place field after another one ($ref) in output of control information of
type $type.

Return true if the field was inserted, otherwise false.

=cut

sub field_insert_after($$@) {
    my ($type, $field, @fields) = @_;

    return 0 if not exists $FIELD_ORDER{$type};

    ($field, @fields) = map { lc } ($field, @fields);
    @{$FIELD_ORDER{$type}} = map {
        ($_ eq $field) ? ($_, @fields) : $_
    } @{$FIELD_ORDER{$type}};

    return 1;
}

=item $bool = field_insert_before($type, $ref, @fields)

Place field before another one ($ref) in output of control information of
type $type.

Return true if the field was inserted, otherwise false.

=cut

sub field_insert_before($$@) {
    my ($type, $field, @fields) = @_;

    return 0 if not exists $FIELD_ORDER{$type};

    ($field, @fields) = map { lc } ($field, @fields);
    @{$FIELD_ORDER{$type}} = map {
        ($_ eq $field) ? (@fields, $_) : $_
    } @{$FIELD_ORDER{$type}};

    return 1;
}

=back

=head1 CHANGES

=head2 Version 1.02 (dpkg 1.22.0)

Deprecate argument: field_transfer_single() implicit argument usage.

=head2 Version 1.01 (dpkg 1.21.0)

New function: field_parse_binary_source().

=head2 Version 1.00 (dpkg 1.17.0)

Mark the module as public.

=cut

1;
</pre></body></html>