package CGI_ARG;

# Author : Gavin Sherlock
# Date   : 23rd August 2000

# Purpose : This module contains a single function,
#           which aids in thhe translation of cgi parameters
#           into parameters to be used to construct an dictyBaseObject
#

use strict;
use vars qw (@ISA @EXPORT_OK);
use Exporter;
@ISA = ('Exporter');
@EXPORT_OK = qw ( GetQueryAndType );

################################################################################
sub GetQueryAndType{
################################################################################
# This subroutine takes a hash as an argument, and returns two scalars,
# the query name, ands it's type

# Usage :
# It is up to the client to contruct the %args hash from the cgi parameters,
# eg .
#
#  my %args;
#
#  foreach (param()){
#
#     $args{$_} = param($_);
#
#  }
#
# Then:
#
# my ($query, $type) = GetQueryAndType(%args);
#
# an dictyBaseObject can then be easily and safely contructed thus:
#
# my $object = dictyBaseObject->new(database=>$database,
#                             $type=>$query);
#
# The client of the dictyBaseObject can then use the methods of that class
# to retrieve further information about the object

    my (%args) = @_;

    my ($query, $type);
	
    if ($args{'locus'}){ # generic query
	$query = $args{'locus'};
	$type = "query";
    }elsif ($args{'dictyBaseid'}){
	$query = $args{'dictyBaseid'};
	$type = "dictyBaseid";
    }elsif ($args{'locusNo'}){ # using the locusNo
	$query = $args{'locusNo'};
	$type = "locusNo";
    }elsif ($args{'locusName'}){
	$query = $args{'locusName'};
	$type = "locusName";
    }elsif ($args{'featureNo'}){
	$query = $args{'featureNo'};
	$type = "featureNo";
    }elsif ($args{'featureName'}){
	$query = $args{'featureName'};
	$type = "featureName";
    }elsif ($args{'aliasNo'}){
	$query = $args{'aliasNo'};
	$type = "aliasNo";
    }elsif ($args{'aliasName'}){
	$query = $args{'aliasName'};
	$type = "aliasName";
    }

    if ($query =~ /^[SL][0-9]+/i) {
	$type = "dictyBaseid";
    }

    return ($query, $type);

}












