()
=cut
#--------
sub type { my($self,$delimiter) = @_; $self->get('type',$delimiter); }
#--------
=head2 note
Usage : $note = $err->note;
: $note = $err->note('');
Purpose : Get any general note associated with the exception.
Returns : String
Argument : optional string to be used as a delimiter.
See Also : L(), L()
=cut
#---------
sub note { my($self,$delimiter) = @_; $self->get('note',$delimiter); }
#---------
=head2 tech
Usage : $tech = $err->tech;
: $tech = $err->tech('');
Purpose : Get any technical note associate with the exception.
Returns : String
Argument : optional string to be used as a delimiter.
See Also : L(), L()
=cut
#------------
sub tech { my($self,$delimiter) = @_; $self->get('tech',$delimiter); }
#------------
=head2 stack
Usage : $stack = $err->stack;
: $stack = $err->stack('');
Purpose : Get the call stack for the exception.
Returns : String
Argument : optional string to be used as a delimiter.
See Also : L(), L()
=cut
#----------
sub stack { my($self,$delimiter) = @_; $self->get('stack',$delimiter); }
#----------
=head2 context
Usage : $context = $err->context;
: $context = $err->context('');
Purpose : Get the containment context of the object which generated the exception.
Returns : String
Argument : optional string to be used as a delimiter.
See Also : L(), L()
=cut
#------------
sub context { my($self,$delimiter) = @_; $self->get('context',$delimiter); }
#------------
=head2 get
Usage : $err->get($member, $delimiter);
Purpose : Get specific data from the Err.pm object.
Returns : String in scalar context.
: Array in list context.
Argument : $member = any of qw(msg type note tech stack context) or combination.
: $delimiter = optional string to be used as a delimiter
: between member data.
See Also : L(), L(), L(), L(), L(), L(), L()
=cut
#---------
sub get {
#---------
my( $self, $member, $delimiter ) = @_;
my $outer_delim = $delimiter || "\n";
# my $outer_delim = ($CGI ? "\n" : $delimiter); ## Subtle bug here.
my (@out);
local $_ = $member;
SWITCH: {
/type/i && do{ push (@out, $self->{'_type'},$outer_delim) };
# /msg/i && do{ print "getting msg";; push (@out, (defined $self->{'_msg'} ? $self->{'_msg'} : ''),$outer_delim); print "msg: @out<---";; };
/msg/i && do{ push (@out, (defined $self->{'_msg'} ? $self->{'_msg'} : ''),$outer_delim); };
/note/i && do{ push (@out, $self->_get_list_data('note', $delimiter ),$outer_delim) };
/tech/i && do{ push (@out, $self->_get_list_data('tech', $delimiter ),$outer_delim) };
/stack/i && do{ push (@out, $self->_get_list_data('stack', $delimiter ),$outer_delim) };
/context/i && do{ push (@out, $self->_get_list_data('context', $delimiter ),$outer_delim) };
## CAN'T USE THE FOLLOWING FORM SINCE IT FAILS WHEN $member EQUALS 'msgnote'.
# /note|tech|stack/ && do{ push @out, $self->_get_list_data( $_, $delimiter ); };
last SWITCH;
$self->warn("Invalid or undefined Err data member ($member).");
}
# $DEBUG && do{ print STDERR "OUTER DELIM = $outer_delim \nOUT: \n @out <---";;};
wantarray ? @out : join('',@out);
}
=head2 _get_list_data
Usage : n/a; internal method used by get()
Purpose : Gets data for members which are list refs (note, tech, stack, context)
Returns : Array
Argument : ($member, $delimiter)
See Also : L()
=cut
#-------------------
sub _get_list_data {
#-------------------
my( $self, $member, $delimiter ) = @_;
$delimiter ||= "\t";
# Sensitive to data member name changes.
$member = "_\l$member";
return if !defined $self->{$member};
join( $delimiter, @{$self->{$member}} );
}
=head2 get_all
Usage : (same as get())
Purpose : Get specific data from all errors in an Err.pm object.
Returns : Array in list context.
: String in scalar context.
Argument : (same as get())
See Also : L()
=cut
#------------
sub get_all {
#------------
my( $self, $member, $delimiter ) = @_;
if( $self->size() == 1) {
return $self->get( $member, $delimiter);
} else {
my $err = $self;
### Return data from multiple errors in a list.
if(wantarray) {
my @out;
do{ push @out, $err->get( $member);
} while($err = $err->prev());
return @out;
} else {
### Return data from multiple errors in a string with each error's data
### bracketed by a "Error #n\n" line and two delimiters.
my $out = '';
if($err->size() == 1) {
$out = $err->get( $member, $delimiter);
} else {
do{ #$out .= "Error #${\$err->rank()}$delimiter";
$out .= $err->get( $member, $delimiter);
$out .= $delimiter.$delimiter;
} while($err = $err->prev());
}
return $out;
}
}
}
#####################################################################################
## INSTANCE METHODS ##
#####################################################################################
=head2 _add_note
Usage : n/a; internal method called by _add_list_data()
Purpose : adds a new note.
See Also : L<_add_list_data>()
=cut
#---------------
sub _add_note {
#---------------
my( $self, $data ) = @_;
if( defined $self->{'_note'} ) {
push @{ $self->{'_note'}}, $data;
} else {
$self->_set_list_data('note', $data );
}
}
#----------------------------------------------------------------------
=head2 _add_tech()
Usage : n/a; internal method called by _add_list_data()
Purpose : adds a new technical note.
See Also : L<_add_list_data>()
=cut
#-------------
sub _add_tech {
#-------------
my( $self, $data ) = @_;
if( defined $self->{'_tech'} ) {
push @{ $self->{'_tech'}}, $data;
} else {
$self->_set_list_data('Tech', $data );
}
}
=head2 _add_list_data
Usage : n/a; called by _set_list_data()
Purpose : adds a new note or tech note.
See Also : L<_set_list_data>()
=cut
#--------------------
sub _add_list_data {
#--------------------
my( $self, $member, $data ) = @_;
local $_ = $member;
SWITCH: {
/note/i && do{ $self->_add_note( $data ); };
/tech/i && do{ $self->_add_tech( $data ); };
}
}
=head2 print
Usage : $err->print;
Purpose : Prints Err data to STDOUT or a FileHandle.
Returns : Call to print
Argument : Named parameters for string()
Comments : Uses string() to get data.
See Also : L()
=cut
#-----------
sub print {
#-----------
my( $self, %param ) = @_;
# my $OUT = $self->parent->fh();
# print $OUT $self->string(%param);
print $self->string(%param);
}
=head2 string
Usage : $err->string( %named_parameters);
Purpose : Stringify the data contained in the Err.pm object.
Example : print STDERR $err->string;
Returns : String
Argument : Named parameters (optional) passed to
: Bio::Root::IOManager::set_display().
See Also : L(), L<_build_from_string>(), B
=cut
#-----------
sub string {
#-----------
my( $self, @param ) = @_;
my %param = @param;
$self->set_display( @param );
my $show = $self->show;
my $out = $param{-BEEP} ? "\a" : '';
my $err = $param{-CURRENT} ? $self->last : $self->first;
# my $err1 = $err;
# my $errL = $self->last;
# print "\n\nERR 1: ${\$err1->msg}";
# print "\nERR L: ${\$errL->msg}";;
my $numerate = $err->size() >1;
my $count = 0;
my ($title);
my $hasnote = defined $self->{'_note'};
my $hastech = defined $self->{'_tech'};
while (ref $err) {
$count++;
# $out .= sprintf "\nERROR #%d:", $count;
if(not $title = $err->{'_type'}) {
$err = $err->next();
next;
}
if( $numerate) {
## The rank data is a bit screwy at present.
$out .= sprintf "\n%s %s %s\n", '-'x 20, $title,'-'x 20;
} else {
$out .= sprintf "\n%s %s %s\n", '-'x20, $title,'-'x20;
}
$show =~ /msg|default/i and $out .= "MSG: " . $err->msg("\n");
$show =~ /note|default/i and $hasnote and $out .= "NOTE: ".$err->note("\n");
$show =~ /tech|default/i and $hastech and $out .= "TECH: ".$err->tech("\n");
$show =~ /context|default/i and $out .= "CONTEXT: ".$err->context("\n");
$show =~ /stack|default/i and $out .= "STACK: \n".$err->stack("\n");
$out .= sprintf "%s%s%s\n",'-'x 20, '-'x (length($title)+2), '-'x 20;
# print "$ID: string: cumulative err:\n$out\n";;
$err = $err->next();
}
$out;
}
=head2 is_fatal
Usage : $err->is_fatal;
Purpose : Determine if the error is of type 'FATAL'
Returns : Boolean
Status : Experimental, Deprecated
=cut
#--------------
sub is_fatal { my $self = shift; $self->{'_type'} eq 'FATAL'; }
#--------------
#####################################################################################
## CLASS METHODS ##
#####################################################################################
=head2 throw
Usage : throw($object, [message], [note], [technical note]);
: This method is exported.
Purpose : Class method version of Bio::Root::Object::throw().
Returns : die()s with the contents of the Err object in a string.
: If the global strictness is less than -1, die is not called and
: the error is printed to STDERR.
Argument : [0] = object throwing the error.
: [1] = optional message about the error.
: [2] = optional note about the error.
: [3] = optional technical note about the error.
Comments : The glogal verbosity level is not used. For verbosity-sensitive
: behavior, use Bio::Root::Object::throw().
Status : Experimental
: This method is an alternative to Bio::Root::Object::throw()
: and is not as well developed or documented as that method.
See Also : L(), B B()
=cut
#----------
sub throw {
#----------
my($obj, @param) = @_;
# print "Throwing exception for object ${\ref $self} \"${\$self->name}\"\n";
my $err = new Bio::Root::Err(
-MSG =>$param[0],
-NOTE =>$param[1],
-TECH =>$param[2],
-STACK =>scalar(Bio::Root::Object::stack_trace($obj,2)),
-CONTEXT =>Bio::Root::Object::containment($obj),
-TYPE =>'EXCEPTION',
# -PARENT =>$obj,
);
if(strictness() < -1) {
print STDERR $err->string(-BEEP=>1) unless verbosity() < 0;
} else {
die $err->string;
}
0;
}
=head2 warning
Usage : warning($object, [message], [note], [technical note]);
: This method is exported.
Purpose : Class method version of Bio::Root::Object::warn().
Returns : Prints the contents of the error to STDERR and returns false (0).
: If the global strictness() is > 1, warn() calls are converted
: into throw() calls.
Argument : [0] = object producing the warning.
: [1] = optional message about the error.
: [2] = optional note about the error.
: [3] = optional technical note about the error.
:
Comments : The glogal verbosity level is not used. For verbosity-sensitive
: behavior, use Bio::Root::Object::warn().
Status : Experimental
: This method is an alternative to Bio::Root::Object::warn()
: and is not as well developed or documented as that method.
See Also : L, B, B
=cut
#-----------
sub warning {
#-----------
my($obj, @param) = @_;
# print "Throwing exception for object ${\ref $self} \"${\$self->name}\"\n";
my $err = new Bio::Root::Err(
-MSG =>$param[0],
-NOTE =>$param[1],
-TECH =>$param[2],
-STACK =>scalar(Bio::Root::Object::stack_trace($obj,2)),
-CONTEXT =>Bio::Root::Object::containment($obj),
-TYPE =>'WARNING',
# -PARENT =>$obj,
);
if(strictness() > 1) {
die $err->string;
} else {
print STDERR $err->string(-BEEP=>1) unless $DONT_WARN;
}
0;
}
=head2 format_stack_entry
Usage : &format_stack_entry(,,,,,)
: This function is exported.
Purpose : Creates a single stack entry given a caller() list.
Argument : List of scalars (output of the caller() method).
Returns : String = class_method($line)
: e.g., Bio::Root::Object::name(1234)
=cut
#------------------------
sub format_stack_entry {
#------------------------
my( $class, $file, $line, $classmethod, $hasargs, $wantarray) = @_;
# if($DEBUG) {
# print STDERR "format_stack_entry data:\n";
# foreach(@_) {print STDERR "$_\n"; } ;
# }
$classmethod ||= 'unknown class/method';
$line ||= 'unknown line';
return "$classmethod($line)";
}
1;
__END__
#####################################################################################
# END OF CLASS #
#####################################################################################
=head1 FOR DEVELOPERS ONLY
=head2 Data Members
Information about the various data members of this module is provided for those
wishing to modify or understand the code. Two things to bear in mind:
=over 4
=item 1 Do NOT rely on these in any code outside of this module.
All data members are prefixed with an underscore to signify that they are private.
Always use accessor methods. If the accessor doesn't exist or is inadequate,
create or modify an accessor (and let me know, too!).
=item 2 This documentation may be incomplete and out of date.
It is easy for this documentation to become obsolete as this module is still evolving.
Always double check this info and search for members not described here.
=back
An instance of Bio::Root::Err.pm is a blessed reference to a hash containing
all or some of the following fields:
FIELD VALUE
------------------------------------------------------------------------
_type fatal | warning | exception (one of @Bio::Root::Err::ERR_TYPES).
_msg Terse description: Main cause of error.
_note List reference. Verbose description: probable cause & troubleshooting for user.
_tech List reference. Technical notes of interest to programmer.
_stack List reference. Stack trace: list of "class::method(line number)" strings.
=cut
1;