I'd guess it is because you are seeing the output of the code after it has been compiled-then-decompiled - it is compiled so it can run and coverage statistics can be collected, then it is decompiled to relate coverage stats to code lines. Now there are many ways to write code that compiles to the same compiled form, but the decompiler (I imagine it is B::Deparse) only decompiles those symbols one way.

As a test, you could change those two lines in Text::Template to be the same as what you are seeing in the coverage HTML, run the make test and cover again and see them unchanged.

Or more directly


=========== deparse.pl =========== #!/usr/bin/perl -w

use strict;

my $self;

$self->{DATA_ACQUIRED} = 1;
+++++++++++
end deparse.pl
+++++++++++

prompt> perl -MO=Deparse deparse.pl
BEGIN { $^W = 1; }
use strict 'refs';
my $self;
$$self{'DATA_ACQUIRED'} = 1;
deparse.pl syntax OK

===========
deparse2.pl
===========
#!/usr/bin/perl -w

use strict;

my $self;

$$self{DATA_ACQUIRED} = 1;
+++++++++++
end deparse2.pl
+++++++++++

prompt> perl -MO=Deparse deparse2.pl
[EMAIL PROTECTED] perl]$ perl -MO=Deparse deparse2.pl
BEGIN { $^W = 1; }
use strict 'refs';
my $self;
$$self{'DATA_ACQUIRED'} = 1;
deparse2.pl syntax OK

Leif

[EMAIL PROTECTED] wrote:

I have just noticed an anomalous difference in output between two of the files created by the Devel::Cover 'cover' utility when run against a popular Perl module -- and I am wondering whether this difference should be considered a feature or a bug.

The module in question is Text::Template, which I am studying as part of Perl Seminar NY's contribution to the Phalanx project. Start with a copy of Text-Template-1.44 (the latest on CPAN) and examine the code. In 'lib/Text/Template.pm', consider these two lines:

  128    $self->_acquire_data unless $self->{DATA_ACQUIRED};

  450        if (! defined $val) {

Proceed in the normal manner:

  perl Makefile.PL
  make
  cover -delete
  HARNESS_PERL_SWITCHES=-MDevel::Cover make test
  cover

... 'cover' creates a number of HTML files, including these two:

  ./Text-Template-1.44/cover_db/blib-lib-Text-Template-pm.html
  ./Text-Template-1.44/cover_db/blib-lib-Text-Template-pm--branch.html

'blib-lib-Text-Template-pm.html' displays lines 128 and 450 exactly as they appear in the module itself. 'blib-lib-Text-Template-pm--branch.html', however, displays the relevant branch part of these lines of code as follows:

  128  unless $$self{'DATA_ACQUIRED'}

  450  if (not defined $val) { }

'$self->{DATA_ACQUIRED}' is changed to '$$self{'DATA_ACQUIRED'}' and '! defined $val' is changed to 'not defined $val'. (I could site other examples as well, but these suffice to illustrate the point.)

Now, I grant that these are merely displays, not live code. Nonetheless, since the purpose of these HTML files is to guide a programmer to lines of code whose test coverage needs improvement, I am puzzled as to why the output in these two files differs.

Jim Keenan

Reply via email to