package PPM::Repository::Local;

use strict;
use PPM::PPD;
use PPM::Search;
use PPM::Result qw(Ok Warning Error List);

use Data::Dumper;

use base qw(PPM::Repository::WWW);
use vars qw($VERSION);
$VERSION = '3.05';

sub init {
    my $o = shift;
    my $base = $o->{url_base};
    $base->scheme('file') unless $base->scheme;
    $base->host('localhost') unless $base->host;
    $o->{url} = $o->{url_base};
}

sub load_pkg {
    my $o = shift;
    my $target = shift;
    my $pkg = shift;
    return Ok()
        if exists $o->{ppds}{$pkg} and $o->{ppds}{$pkg}->is_complete;
    my $file = "$o->{dir}/$pkg";
    $file .= ".ppd" unless $file =~ /\.ppd$/i;
    unless (-f $file) {
	return Error("Package '$pkg' not found. "
		     . "Please 'search' for it first.");
    }
    $o->{ppds}{$pkg} = PPM::PPD->new($file, $o, $pkg);
    Ok();
}

sub type_printable { "Local directory" }
