These documents are For the HEAD of the CVS repository on July 19, 2007
Api docs for previous releases
Modware
Root
Modware::Root - Base class, provides common error handling methods.
|
No package variables defined. |
Inherited by most Modware objects
|
This class simply is pretty much a ripoff of the BioPerl Bio::Root::Root object. Much of the of the code is lifted verbatim from that. It has been stripped down to keep things simple.
It provides such functionality as case insensitive argument parsing, throwing stack traces by calling $self->throw() or $self->warn(), and dynamically loading modules.
|
Methods description
NOTE : THIS IS A SIIMPLIFIED VERSION OF A METHOD LIFTED FROM BIOPERL
Title : _load_module
Usage : $self->_load_module("Bio::SeqIO::genbank");
Function: Loads up (like use) the specified module at run time on demand.
Example :
Returns : TRUE on success. Throws an exception upon failure.
.
Args : The module to load (_without_ the trailing .pm).
NOTE : LIFTED WHOLESALE FROM BIOPERL!!!!!!
Usage : $object->_rearrange( array_ref, list_of_arguments)
Purpose : Rearranges named parameters to requested order.
Example : $self->_rearrange([qw(SEQUENCE ID DESC)],@param);
: Where @param = (-sequence => $s,
: -desc => $d,
: -id => $i);
Returns : @params - an array of parameters in the requested order.
: The above example would return ($s, $i, $d).
: Unspecified parameters will return undef. For example, if
: @param = (-sequence => $s);
: the above _rearrange call would return ($s, undef, undef)
Argument : $order : a reference to an array which describes the desired
: order of the named parameters.
: @param : an array of parameters, either as a list (in
: which case the function simply returns the list),
: or as an associative array with hyphenated tags
: (in which case the function sorts the values
: according to @{$order} and returns that new array.)
: The tags can be upper, lower, or mixed case
: but they must start with a hyphen (at least the
: first one should be hyphenated.)
Source : This function was taken from CGI.pm, written by Dr. Lincoln
: Stein, and adapted for use in Bio::Seq by Richard Resnick and
: then adapted for use in Bio::Root::Object.pm by Steve Chervitz,
: then migrated into Bio::Root::RootI.pm by Ewan Birney.
: then copied to Modware::Root by Eric Just!
Comments :
: Uppercase tags are the norm,
: (SAC)
: This method may not be appropriate for method calls that are
: within in an inner loop if efficiency is a concern.
:
: Parameters can be specified using any of these formats:
: @param = (-name=>'me', -color=>'blue');
: @param = (-NAME=>'me', -COLOR=>'blue');
: @param = (-Name=>'me', -Color=>'blue');
: @param = ('me', 'blue');
: A leading hyphenated argument is used by this function to
: indicate that named parameters are being used.
: Therefore, the ('me', 'blue') list will be returned as-is.
:
: Note that Perl will confuse unquoted, hyphenated tags as
: function calls if there is a function of the same name
: in the current namespace:
: -name => 'foo' is interpreted as -&name => 'foo'
:
: For ultimate safety, put single quotes around the tag:
: ('-name'=>'me', '-color' =>'blue');
: This can be a bit cumbersome and I find not as readable
: as using all uppercase, which is also fairly safe:
: (-NAME=>'me', -COLOR =>'blue');
:
: Personal note (SAC): I have found all uppercase tags to
: be more managable: it involves less single-quoting,
: the key names stand out better, and there are no method naming
: conflicts.
: The drawbacks are that it's not as easy to type as lowercase,
: and lots of uppercase can be hard to read.
:
: Regardless of the style, it greatly helps to line
: the parameters up vertically for long/complex lists.
Usage : $object->_remove_arg( argument to remove, list_of_arguments)
Purpose : removes a parameter to from an argument list.
Example : $self->_remove_arg('sequence',@param);
: Where @param = (-sequence => $s,
-desc => $d,
: -id => $i);
Returns : @params - an array of parameters minus the requested parameter
: The above example would return
(-desc => $d,
: -id => $i);
Argument : $remove_key : argument name to remove (case insensitive)
: order of the named parameters.
: @param : an array of parameters, as a list
Methods code
sub _load_module
{
my ($self, $load) = @_;
$load =~ s/::/\//g;
eval {
require $load.".pm";
};
if ( $@ ) {
$self->throw("Failed to load module $load. ".$@);
}
return 1;
}
sub _rearrange
{
my $dummy = shift;
my $order = shift;
return @_ unless (substr($_[0]||'',0,1) eq '-');
push @_,undef unless $#_ %2;
my %param;
while( @_ ) {
(my $key = shift) =~ tr/a-z\055/A-Z/d; #deletes all dashes!
$param{$key} = shift;
}
map { $_ = uc($_) } @$order; # for bug #1343, but is there perf hit here?
return @param{@$order};
}
sub _remove_arg
{ my $dummy = shift;
my $remove_key = shift;
my @return =();
push @_,undef unless $#_ %2;
my %param = ();
while( @_ ) {
my $key = shift;
if ( uc($key) ne "-".uc($remove_key) ) {
$param{$key} = shift;
}
else {shift;}
}
@return = %param;
return @return;
}
sub throw
{ my ($self, @args) = @_;
croak(@args);
}
sub warn
{ my ($self, @args) = @_;
warn(@args);
}
General documentation
Copyright © 2006, Northwestern University
All rights reserved.
|
|