Bionanny::Base - a base object for all Bionanny objects


  # any Bionanny object is a Base object
  # Here's how to throw and catch an exception using the eval-based syntax.
  $obj->throw ("This is an exception");
  eval {
      $obj->throw ("This is how to catch an exception");
  if ($@) {
      print "Caught exception";
  } else {
      print "no exception";
  # --- OR ---
  $obj->throw( -class => 'Bionanny::YourOwnException',
               -text  => "Can not open file $file",
               -value  => $file);


Most Bionanny objects should inherit from this. It gives them unified constructor and error handling.



Martin Senger (


This file is a component of the Bionanny project. Copyright Michael Niemi & Martin Senger. For details contact, or see

Parts were re-factored from modules available in Bioperl project. See copyright notices there.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


This software is provided ``as is'' without warranty of any kind.



  $obj->throw ("error message");

--- OR ---

  $obj->throw( -text  => "error message",
               -value => $bad_value  );
--- OR ---
  $obj->throw( -class => 'Bionanny::MyOwnException',
               -text  => "error message",
               -value => $bad_value  );

It throws an exception, which, if not caught with an eval or a try block will provide a nice stack trace to STDERR with the message. If no -class parameter is provided (i.e. a simple string is given), a the Bionanny::Exception manpage is thrown.

It does not return anything meaningful.

An argument can be a string giving a descriptive error message, or there may be named arguments, from which the -class is recognized here: it contains a string with the name of a class that derives from, such as a the Bionanny::Exception manpage (which is used as the default one if no class is given). All arguments are passed to the constructor of this class.


 $object->extract ($array_ref, @params)

The argument $array_ref is a reference to an array which contains names of the wanted parameters (without hyphens).

The argument @param is an array of parameters as an associative array with hyphenated tags (names, keys). The tags can be upper, lower, or mixed case.

It extracts named parameters from a list. The input list is expected to consist from the name-value pairs. The returned list contains just the values of the pairs whose names were requested in the first argument, or undef if the specified name does not exist.

For example, assuming that @param contains:

  @param = (-class => $class,
            -text  => $text);

one can extract:

  $self->extract ([qw(CLASS TEXT)],@param);

that returns ($class, $text).