File Coverage

blib/lib/DPKG/Parse/Status.pm
Criterion Covered Total %
statement 30 33 90.9
branch 2 2 100.0
condition n/a
subroutine 8 9 88.8
pod 3 3 100.0
total 43 47 91.4


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.03';
38              
39 2     2   51058 use DPKG::Parse::Entry;
  2         7  
  2         18  
40 2     2   100 use Params::Validate qw(:all);
  2         4  
  2         356  
41 2     2   1134 use Class::C3;
  2         5477  
  2         35  
42 2     2   88 use base qw(DPKG::Parse);
  2         2  
  2         884  
43 2     2   11 use strict;
  2         4  
  2         59  
44 2     2   11 use warnings;
  2         4  
  2         574  
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 27 my $pkg = shift;
56 2         142 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         28 my $ref = $pkg->next::method('filename' => $p{'filename'}, debug => $p{debug});
63 2         7 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         6 $pkg->next::method;
75 1         2 my $installed;
76 1         3 foreach my $entry (@{$pkg->entryarray}) {
  1         10  
77 4 100       44 if ($entry->status =~ /^install ok installed$/) {
78 1         14 $installed->{$entry->package} = $entry;
79             }
80             }
81 1         13 $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__