FreeBSD::Ports::INDEXhash - Generates a hash out of the FreeBSD Ports index file.


FreeBSD-Ports-INDEXhash documentation Contained in the FreeBSD-Ports-INDEXhash distribution.

Index


Code Index:

NAME

Top

FreeBSD::Ports::INDEXhash - Generates a hash out of the FreeBSD Ports index file.

VERSION

Top

Version 1.2.2

SYNOPSIS

Top

	use FreeBSD::Ports::INDEXhash qw/INDEXhash/;

	my %hash=INDEXhash();

	while(my ($name, $port) = each %hash){
	    print "Name: ".$name."\n".
	            "Info: ".$port->{info}."\n".
	            "Prefix: ".$port->{prefix}."\n".
	            "Maintainer: ".$port->{maintainer}."\n".
	            "WWW: ".$port->{www}."\n".
	            "Categories: ".join(" ", @{$port->{categories}})."\n".
	            "E-deps: ".join(" ", @{$port->{Edeps}})."\n".
	            "B-deps: ".join(" ", @{$port->{Bdeps}})."\n".
	            "P-deps: ".join(" ", @{$port->{Pdeps}})."\n".
	            "R-deps: ".join(" ", @{$port->{Rdeps}})."\n".
	            "F-deps: ".join(" ", @{$port->{Fdeps}})."\n".
	            "\n";

	    $keysInt++;
	};




EXPORT

Top

INDEXhash

FUNCTIONS

Top

INDEXhash

This parses the FreeBSD ports index file and a hash of it. Upon error it returns undef.

If a path to it is not passed to this function, it chooses the file automatically. The PORTSDIR enviromental varaiable is respected if using automatically.

HASH FORMAT

Top

Each entry, minus 'originsN2D' and 'originsD2N'.

ports hash

info

This is a short description of the port.

prefix

This is the install prefix the port will try to use.

maintainer

This is the email address for the port's maintainer.

www

This is the web site of a port inquestion.

Edeps

This is the extract depends of a port. This is a array.

Bdeps

This is the build depends for the port. This is a array.

Pdeps

This is the package depends for a port. This is a array.

Rdeps

This is the run depends of a port. This is a array.

Fdeps

This is the fetch depends of a port. This is a array.

categories

This is all the categories a specific port falls under. This is a array.

originsN2D

This contains a mapping of port names to the directory they are in.

originsD2N

This contains a mapping of directories to port names.

soriginsD2N

This is the same as 'originsD2N', but does not everything prior to the ports directory is removed. This is to make it easy for matching packages to ports.

originsN2D

This is the same as 'originsN2D', but does not everything prior to the ports directory is removed.

AUTHOR

Top

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

BUGS

Top

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

SUPPORT

Top

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

    perldoc FreeBSD::Ports::INDEXhash




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-Ports-INDEXhash

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/FreeBSD-Ports-INDEXhash

* CPAN Ratings

http://cpanratings.perl.org/d/FreeBSD-Ports-INDEXhash

* Search CPAN

http://search.cpan.org/dist/FreeBSD-Ports-INDEXhash

ACKNOWLEDGEMENTS

Top

kevin brintnall <kbrint@rufus.net> for pointing out how useful the each function is.

Yen-Ming Lee <leeym@freebsd.org> for pointing out the issue with Fdeps always being defined due to a new line on the end of it.

COPYRIGHT & LICENSE

Top


FreeBSD-Ports-INDEXhash documentation Contained in the FreeBSD-Ports-INDEXhash distribution.
package FreeBSD::Ports::INDEXhash;

use warnings;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
require Exporter;

@EXPORT_OK   = qw(INDEXhash);
@ISA         = qw(Exporter);
@EXPORT      = ();

our $VERSION = '1.2.2';


