#!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; { package TestCaller; use strict; use warnings; sub throw { my $self = bless {}, __PACKAGE__; my $i = 0; my @stack_trace; push @stack_trace, [ (caller($i))[0 .. 3] ] while caller(++$i); $self->{stack_trace} = \@stack_trace; die $self; } } eval { throw TestCaller }; isa_ok($@, 'TestCaller'); is_deeply($@->{stack_trace}, [[ 'main', 'test.pl', 24, '(eval)']], '... got the stack trace we expected'); 1; #### [:~] stevan% perl test.pl 1..2 ok 1 - The object isa TestCaller ok 2 - ... got the stack trace we expected [:~] stevan% perl -MDevel::Cover test.pl 1..2 Devel::Cover 0.47: Collecting coverage data for branch, condition, pod, statement, subroutine and time. Selecting packages matching: Ignoring packages matching: /Devel/Cover[./] Ignoring packages in: . /Library/Perl /Library/Perl/darwin /Users/stevan/Projects/PerlFramework ok 1 - The object isa TestCaller not ok 2 - ... got the stack trace we expected # Failed test (test.pl at line 27) # Structures begin differing at: # $got->[0][0] = Does not exist # $expected->[0][0] = 'main' # Looks like you failed 1 tests of 2. Devel::Cover: Writing coverage database to /Users/stevan/cover_db/runs/1094834470.5906.15059 ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt branch cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ test.pl 100.0 n/a n/a 100.0 n/a 100.0 100.0 Total 100.0 n/a n/a 100.0 n/a 100.0 100.0 ---------------------------- ------ ------ ------ ------ ------ ------ ------