| Bio-Phylo documentation | Contained in the Bio-Phylo distribution. |
Bio::Phylo::Util::StackTrace - Stack traces for exceptions
use Bio::Phylo::Util::StackTrace; my $trace = Bio::Phylo::Util::StackTrace->new; print $trace->as_string;
This is a simple stack trace object that is used by Bio::Phylo::Util::Exceptions. At the moment of its instantiation, it creates a full list of all frames in the call stack (except those originating from with the exceptions class). These can subsequently be stringified by calling as_string().
(If you have no idea what any of this means, don't worry: this class is mostly for internal usage. You can probably ignore this safely.)
Stack trace object constructor.
Type : Constructor
Title : new
Usage : my $trace = Bio::Phylo::Util::StackTrace->new
Function: Instantiates a Bio::Phylo::Util::StackTrace
object.
Returns : A Bio::Phylo::Util::StackTrace.
Args : None
Creates a string representation of the stack trace
Type : Serializer Title : as_string Usage : print $trace->as_string Function: Creates a string representation of the stack trace Returns : String Args : None
The stack trace object is used internally by the exception classes.
Also see the manual: Bio::Phylo::Manual and http://rutgervos.blogspot.com.
If you use Bio::Phylo in published research, please cite it:
Rutger A Vos, Jason Caravas, Klaas Hartmann, Mark A Jensen and Chase Miller, 2011. Bio::Phylo - phyloinformatic analysis using Perl. BMC Bioinformatics 12:63. http://dx.doi.org/10.1186/1471-2105-12-63
$Id: StackTrace.pm 1593 2011-02-27 15:26:04Z rvos $
| Bio-Phylo documentation | Contained in the Bio-Phylo distribution. |
package Bio::Phylo::Util::StackTrace; use strict;
sub new { my $class = shift; my $self = []; my $i = 0; my $j = 0; package DB; # to get @_ stack from previous frames, see perldoc -f caller while ( my @frame = caller($i) ) { my $package = $frame[0]; if ( not Bio::Phylo::Util::StackTrace::_skip_me($package) ) { my @args = @DB::args; $self->[ $j++ ] = [ @frame, @args ]; } $i++; } package Bio::Phylo::Util::StackTrace; shift @$self; # to remove "throw" frame return bless $self, $class; } sub _skip_me { my $class = shift; my $skip = 0; if ( $class->isa('Bio::Phylo::Util::Exceptions') ) { $skip++; } if ( $class->isa('Bio::Phylo::Util::ExceptionFactory') ) { $skip++; } return $skip; }
sub as_string { my $self = shift; my $string = ""; for my $frame (@$self) { my $method = $frame->[3]; my @args; for my $i ( 10 .. $#{$frame} ) { push @args, $frame->[$i]; } my $file = $frame->[1]; my $line = $frame->[2]; $string .= $method . "(" . join( ', ', map { "'$_'" } grep { $_ } @args ) . ") called at $file line $line\n"; } return $string; }
1;