#!/usr/bin/perl -w

use strict;

package test;

#use Data::Dumper;

my %disp;
my $func;
my $str;

sub findfunc($) {
    $str = shift;
    my $ref = $disp{$str};
    if (defined($ref)) {
	$func = $$ref[0];
    } else {
	print "no such function: <$str>\n";
    }
}

sub main(%) {
    %disp = @_;

    if (-t STDIN) {
	print "Available functions:\n ", join(" ", sort keys %disp), "\n\n";
    }
    if (@ARGV) {
	my $tst = shift @ARGV;
	findfunc($tst);
    }
    while (<>) {
	chomp;
	#print "Got <$_>\n";
	if (m/^sub (.*)$/) {
	    #print "sub thing\n";
	    findfunc($1);
	    #print Dumper(\%disp);
	    #print Dumper($ref);
	    next;
	}
        if (!defined($func)) {
	    print "no function selected, use \"sub <func>\"\n";
	    next;
	}

	print "Testing $str($_):\n";
	&$func($_);
    }
}

1;
