line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
DPKG::Parse - Parse various dpkg files into Perl Objects |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use DPKG::Parse::Status; |
8
|
|
|
|
|
|
|
my $status = DPKG::Parse::Status->new; |
9
|
|
|
|
|
|
|
while (my $entry = $status->next_package) { |
10
|
|
|
|
|
|
|
print $entry->package . " " . $entry->version . "\n"; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use DPKG::Parse::Available; |
14
|
|
|
|
|
|
|
my $available = DPKG::Parse::Available->new; |
15
|
|
|
|
|
|
|
while (my $entry = $available->next_package) { |
16
|
|
|
|
|
|
|
print $entry->package . " " . $entry->version . "\n"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
DPKG::Parse contains utilities to parse the various files created by |
22
|
|
|
|
|
|
|
dpkg and turn them into helpful Perl objects. Current files understood |
23
|
|
|
|
|
|
|
by various DPKG::Parse modules: |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
/var/lib/dpkg/status - DPKG::Parse::Status |
26
|
|
|
|
|
|
|
/var/lib/dpkg/available - DPKG::Parse::Available |
27
|
|
|
|
|
|
|
Packages.gz - DPKG::Parse::Packages |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
See each module's documentation for particulars - You should not be calling |
30
|
|
|
|
|
|
|
DPKG::Parse directly. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
package DPKG::Parse; # git description: v0.02-2-gca4c3e9 |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
4
|
|
27
|
use Params::Validate qw(:all); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
731
|
|
41
|
4
|
|
|
4
|
|
799
|
use DPKG::Parse::Entry; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
23
|
|
42
|
4
|
|
|
4
|
|
122
|
use Class::C3; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
17
|
|
43
|
4
|
|
|
4
|
|
115
|
use base qw(Class::Accessor); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
327
|
|
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
4
|
|
18
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
105
|
|
46
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1907
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
DPKG::Parse->mk_accessors(qw(filename entryarray entryhash)); |
49
|
|
|
|
|
|
|
DPKG::Parse->mk_ro_accessors('debug'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item filename($filename) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
A simple accessor for the file currently being parsed. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item entryarray |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Access to the raw array of entries in a given file. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item entryhash |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Access to the raw hash of entries. The key is determined by the module, |
64
|
|
|
|
|
|
|
but is usually the Package name. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item new('filename' => '/var/lib/dpkg/status'); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
A generic new function; takes a filename and calls the filename() accessor |
69
|
|
|
|
|
|
|
with it. Should not be called directly, but through on of the children of |
70
|
|
|
|
|
|
|
this package. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
sub new { |
74
|
6
|
|
|
6
|
1
|
131
|
my $pkg = shift; |
75
|
6
|
|
|
|
|
104
|
my %p = validate(@_, |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
'filename' => { 'type' => SCALAR, }, |
78
|
|
|
|
|
|
|
'debug' => { 'type' => SCALAR, 'default' => 0, 'optional' => 1 } |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
6
|
|
|
|
|
27
|
my $ref = {}; |
82
|
6
|
50
|
|
|
|
21
|
if ($p{'filename'}) { |
83
|
6
|
|
|
|
|
13
|
$ref->{'filename'} = $p{'filename'}; |
84
|
|
|
|
|
|
|
}; |
85
|
6
|
|
|
|
|
10
|
$ref->{debug} = $p{debug}; |
86
|
6
|
|
|
|
|
12
|
$ref->{'entryarray'} = []; |
87
|
6
|
|
|
|
|
11
|
$ref->{'entryhash'} = {}; |
88
|
6
|
|
|
|
|
13
|
bless($ref, $pkg); |
89
|
6
|
|
|
|
|
25
|
return $ref; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item parse |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
A default parse function; simply calls parse_package_format. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
sub parse { |
98
|
3
|
|
|
3
|
1
|
30
|
my $pkg = shift; |
99
|
3
|
|
|
|
|
19
|
$pkg->parse_package_format; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item parse_package_format |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Takes a file in a format similar to the dpkg "available" file, and creates |
105
|
|
|
|
|
|
|
L objects from each entry. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
sub parse_package_format { |
109
|
3
|
|
|
3
|
1
|
7
|
my $pkg = shift; |
110
|
3
|
50
|
|
|
|
27
|
if (! -f $pkg->filename) { |
111
|
0
|
|
|
|
|
0
|
die "Cannot find " . $pkg->filename . ", or it's not a file at all!"; |
112
|
|
|
|
|
|
|
} |
113
|
3
|
|
|
|
|
168
|
open(STATUS, $pkg->filename); |
114
|
3
|
|
|
|
|
113
|
my $entry; |
115
|
3
|
|
|
|
|
7
|
my $line_num = -1; |
116
|
3
|
|
|
|
|
5
|
my $entry_line = 0; |
117
|
3
|
|
|
|
|
100
|
STATUSLINE: while (my $line = ) { |
118
|
162
|
|
|
|
|
117
|
++$line_num; |
119
|
162
|
100
|
|
|
|
297
|
if ($line =~ /^\n$/) { |
120
|
10
|
|
|
|
|
52
|
my $dpkg_entry = DPKG::Parse::Entry->new('data' => $entry, debug => $pkg->debug, line_num => $entry_line); |
121
|
10
|
|
|
|
|
18
|
push(@{$pkg->{'entryarray'}}, $dpkg_entry); |
|
10
|
|
|
|
|
25
|
|
122
|
10
|
|
|
|
|
29
|
$pkg->{'entryhash'}->{$dpkg_entry->package} = $dpkg_entry; |
123
|
10
|
|
|
|
|
87
|
$entry = undef; |
124
|
10
|
|
|
|
|
14
|
$entry_line = $line_num + 1; |
125
|
10
|
|
|
|
|
74
|
next STATUSLINE; |
126
|
|
|
|
|
|
|
} |
127
|
152
|
|
|
|
|
322
|
$entry = $entry . $line; |
128
|
|
|
|
|
|
|
} |
129
|
3
|
|
|
|
|
39
|
close(STATUS); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item get_package('name' => 'postfix', 'hash' => 'entryhash'); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The value of a hash, if it exists. By default, it uses the value returned |
135
|
|
|
|
|
|
|
by the "entryhash" accessor, but that can be overridden with the "hash" |
136
|
|
|
|
|
|
|
parameter. Usually returns a L object. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
sub get_package { |
140
|
6
|
|
|
6
|
1
|
6843
|
my $pkg = shift; |
141
|
6
|
|
|
|
|
139
|
my %p = validate( @_, |
142
|
|
|
|
|
|
|
{ |
143
|
|
|
|
|
|
|
'name' => { 'type' => SCALAR, }, |
144
|
|
|
|
|
|
|
'hash' => { 'type' => SCALAR, 'default' => 'entryhash', }, |
145
|
|
|
|
|
|
|
}, |
146
|
|
|
|
|
|
|
); |
147
|
6
|
50
|
|
|
|
47
|
if (exists($pkg->{$p{'hash'}}->{$p{'name'}})) { |
148
|
6
|
|
|
|
|
30
|
return $pkg->{$p{'hash'}}->{$p{'name'}}; |
149
|
|
|
|
|
|
|
} else { |
150
|
0
|
|
|
|
|
0
|
return undef; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item next_package |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Shifts the next value off the array stored in the entryarray() accessor. |
157
|
|
|
|
|
|
|
If you want to access the raw values, do not use this function! It shifts! |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
sub next_package { |
161
|
13
|
|
|
13
|
1
|
7669
|
my $pkg = shift; |
162
|
13
|
|
|
|
|
16
|
return shift(@{$pkg->{'entryarray'}}); |
|
13
|
|
|
|
|
37
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |