FreeBSD::Pkgs - Reads the FreeBSD installed packaged DB.
Version 0.2.0
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"; }
#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); }
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.
This parses the '+CONTENTS' file for a package. The only required is a string containing the contents of the file to be parsed.
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); }
This reads all installed packages. The returned value is a boolean.
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"; }
This parses the specified installed package.
This will be passed to parseContents.
my %pkg=$pkgdb->parseInstalledPkg($pkgname, %args); if($error){ print "Error!\n"; }
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.
This holds the package comment.
This contains a hash that contains the parsed contents of the '+CONTENTS' file. For additional information on this hash see the section '+CONTENTS Hash'.
This holds the description of the package.
This contains a array holding the a list of packages that require this package.
This has is either contained in $pkgdb->{packages}{<packagename>}{contents} or returned by $pkgdb->parseContents.
This is a string that contains the prefix for the package.
This is a string that contains the mtree file to use for the package.
This is a array that contains a list of packages that requires this package.
See pkg_create(1) for @srcdir, as I can't think of a decent description.
This is a array that contains the unexec lines.
This is a array that contains the exec lines.
This is a array of directories to remove.
This is a array that holds a list of conflicting packages.
This contains another hash. See the section 'deps Hash' for more information.
This is a array that contains comments that this module was not sure what to do with.
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}{deps}{<pkgdep>}.
This is the ports origin location, if one is given.
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.
This is the MD5 sum of the file.
This is the cwd for the file if it is not set to the base one.
This is defined if the ignore_inst flag is set to.
This is defined if the ignore flag is set to.
This is defined if a specific mode is set for a file.
This is defined if a specific group is set for a file.
This is defined if a specific owner is set for a file.
These lines in the '+CONTENTS' file are not currently handled.
The handling of these lines are going to be changed in the near future.
Currently not handled in this version of.
It is generally uses atleast twice the amount of ram as the size of the pkgdb.
Error handling is provided by Error::Helper.
PKG_DBDIR does not exist.
Could not open PKG_DBDIR.
The named dir entry in PKG_DBDIR is not a directory.
Could not open the specified required by file.
Could not open the specified comment file.
Could not open the specified description file.
Could not open the specified contents file.
A line matching /^\@comment DEPORIGIN:/ was found, no previous depedencies have been found.
A line matching /^\@comment MD5:/ was found, no previous files have been found.
Unable to make sense of the specified '+CONTENTS' line.
/^\@cwd/ matched twice in a '+CONTENTS' file.
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
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.
bug-freebsd-pkgs at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc FreeBSD::Pkgs
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-Pkgs
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/FreeBSD-Pkgs
CPAN Ratings
http://cpanratings.perl.org/d/FreeBSD-Pkgs
Search CPAN
http://search.cpan.org/dist/FreeBSD-Pkgs
Peter V. Vereshagin, #69658, notified me about a pointless warning for the portupgrade DB file
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.
To install FreeBSD::Pkgs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FreeBSD::Pkgs
CPAN shell
perl -MCPAN -e shell install FreeBSD::Pkgs
For more information on module installation, please visit the detailed CPAN module installation guide.