I am seeing some weird behavior where Devel::Cover seems to be removing/consuming information I am trying to extract with caller(). I have managed to isolate the behavior in a small script, which is included below. Anyone else seen this problem before?
Here is the script:
And here is the output of that script#!/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;
Am I doing something wrong? Or is this a limitation of Devel::Cover? Any thoughts? Does this have something to do with Devel::Cover's use of the runops function maybe?[:~] 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 ---------------------------- ------ ------ ------ ------ ------ ------ + ------
I have asked this over at the perl-qa list as well, but I thought it would be useful to ask it here too.
In reply to Devel::Cover eating caller() information by stvn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |