#! /pm/bin/perl5 -w
#
#V  Valparams.pm V1.0 14 Nov 1994 (for Perl 5.000)
#   Jim Richardson, University of Sydney
#   jimr@maths.usyd.edu.au or http://www.maths.usyd.edu.au:8000/jimr.html

package Valparams;

    require Exporter;
    @ISA = Exporter;
    @EXPORT = qw( valparams );

sub valparams
{
    my ( $params, @valparams ) = @_;

    #  Check that all the parameters supplied as { @_ } in the first
    #  argument have keywords occuring among @valparams

    my $object = {};

    #  Accept the valid parameters

    foreach( @valparams )
    {
	$object->{ $_ } = delete $params->{ $_ };
    }

    #  Reject any others

    my @badopts = keys %$params;

    if( @badopts )
    {
	my ( $pack1, $file1, $line1, $subname1 ) = caller( 1 );
	my ( $pack2, $file2, $line2, $subname2 ) = caller( 2 );

	die 'Unexpected option' . ( @badopts > 1 ? 's ' : ' ' ) .
	    join( ', ', @badopts ) .
	    " for $pack1::$subname1\n" .
	    "  called from $pack2::$subname2 at line $line2 in $file2\n";
    }

    $object;
}

#!#
