| DPKG-Parse documentation | Contained in the DPKG-Parse distribution. |
DPKG::Parse - Parse various dpkg files into Perl Objects
use DPKG::Parse::Status;
my $status = DPKG::Parse::Status->new;
while (my $entry = $status->next_package) {
print $entry->package . " " . $entry->version . "\n";
}
use DPKG::Parse::Available;
my $available = DPKG::Parse::Available->new;
while (my $entry = $available->next_package) {
print $entry->package . " " . $entry->version . "\n";
}
DPKG::Parse contains utilities to parse the various files created by dpkg and turn them into helpful Perl objects. Current files understood by various DPKG::Parse modules:
/var/lib/dpkg/status - DPKG::Parse::Status /var/lib/dpkg/available - DPKG::Parse::Available Packages.gz - DPKG::Parse::Packages
See each module's documentation for particulars - You should not be calling DPKG::Parse directly.
A simple accessor for the file currently being parsed.
Access to the raw array of entries in a given file.
Access to the raw hash of entries. The key is determined by the module, but is usually the Package name.
A generic new function; takes a filename and calls the filename() accessor with it. Should not be called directly, but through on of the children of this package.
A default parse function; simply calls parse_package_format.
Takes a file in a format similar to the dpkg "available" file, and creates DPKG::Parse::Entry objects from each entry.
The value of a hash, if it exists. By default, it uses the value returned by the "entryhash" accessor, but that can be overridden with the "hash" parameter. Usually returns a DPKG::Parse::Entry object.
Shifts the next value off the array stored in the entryarray() accessor. If you want to access the raw values, do not use this function! It shifts!
Adam Jacob, holoway@cpan.org
This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.
| DPKG-Parse documentation | Contained in the DPKG-Parse distribution. |
# # DPKG::Parse.pm # Created by: Adam Jacob, <holoway@cpan.org> # Created on: 12/19/2005 02:21:03 PM PST # # $Id: $
package DPKG::Parse; use Params::Validate qw(:all); use DPKG::Parse::Entry; use Class::C3; use base qw(Class::Accessor); use strict; use warnings; DPKG::Parse->mk_accessors(qw(filename entryarray entryhash)); my $VERSION = "0.01";
sub new { my $pkg = shift; my %p = validate(@_, { 'filename' => { 'type' => SCALAR, }, } ); my $ref = {}; if ($p{'filename'}) { $ref->{'filename'} = $p{'filename'}; }; $ref->{'entryarray'} = []; $ref->{'entryhash'} = {}; bless($ref, $pkg); return $ref; }
sub parse { my $pkg = shift; $pkg->parse_package_format; }
sub parse_package_format { my $pkg = shift; if (! -f $pkg->filename) { die "Cannot find " . $pkg->filename . ", or it's not a file at all!"; } open(STATUS, $pkg->filename); my $entry; STATUSLINE: while (my $line = <STATUS>) { if ($line =~ /^\n$/) { my $dpkg_entry = DPKG::Parse::Entry->new('data' => $entry); push(@{$pkg->{'entryarray'}}, $dpkg_entry); $pkg->{'entryhash'}->{$dpkg_entry->package} = $dpkg_entry; $entry = undef; next STATUSLINE; } $entry = $entry . $line; } close(STATUS); }
sub get_package { my $pkg = shift; my %p = validate( @_, { 'name' => { 'type' => SCALAR, }, 'hash' => { 'type' => SCALAR, 'default' => 'entryhash', }, }, ); if (exists($pkg->{$p{'hash'}}->{$p{'name'}})) { return $pkg->{$p{'hash'}}->{$p{'name'}}; } else { return undef; } }
sub next_package { my $pkg = shift; return shift(@{$pkg->{'entryarray'}}); } 1; __END__