Devel::CallerStack - Object-Oriented call stack and iterator.
Devel-CallerStack is an object-oriented interface to the call stack. When constructed it will build a callstack and provide you access and filtration methods. Each element of the stack is an instance of Devel::CallerStack::Level.
use Devel::CallerStack qw/caller_stack/; my $stack = Devel::CallerStack->new(); # or my $stack = caller_stack(); # Get all callers my @callers = $stack->all_list(); # Limit to specific callers: $stack->filter( 'line', 100 ); $stack->filter( 'subroutine', qr/mysub$/ ); $stack->filter( 'package', 'My::Package' ); my @specific_callers = $stack->filtered_list() # As an iterator while ( my $level = $stack->next ) { ... } 1;
Nothing is exported by default. However caller_stack() can be imported.
Shortcut for Devel::CallerStack->new();
Builds a new caller stack.
The following will always return the complete unfiltered caller stack.
Return a reference to the actual array of caller levels. Each item will be an instance of Devel::CallerStack::Level.
Return a list of caller levels. Each item will be an instance of Devel::CallerStack::Level.
You can apply filters that will remove any levels from the stack that do not match given check against it's attributes. You can apply multiple filters, each will filter the remaining results from the previous filter.
Filter the stack so that only levels where the given attribute matches the given check will be listed. $attribute should be the name of a caller attribute (See Devel::CallerStack::Level). $check may be a string against which to compare, a regex, or a coderef.
NOTE: When called in list context it will return the filtered results, but will not modify the object in any way. In any other context the filter will be applied to the object itself.
filter() returns $self in scalar context making the call chainable.
Filter out any levels where the package is not an instance of 'Wanted::Package':
$stack->filter( 'package', sub { my $package = shift; $package->isa( 'Wanted::Package' ); });
Get a reference to the actual list of callers remaining after filters have been applied. Each element is an instance of Devel::CallerStack::Level.
Get a list of callers remaining after filters have been applied. Each element is an instance of Devel::CallerStack::Level.
Returns true if filters have been applied
Removes all filters. unfilter() returns $self in scalar context making the call chainable.
Return an arrayref containing $attribute from each stack element.
The caller stack is an array of Devel::CallerStack::Level items progressing from the most recent caller to the most distant.
Return the most recent caller.
Returns the next most recent caller, and increments the index. Returns undef at the end of the stack.
The reverse of next, used to go backwords.
Return the most distant caller.
Returns the index of the iterator
Resets the iterator to index 0.
Return the most recent call from the specified package.
Return the most distant call from the specified package.
Return all the calls from a given package.
This module is part of the Fennec project. See Fennec for more details. Fennec is a project to develop an extendable and powerful testing framework. Together the tools that make up the Fennec framework provide a potent testing environment.
The tools provided by Fennec are also useful on their own. Sometimes a tool created for Fennec is useful outside the greator framework. Such tools are turned into their own projects. This is one such project.
The primary Fennec project that ties them all together.
Chad Granum exodist7@gmail.com
Copyright (C) 2010 Chad Granum
Devel-CallerStack is free software; Standard perl licence.
Devel-CallerStack is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
To install Devel::CallerStack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::CallerStack
CPAN shell
perl -MCPAN -e shell install Devel::CallerStack
For more information on module installation, please visit the detailed CPAN module installation guide.