NAME

FreeBSD::Pkgs - Reads the FreeBSD installed packaged DB.

VERSION

Version 0.2.0

SYNOPSIS

The following example prints out the package information.

use FreeBSD::Pkgs;

$pkgdb=FreeBSD::Pkgs->new;

$pkgdb->parseInstalled;

while(my ($name, $pkg) = each %{$pkgdb->{packages}}){
	print $name."\nComment=".$pkg->{comment}."\n";

	#prints the packages that require it
	if (defined($pkg->{requiredby})){
		my $requiredbyInt=0;
		while (defined($pkg->{requiredby}[$requiredbyInt])){
			print $name." required by ".$pkg->{requiredby}[$requiredbyInt]."\n";
			$requiredbyInt++;
		}
	}

	#if the extract-in-place option is set, print it
	if (defined($pkg->{contents}{extract-in-place})){
		print $name." is set to extract in place\n";
	}

	#if the extract-in-place option is set, print it
	if (defined($pkg->{contents}{preserve})){
		print $name." is set to preserve the old file\n";
	}

	#print the mtree
	if (defined($pkg->{contents}{mtree})){
		print $name." the mtree for this package is '".$pkg->{contents}{mtree}."'\n";
	}

	#print installed files and associated info
	if (defined($pkg->{contents}{files})){
		my @files=keys(%{$pkg->{contents}{files}});
		my $filesInt=0;
		while (defined($files[$filesInt])){
			print $name." installs ".$files[$filesInt]." md5='".
			$pkg->{contents}{files}{$files[$filesInt]}{MD5}."' ";
			#prints the the group if there is a specific one for the file
			if (defined($pkg->{contents}{files}{$files[$filesInt]}{group})) {
				print " group='".$pkg->{contents}{files}{$files[$filesInt]}{group}."'";
			}
			#prints the the user if there is a specific one for the file
			if (defined($pkg->{contents}{files}{$files[$filesInt]}{user})) {
				print " user='".$pkg->{contents}{files}{$files[$filesInt]}{user}."'";
			}
			#prints the the mode if there is a specific one for the file
			if (defined($pkg->{contents}{files}{$mfiles[$filesInt]}{mode})) {
				print " mode='".$pkg->{contents}{files}{$files[$filesInt]}{mode}."'";
			}
			#prints the directory if it is not relative to the base
			if (defined($pkg->{contents}{files}{$mfiles[$filesInt]}{cwd})) {
				print " cwd='".$pkg->{contents}{files}{$files[$filesInt]}{cwd}."'";
			}
			#print if the file is set to be ignored
			if (defined($pkg->{contents}{files}{$mfiles[$filesInt]}{ignore})) {
				print " ignore='".$pkg->{contents}{files}{$files[$filesInt]}{ignore}."'";
			}
			#print if the file is set to be ignored
			if (defined($pkg->{contents}{files}{$mfiles[$filesInt]}{ignore_inst})) {
				print " ignore_inst='".$pkg->{contents}{files}{$files[$filesInt]}{ignore_inst}."'";
			}
			print "\n";
			$filesInt++;
		}
	}

	#prints the conflict information
	my $conflictInt=0;
	while (defined($pkg->{contents}{conflict}[$conflictInt])){
		print $name." conflicts with ".$pkg->{contents}{conflict}[$conflictInt]."\n";
		$conflictInt++;
	}

	#print dirrm stuff
	my $dirrmInt=0;
	while (defined($pkg->{contents}{dirrm}[$dirrmInt])){
		print $name." conflicts with ".$pkg->{contents}{dirrm}[$dirrmInt]."\n";
		$dirrmInt++;
	}

	print "\n";
}

FUNCTIONS

new

#creates a new object with the default settings
my $pkgdb=FreeBSD::Pkgs->new;

#creates a new package with the a specified pkgdb dir
my $pkgdb=FreeBSD::Pkgs->new({pkgdb=>'/var/db/pkg'});

#if this is true there is a error
if($pkgdb->error){
    warn('Error:'.$pkgdb->error.': '.$pkgdb->errorString);
}

arguement keys

pkgdb

If this key is defined, it uses this dir to use for the package db.

The same environmental variables as used by the package tools are respected.

parseContents

This parses the '+CONTENTS' file for a package. The only required is a string containing the contents of the file to be parsed.

args hash

files

