#!/usr/pkg/bin/perl

# simple pkgsrc / wip search script using pkgsrc.netbsd.se
# written by iMil <imil@gcu.info>

use LWP::UserAgent;
use HTTP::Request::Common;

my $version = "0.3";

sub usage {
  die "usage: $0 <pkgname>\n";
}

if ($#ARGV < 0) {
  usage();
}

my $pkgname=$ARGV[0];
my $baseurl='http://search.pkgsrc.se/';

my $ua = LWP::UserAgent->new(agent => 'pkgse $version');

my $resp = $ua->request(GET $baseurl.$pkgname);

print $resp->error_as_HTML unless $resp->is_success;

my $result=$resp->content();

my @list=split(/\n/, $result);

print "\n";
foreach(@list) {
	if (/^[0-9]+$/) {
		next; # we don't use result number
	}
	($category,$folder,$pkgname,$distname,$comment,$maint,$url) = split(/\|/, $_);
	print "Version    : $pkgname\n";
	print "Location   : $category/$folder\n";
	print "Comment    : $comment\n";
	print "Maintainer : $maint\n";
	print "URL        : $url\n";
	print "\n";
}