sub INDEXhash {
	my $index=$_[0];
	
	if(!defined($index)){
		if(!defined($ENV{PORTSDIR})){
			$index="/usr/ports/INDEX-";

		}else{
			$index=$ENV{PORTSDIR}."/INDEX-";
		};

		my $fbsdversion=`uname -r`;
		chomp($fbsdversion);
		$fbsdversion =~ s/\..+// ;
		$index=$index.$fbsdversion;

		if (! -f $index) {
			if(!defined($ENV{PORTSDIR})){
				$index="/usr/ports/INDEX";
				
			}else{
				$index=$ENV{PORTSDIR}."/INDEX";
			};
		}

	};

	#error out if the it is not a file
	if(! -f $index){
		return undef;
	};
	
	#read the index file
	if(!open(INDEXFILE, $index)){
		return undef;
	};
	my @rawindex=<INDEXFILE>;
	close(INDEXFILE);
	
	my %hash=(orginsN2D=>{}, originsD2N=>{});
	
	my $rawindexInt=0;
	while(defined($rawindex[$rawindexInt])){
		my @linesplit=split(/\|/, $rawindex[$rawindexInt]);

		$hash{$linesplit[0]}={path=>$linesplit[1],
								prefix=>$linesplit[2],
								info=>$linesplit[3],
								maintainer=>$linesplit[5],
								www=>$linesplit[9],
								Bdeps=>[],
								Rdeps=>[],
								Edeps=>[],
								Pdeps=>[],
								Fdeps=>[],
								categories=>[]
							};

		#builds the origin mappings
		$hash{originsN2D}{$linesplit[0]}=$linesplit[1];
		$hash{originsD2N}{$linesplit[1]}=$linesplit[0];
		#builds the short origin mappings
		$hash{soriginsN2D}{$linesplit[0]}=$linesplit[1];
		$hash{soriginsN2D}{$linesplit[0]}=~s/\/usr\/ports\///;
		if (defined($ENV{PORTSDIR})) {
			$hash{soriginsN2D}{$linesplit[0]}=~s/$ENV{PORTSDIR}//;
			$hash{soriginsN2D}{$linesplit[0]}=~s/^\///;
		}
		$hash{soriginsD2N}{$hash{soriginsN2D}{$linesplit[0]}}=$linesplit[0];

		my $depsInt=0;
		chomp($linesplit[12]);
		my @Fdeps=split(/ /, $linesplit[12]);		
		while(defined($Fdeps[$depsInt])){
			push(@{$hash{$linesplit[0]}{Fdeps}}, $Fdeps[$depsInt]);
			
			$depsInt++;
		};


		$depsInt=0;
		my @Pdeps=split(/ /, $linesplit[11]);
		while(defined($Pdeps[$depsInt])){
			push(@{$hash{$linesplit[0]}{Pdeps}}, $Pdeps[$depsInt]);

			$depsInt++;
		};

		$depsInt=0;
		my @Edeps=split(/ /, $linesplit[10]);
		while(defined($Edeps[$depsInt])){
			push(@{$hash{$linesplit[0]}{Edeps}}, $Edeps[$depsInt]);

			$depsInt++;
		};

		$depsInt=0;
		my @Rdeps=split(/ /, $linesplit[8]);
		while(defined($Rdeps[$depsInt])){
			push(@{$hash{$linesplit[0]}{Rdeps}}, $Rdeps[$depsInt]);

			$depsInt++;
		};

		$depsInt=0;
		my @Bdeps=split(/ /, $linesplit[7]);
		while(defined($Bdeps[$depsInt])){
			push(@{$hash{$linesplit[0]}{Bdeps}}, $Bdeps[$depsInt]);

			$depsInt++;
		};

		$depsInt=0;
		my @categories=split(/ /, $linesplit[6]);
		while(defined($categories[$depsInt])){
			push(@{$hash{$linesplit[0]}{categories}}, $categories[$depsInt]);

			$depsInt++;
		};

		$rawindexInt++;
	};
	
	return %hash;
};

1; # End of FreeBSD::Ports::INDEXhash