A boolean controlling if file information is parsed or not.

my %contents=$pkgdb->parseContents($contentString, %args);
if($pkgdb->error){
    warn('Error:'.$pkgdb->error.': '.$pkgdb->errorString);
}

parseInstalled

This reads all installed packages. The returned value is a boolean.

args hash

files

A boolean controlling if file information is parsed or not.

This will be passed to parseInstalledPkg and then parseContents.

$pkgdb->parseInstalled(%args);
#checks to see if it completed successfully
if($pkgdb->{error}){
    print 'Error: '.$pkgdb->{error}."\n";
}

#checks to make sure it completed successfully using a if statement
if($pkgdb->parseInstalled(%args)){
    print 'Error: '.$pkgdb->{error}."\n";
}

parseInstalledPkg

This parses the specified installed package.

args hash

files

A boolean controlling if file information is parsed or not.

This will be passed to parseContents.

my %pkg=$pkgdb->parseInstalledPkg($pkgname, %args);
if($error){
    print "Error!\n";
}

Package Hash

This hash is contained in $pkgdb->{packages} or returned by $pkgdb-parseInstalledPkg. Each of it's key is name of a installed package and a hash. See the information below for key values of that hash.

comment

This holds the package comment.

contents

This contains a hash that contains the parsed contents of the '+CONTENTS' file. For additional information on this hash see the section '+CONTENTS Hash'.

desc

This holds the description of the package.

requiredby

This contains a array holding the a list of packages that require this package.

+CONTENTS Hash

This has is either contained in $pkgdb->{packages}{<packagename>}{contents} or returned by $pkgdb->parseContents.

cwd

This is a string that contains the prefix for the package.

mtree

This is a string that contains the mtree file to use for the package.

requiredby

This is a array that contains a list of packages that requires this package.

srcdir

See pkg_create(1) for @srcdir, as I can't think of a decent description.

unexec

This is a array that contains the unexec lines.

exec

This is a array that contains the exec lines.

dirrm

This is a array of directories to remove.

conflicts

This is a array that holds a list of conflicting packages.

deps

This contains another hash. See the section 'deps Hash' for more information.

comment

This is a array that contains comments that this module was not sure what to do with.

files

This is a hash that contains information on the installed files. See the section 'files Hash' for more information.

deps Hash

This is a hash contained in $pkgdb->{<package>}{contents}{deps}{<pkgdep>}.

origin

This is the ports origin location, if one is given.

files Hash

This is a hash that contains information on the installed files. See the section 'files Hash' for more information. This is a hash contained in $pkgdb->{<package>}{contents}{files}{<file>}. The keys of the hash are the name of the files.

MD5

This is the MD5 sum of the file.

cwd

This is the cwd for the file if it is not set to the base one.

ignore_inst

This is defined if the ignore_inst flag is set to.

ignore

This is defined if the ignore flag is set to.

mode

This is defined if a specific mode is set for a file.

group

This is defined if a specific group is set for a file.

owner

This is defined if a specific owner is set for a file.

NOTES

@noinst

These lines in the '+CONTENTS' file are not currently handled.

@exec

The handling of these lines are going to be changed in the near future.

@unexec

The handling of these lines are going to be changed in the near future.

@display

Currently not handled in this version of.

memory

It is generally uses atleast twice the amount of ram as the size of the pkgdb.

ERROR CODES/HANDLING

Error handling is provided by Error::Helper.

1

PKG_DBDIR does not exist.

2

Could not open PKG_DBDIR.

3

The named dir entry in PKG_DBDIR is not a directory.

4

Could not open the specified required by file.

5

Could not open the specified comment file.

6

Could not open the specified description file.

7

Could not open the specified contents file.

8

A line matching /^\@comment DEPORIGIN:/ was found, no previous depedencies have been found.

9

A line matching /^\@comment MD5:/ was found, no previous files have been found.

10

Unable to make sense of the specified '+CONTENTS' line.

11

/^\@cwd/ matched twice in a '+CONTENTS' file.

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-freebsd-pkgs at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-Pkgs. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc FreeBSD::Pkgs

You can also look for information at:

ACKNOWLEDGEMENTS

Peter V. Vereshagin, #69658, notified me about a pointless warning for the portupgrade DB file

COPYRIGHT & LICENSE

Copyright 2012 Zane C. Bowers-Hadley, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.