File Coverage

blib/lib/DPKG/Parse/Status.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


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