Given the SSCCE below, Devel::Cover v1.40 shows missing "statement" coverage for a line of code that is being run:
#!perl use 5.012; # strict, // use warnings; { my $i = 1; my $j = 2; sub get { $i + $j; } } get();
and running with
perl -MDevel::Cover x.pl cover

why does it say only 90.9% coverage?

----- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ----- ------ ------ ------ ------ ------ ------ ------ x.pl 90.9 n/a n/a 100.0 n/a 100.0 92.8 Total 90.9 n/a n/a 100.0 n/a 100.0 92.8 ----- ------ ------ ------ ------ ------ ------ ------

The coverage report shows the following table:
linestmtbrancondsubpodtimecode
1#!perl
2
1
1
0
0
use 5.012; # strict, //
3
1
1
1
0
0
0
use warnings;
4
5{
6
1
0
0
0
    my $i = 1;
7
1
0
    my $j = 2;
8    sub get {
9
1
        $i + $j;
10    }
11}
12
1
1
74157
0
get();

... but I cannot see why line 6 has two rows in the table, or why it says that the second row for that line was never run; there's only one statement, as far as I can tell. Removing the  = 1 or changing the order of the declarations doesn't change the fact that the first row in that block claims to never run.

If I change to do { ... }; instead of just a block, then line 6 cleans up and only shows one row in the table, but now the line 4 do { shows it was run 0 times:

linestmtbrancondsubpodtimecode
1#!perl
2
1
1
5875
0
use 5.012; # strict, //
3
1
1
1
0
0
0
use warnings;
4
5
0
0
do {
6
1
0
    my $i = 1;
7
1
0
    my $j = 2;
8    sub get {
9
1
        $i + $j;
10    }
11
1
58427
};
12
1
0
get();

If I convert the block to a sub init { ... } and then call it with init(), then the sub init { line shows as uncovered statement, just like the do { version.

I can work around it by getting rid of the block, so eliminating the coverage-flag isn't a problem (but I want the block in my real code to encapsulate the my variables to be private just for my get function, so I'm not going to do that). Or I can cheat with # uncoverable statement count:2. But my curiosity has been piqued as to why I should need a workaround at all.


In reply to mystery: Devel::Cover showing missing statement coverage on a line that is being run by pryrt

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.