FreeBSD::Pkgs::FindUpdates - Finds updates for FreeBSD pkgs by checking the ports index.


FreeBSD-Pkgs-FindUpdates documentation Contained in the FreeBSD-Pkgs-FindUpdates distribution.

Index


Code Index:

NAME

Top

FreeBSD::Pkgs::FindUpdates - Finds updates for FreeBSD pkgs by checking the ports index.

VERSION

Top

Version 0.2.1

SYNOPSIS

Top

This does use FreeBSD::Ports::INDEXhash. Thus if you want to specifiy the location of the index file, you will want to see the supported methodes for it in that module.

    use FreeBSD::Pkgs::FindUpdates;
    #initiates the module
    my $pkgsupdate = FreeBSD::Pkgs::FindUpdates->new();
    #finds changes
    my %changes=$pkgsupdate->find();
    #prints the upgraded stuff
    while(my ($name, $pkg) = each %{$changes{upgrade}}){
        print $name.' updated from "'.
              $pkg->{oldversion}.'" to "'.
              $pkg->{newversion}."\"\n";
    }
    #prints the downgraded stuff
    while(my ($name, $pkg) = each %{$changes{upgrade}}){
        print $name.' updated from "'.
              $pkg->{oldversion}.'" to "'.
              $pkg->{newversion}."\"\n";
    }

FUNCTIONS

Top

new

This initiate the module.

find

This finds any changes creates a hash.

Two arguements are optionally accepted. The first is a hash returned from INDEXhash

    #basic usage...
    my %changes=$pkgsupdate->find;

    #create the INDEXhash and pkgdb and then pass it
    my $pkgdb=FreeBSD::Pkgs->new;
    $pkgdb->parseInstalled({files=>0});
    my %index=INDEXhash();
    my %changes=$pkgsupdate->find(\%index, $pkgdb);

Changes Hash

Top

This hash contains several keys that are listed below. Each is a hash that contain several keys of their own. Please see the sub hash section for information on that.

The name of the installed package is used as the primary key in each.

downgrade

This is a hash that contains a list of packages to be down graded.

from

The keys to this hash are the packages that will be change from. The values are the names that it will changed to.

upgrade

This is a hash that contains a list of packages to be up graded.

same

This means there is no change.

to

The keys to this hash are the packages that will be change to. The values are the names that it will changed from.

sub hash

All three keys contain hashes that then contian these values.

old

This is the name of the currently installed package.

new

This is the name of what it will be changed to if upgraded/downgraded.

oldversion

This is the old version.

newversion

This is the version ofwhat it will be changed toif upgraded/downgraded.

port

This is the port that provides it.

ERROR

Top

1

No origin for a specified package. This is not a fatal error.

2

A line in the INDEX file is missing the path to the ports directory for that port.

AUTHOR

Top

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

BUGS

Top

Please report any bugs or feature requests to bug-freebsd-pkgs-findupdates at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-Pkgs-FindUpdates. 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::Pkgs::FindUpdates




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-Pkgs-FindUpdates

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/FreeBSD-Pkgs-FindUpdates

* CPAN Ratings

http://cpanratings.perl.org/d/FreeBSD-Pkgs-FindUpdates

* Search CPAN

http://search.cpan.org/dist/FreeBSD-Pkgs-FindUpdates

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


FreeBSD-Pkgs-FindUpdates documentation Contained in the FreeBSD-Pkgs-FindUpdates distribution.
package FreeBSD::Pkgs::FindUpdates;

use warnings;
use strict;
use FreeBSD::Pkgs;
use FreeBSD::Ports::INDEXhash qw/INDEXhash/;
use Sort::Versions;

our $VERSION = '0.2.1';


sub new {
	my %args;
	if(defined($_[1])){
		%args= %{$_[1]};
	};

	my $self={error=>undef, errorString=>''};
	bless $self;
	return $self;

}

sub find {
	my %index;
	if(defined($_[1])){
		%index= %{$_[1]};
	}else {
		%index=INDEXhash();
	};
	my $pkgdb;
	if (defined($_[2])) {
		$pkgdb=$_[2];
	}else {
		#parse the installed packages
		$pkgdb=FreeBSD::Pkgs->new;
		$pkgdb->parseInstalled({files=>0});
	}

	#a hash of stuff that needes changed
	my %change;
	$change{upgrade}={};
	$change{same}={};
	$change{downgrade}={};
	$change{from}={};
	$change{to}={};

	#process it
	while(my ($pkgname, $pkg) = each %{$pkgdb->{packages}}){
		my $src=$pkg->{contents}{origin};
		my $path=$src;

		#versionless packagename
		my $vpkgname=$pkgname;
		my @vpkgnameSplit=split(/-/, $vpkgname);
		my $int=$#vpkgnameSplit - 1;#just called int as I can't think of a better name
		$vpkgname=join('-', @vpkgnameSplit[0..$int]);

		#get the pkg version
		my $pkgversion=$pkgname;
		$pkgversion=~s/.*-//;

		#if this is not defined, we can't upgrade it... so skip it
		#stuff in stalled via cpan will do this
		if (!defined($src)) {
			if (!$pkgname =~ /^bsdpan-/) {
				warn('FreeBSD-Pkgs-FindUpdates find:1: No origin for "'.$pkgname.'"');
			}
		}else{
			my $portname=$index{soriginsD2N}{$path};

			if (!defined($portname)) {
				warn("No port found for '".$path."'");
				goto versionCompareEnd;
			}

			#versionless portname
			my $vportname=$portname;
			my @vportnameSplit=split(/-/, $vportname);
			$int=$#vportnameSplit - 1;#just called int as I can't think of a better name
			$vportname=join('-', @vportnameSplit[0..$int]);
			
			#get the port version
			my $portversion=$portname;
			$portversion=~s/.*-//;
			
			#if the pkg versionis less than the port version, it needs to be upgraded
			if (versioncmp($pkgversion, $portversion) == -1) {
				$change{upgrade}{$pkgname}={old=>$pkgname, new=>$portname,
											oldversion=>$pkgversion,
											newversion=>$portversion,
											port=>$path,
											};
				$change{from}{$pkgname}=$portname;
				$change{to}{$portname}=$pkgname;
			}
			
			#if the pkg version and the port version are the same it is the same
			if (versioncmp($pkgversion, $portversion) == 0) {
				$change{same}{$pkgname}={old=>$pkgname, new=>$portname,
										 oldversion=>$pkgversion,
										 newversion=>$portversion,
										 port=>$path
										 };
			}
			
			#if the pkg version is greater than the port version, it needs to be downgraded
			if (versioncmp($pkgversion, $portversion) == 1) {
				$change{downgrade}{$pkgname}={old=>$pkgname, new=>$portname,
											  oldversion=>$pkgversion,
											  newversion=>$portversion,
											  port=>$path,
											  };
				$change{to}{$pkgname}=$portname;
				$change{from}{$portname}=$pkgname;
			}

			versionCompareEnd:
		}
	}
	
	return %change;
}

1; # End of FreeBSD::Pkgs::FindUpdates