lib SubOpt
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
SubOpt - Odyssey Subroutine Input API
Package variables
Privates (from "my" definitions)
%data;
Included modules
G::Messenger
Inherit
Exporter
Synopsis
  use SubOpt;

  &odyssey ($gb, -option=>"neat!", -file=>"fancy.txt", "oops");

  sub odyssey{
      opt_default(option => 'none', file => 'hoge.txt');
      # Set default values. This is optional.

      my @args = opt_get(@_);
      # Parse options.

      my $gb = opt_as_gb(shift @args);
      # Get the input value as a G instance
 
      my $last = shift @args;

      print $gb->{SEQ} , "\n";
      print "last: $last\n";
      print "option: ", opt_val("option"), "\n";
      print "file: ", opt_val("file"), "\n";
      # Option values are accessed via opt_val().
  }
Description
  SubOpt parses the arguments given to a subroutine in a similar 
  manner as GetOpt module.

  Options are specified in the form: -option=>"hoge"
  The above will input the value "hoge" with a key "option".
  i.e. option with '-' is stored with the value pointed with '=>'.

  supported methods:

  opt_default(
Methods
opt_as_gb
No description
Code
opt_default
No description
Code
opt_get
No description
Code
opt_val
No description
Code
Methods description
None available.
Methods code
opt_as_gbdescriptionprevnextTop
sub opt_as_gb {
    if ($#_ >= 1){
	&msg_error("Error 1 in SubOpt::opt_as_gb():\n  Given value is not a valid sequence.\n");
	return '';
    }elsif (length $_[0] < 1){
	&msg_error("Error 2 in SubOpt::opt_as_gb():\n  Given value is NULL.\n");
	die;
    }

    my $unknown = shift @_;
    my $ref =\$ unknown;
    my $new_gb = new G::Skyline('blessed');

    if ("$unknown" =~ /\=/){
	if (defined $unknown->{SEQ}){
	    return $unknown;
	}else{
	    &msg_error("Error 3 in SubOpt::opt_as_gb():\n  Given value is not a valid sequence.\n");
	    return '';
	}
    } elsif (ref $unknown eq 'SCALAR') {
	$new_gb->{SEQ} = $$unknown;
	return $new_gb;
    } elsif (ref $unknown eq 'REF') {
	$new_gb->{SEQ} = $$unknown;
	return $new_gb;
    } elsif (ref $ref eq 'SCALAR'){
	$new_gb->{SEQ} = $unknown;
	return $new_gb;
    }else{
	&msg_error("Error 4 in SubOpt::opt_as_gb():\n  Given value is not a valid sequence.\n");
	return '';
    }
}
opt_defaultdescriptionprevnextTop
sub opt_default {
    %data = (@_);
}
opt_getdescriptionprevnextTop
sub opt_get {
    my @args = @_;
    my @new_args = ();
    my $i = 0;
    my @bparray = ();

    while(defined $args[$i]){

	if (substr($args[$i], 0, 1) eq '-' && substr($args[$i], 1, 1) !~ /[0-9]/){
	    $data{substr($args[$i],1)} = $args[$i + 1];
	    $i += 2;
        }else{
	    if (ref $args[$i] =~ /Bio::Seq/){
		push(@new_args, G::IO::Bioperl::convert($args[$i]));
	    }else{
		push(@new_args, $args[$i]);
	    }
	    $i ++;
	}
    }

    return @new_args;
}
opt_valdescriptionprevnextTop
sub opt_val {
    my $key = shift;
    return $data{$key};
}
General documentation
AUTHORTop
  Kazuharu Arakawa, gaou@sfc.keio.ac.jp
SEE ALSOTop
perl(1).