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:

#!/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;
And here is the output of that script
[:~] 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 ---------------------------- ------ ------ ------ ------ ------ ------ + ------
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?

I have asked this over at the perl-qa list as well, but I thought it would be useful to ask it here too.

-stvn

In reply to Devel::Cover eating caller() information by stvn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.