/usr/share/perl5/DPKG/Parse/Entry.pm is in libdpkg-parse-perl 0.03-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | =head1 NAME
DPKG::Parse::Entry - Parse a Package style entry
=head1 SYNOPSIS
use DPKG::Parse::Entry;
my $data = <<EOH;
Package: kernel-image-2.6.12.2
Source: kernel-source-2.6.12.2
Version: wrk01
Priority: optional
Section: base
Maintainer: Jamie Heilman <jamie@marchex.com>
Depends: coreutils | fileutils (>= 4.0)
Suggests: lilo (>= 19.1) | grub, fdutils, kernel-doc-2.6.12.2 | kernel-source-2.6.12.2
Provides: kernel-image, kernel-image-2.6
Architecture: i386
Filename: packages/./kernel-image-2.6.12.2_wrk01_i386.deb
Size: 4293154
Installed-Size: 10312
MD5sum: 2acf846b127b71a1fa1143214b2b85a9
Description: Linux kernel binary image for version 2.6.12.2.
EOH
my $entry = DPKG::Parse::Entry->new('data' => $data);
print $entry->package . " " . $entry->version . "\n";
$entry->package("kernel-foobar");
=head1 DESCRIPTION
L<DPKG::Parse::Entry> parses a dpkg "Package" file entry, creating a new
L<DPKG::Parse::Entry> instance for it. You submit the contents, beginning
with a "Package:" line, as the 'data' argument to new. After that, all
the data is populated as lowercased instance methods. For example, if
we used the above to create an $entry object, we would have:
$entry->package == "kernel-image-2.6.12.2"
$entry->size == 4293154
$entry->md5sum == 2acf846b127b71a1fa1143214b2b85a9
L<DPKG::Parse::Entry> will skip any attribute it does not know about. You
can see what it has skipped by passing a true value to the 'debug' option to
'new()'.
It should know all the attributes present in a Packages, available, and
status file.
See L<DPKG::Parse::Status>, L<DPKG::Parse::Available>, and
L<DPKG::Parse::Packages> for more information on how to easily generate
DPKG::Parse::Entry objects.
=head1 METHODS
=over 4
=cut
package DPKG::Parse::Entry;
our $VERSION = '0.03';
use Params::Validate qw(:all);
use base qw(Class::Accessor);
use Carp;
use strict;
use warnings;
DPKG::Parse::Entry->mk_accessors(qw(
architecture
bugs
build_essential
conflicts
config_version
conffiles
depends
description
enhances
essential
filename
installed_size
maintainer
md5sum
origin
package
priority
provides
pre_depends
recommends
replaces
size
source
section
suggests
status
task
tag
url
version
original_maintainer
homepage
breaks
python_version
multi_arch
gstreamer_decoders
gstreamer_elements
gstreamer_encoders
gstreamer_uri_sources
gstreamer_version
python_runtime
npp_applications
npp_file
npp_mimetype
npp_name
npp_description
python_runtime
gstreamer_uri_sinks
xul_appid
original_vcs_browser
original_vcs_git
));
DPKG::Parse::Entry->mk_ro_accessors(qw(__debug __line_num));
=item Accessor Methods
The following accessor methods correspond directly to the values found in
the parsed Package block, with one exception: "-" characters are replaced
with "_". So, "build-essential" becomes "build_essential".
The accessors are:
architecture
bugs
build_essential
conflicts
config_version
conffiles
depends
description
enhances
essential
filename
installed_size
maintainer
md5sum
origin
package
priority
provides
pre_depends
recommends
replaces
size
source
section
suggests
status
task
tag
url
version
=item new('data' => $data, 'debug' => 1)
Creates a new L<DPKG::Parse::Entry> object. 'data' should be a scalar that
contains the text of a dpkg-style Package entry. If the 'debug' flag is
set, we will Carp about entries we don't have accessors for.
=cut
sub new {
my $pkg = shift;
my %p = validate(@_,
{
'data' => { 'type' => SCALAR, 'optional' => 1 },
'debug' => { 'type' => SCALAR, 'default' => 0, 'optional' => 1 },
'line_num' => { type => SCALAR, default => 0, optional => 1 }
}
);
my $ref = {
__debug => $p{debug},
__line_num => $p{line_num}
};
bless($ref, $pkg);
if ($p{'data'}) {
$ref->parse('data' => $p{'data'});
};
return $ref;
}
=item parse('data' => $data);
Does the actual parsing of the Package block given to new(). Probably
should only be called once per object.
=cut
sub parse {
my $pkg = shift;
my %p = validate(@_,
{
'data' => { 'type' => SCALAR, 'optional' => 1 },
},
);
my $field;
my $contents;
my $line_num = $pkg->__line_num;
foreach my $line (split(/\n/, $p{'data'})) {
++$line_num;
if ($line =~ /^([\w|-]+): (.+)$/) {
$field = $1;
$contents = $2;
$field = lc($field);
$field =~ s/-/_/g;
if ($pkg->can($field)) {
$pkg->$field($contents);
} else {
if ($pkg->__debug) {
carp "line ${line_num}: I don't know about field '${field}'\n";
}
next;
}
} elsif ($line =~ /^ / && $field) {
$line =~ s/^ //g;
$line =~ s/^.$//g;
if ($contents !~ /\n$/) {
$contents = $contents . "\n" . $line . "\n";
} else {
$contents = $contents . $line;
}
if ($pkg->can($field)) {
$pkg->$field($contents);
} else {
if ($pkg->__debug) {
carp "line ${line_num}: I don't know about field '${field}'\n";
}
next;
}
} elsif ($line =~ /^([\w|-]+):\s*$/) {
$field = $1;
$field = lc($field);
$field =~ s/-/_/g;
if ($pkg->can($field)) {
$pkg->$field("");
} else {
if ($pkg->__debug) {
carp "line ${line_num}: I don't know about field '${field}'\n";
}
next;
}
} else {
die "line ${line_num}: I have no idea what to do with '${line}'!\n";
}
}
}
=back
=cut
1;
|