line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
DPKG::Parse::Status - Parse the "status" file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use DPKG::Parse::Status; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $status = DPKG::Parse::Status->new; |
10
|
|
|
|
|
|
|
while (my $entry = $status->next_package) { |
11
|
|
|
|
|
|
|
print $entry->package . " " . $entry->version . "\n"; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $postfix = $status->get_package('name' => 'postfix'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $postfix = $status->get_installed('name' => 'postfix'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
L parses a dpkg "status" file and turns |
21
|
|
|
|
|
|
|
each entry into a L object. By default, it uses |
22
|
|
|
|
|
|
|
the Debian default location of "/var/lib/dpkg/status". |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
See L for more information on the get_package and next_package |
25
|
|
|
|
|
|
|
methods. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
See L for more information on the entry objects. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package DPKG::Parse::Status; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $VERSION = '0.02'; # TRIAL |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
45612
|
use DPKG::Parse::Entry; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
15
|
|
40
|
2
|
|
|
2
|
|
93
|
use Params::Validate qw(:all); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
397
|
|
41
|
2
|
|
|
2
|
|
1084
|
use Class::C3; |
|
2
|
|
|
|
|
4760
|
|
|
2
|
|
|
|
|
30
|
|
42
|
2
|
|
|
2
|
|
80
|
use base qw(DPKG::Parse); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
832
|
|
43
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
44
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
417
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
DPKG::Parse::Status->mk_accessors(qw(installed)); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item new('filename' => '/var/lib/dpkg/status') |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Creates a new DPKG::Parse::Status object. By default, it tries to open |
51
|
|
|
|
|
|
|
/var/lib/dpkg/status. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
sub new { |
55
|
2
|
|
|
2
|
1
|
24
|
my $pkg = shift; |
56
|
2
|
|
|
|
|
133
|
my %p = validate(@_, |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
'filename' => { 'type' => SCALAR, 'default' => '/var/lib/dpkg/status', 'optional' => 1 }, |
59
|
|
|
|
|
|
|
'debug' => { 'type' => SCALAR, 'default' => 0, 'optional' => 1 } |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
2
|
|
|
|
|
27
|
my $ref = $pkg->next::method('filename' => $p{'filename'}, debug => $p{debug}); |
63
|
2
|
|
|
|
|
6
|
return $ref; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item parse |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Calls DPKG::Parse::parse, and populates the "installed" accessor with a hash |
69
|
|
|
|
|
|
|
of packages whose "status" is "install ok installed". |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
sub parse { |
73
|
1
|
|
|
1
|
1
|
5
|
my $pkg = shift; |
74
|
1
|
|
|
|
|
3
|
$pkg->next::method; |
75
|
1
|
|
|
|
|
2
|
my $installed; |
76
|
1
|
|
|
|
|
2
|
foreach my $entry (@{$pkg->entryarray}) { |
|
1
|
|
|
|
|
7
|
|
77
|
4
|
100
|
|
|
|
29
|
if ($entry->status =~ /^install ok installed$/) { |
78
|
1
|
|
|
|
|
9
|
$installed->{$entry->package} = $entry; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
10
|
$pkg->installed($installed); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item get_installed('name' => 'postfix'); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns a L object for the given package, or undef if |
87
|
|
|
|
|
|
|
it's not found. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
sub get_installed { |
91
|
0
|
|
|
0
|
1
|
|
my $pkg = shift; |
92
|
0
|
|
|
|
|
|
my %p = validate( @_, |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
'name' => { 'type' => SCALAR, }, |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
); |
97
|
0
|
|
|
|
|
|
return $pkg->get_package('name' => $p{'name'}, 'hash' => 'installed'); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |