Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Devel-Cover CPAN distribution.

Report information
The Basics
Id: 4366
Status: resolved
Priority: 0/
Queue: Devel-Cover

People
Owner: Nobody in particular
Requestors: sjs [...] khadrin.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.27
Fixed in: 0.33



Subject: Inheriting from Exporter causes errors
I have noticed this issue with the following components: Devel-Cover versions 0.26 and 0.27 Perl, v5.8.0 built for i386-linux-thread-multi Red Hat Linux 9 with kernel 2.4.20-20.9 Some version of Perl on some version of Cygwin (fairly up-to-date though) Modules that inherit from Exporter (@ISA = 'Exporter') seem to cause problems for Devel::Cover, as illustrated by the following: [sjs@cobra Foo]$ cat Foo.pm package Foo; use 5.008; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(is_3digits); sub is_3digits { my $val = shift; my $retval = undef; $retval=1 if $val =~ /^\d{3}$/; return $retval; } 1; [sjs@cobra Foo]$ cat foo.pl #!/usr/bin/perl use strict; use warnings; use lib qw(.); use Foo; is_3digits(1234); is_3digits(123); exit; [sjs@cobra Foo]$ Some (heavily trimmed) results: [sjs@cobra Foo]$ perl -MDevel::Cover foo.pl Devel::Cover: Writing coverage database to /home/sjs/foo/Foo/cover_db ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt branch cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ Foo.pm 100.00 75.00 n/a 100.00 n/a 76.57 92.86 foo.pl 100.00 n/a n/a n/a n/a 23.43 100.00 Total 100.00 75.00 n/a 100.00 n/a 100.00 94.12 ---------------------------- ------ ------ ------ ------ ------ ------ ------ [sjs@cobra Foo]$ Branches -------- line err % true false branch ----- --- ------ ------ ------ ------ 15 100 1 1 if $val =~ /^\d{3}$/ *** 50 0 2 if $val =~ /^\d{3}$/ Note the "***" under err. Comment out the @ISA line in Foo.pm, and prefix the calls to is_3digits() with Foo:: and the results look much better: [sjs@cobra Foo]$ perl -MDevel::Cover foo.pl Devel::Cover: Writing coverage database to /home/sjs/foo/Foo/cover_db ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt branch cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ Foo.pm 100.00 100.00 n/a 100.00 n/a 60.58 100.00 foo.pl 100.00 n/a n/a n/a n/a 39.42 100.00 Total 100.00 100.00 n/a 100.00 n/a 100.00 100.00 ---------------------------- ------ ------ ------ ------ ------ ------ ------ [sjs@cobra Foo]$ Branches -------- line err % true false branch ----- --- ------ ------ ------ ------ 15 100 1 1 if $val =~ /^\d{3}$/ There are some interesting differences in the coverage database between the two versions, but I couldn't make sense of them. The coverage database that 0.26 generates is a lot easier to read for humans.
From: sjs [...] khadrin.com
I was thinking about this issue a little bit more and decided it probably isn't Exporter per se, but rather that the function in question can be referenced from two different packages. I remember reading somewhere that Devel::Cover is doing something with the compiled parse tree and mapping the results back to the original code. I can't seem to find that info now though. Anyway, below is a script that demonstrates the same behavior but manipulates the symbol tables directly: [sjs@cobra foo]$ cat foo #!/usr/bin/perl use strict; use warnings; package Foo; sub is_3digits { my $val = shift; my $retval = undef; $retval=1 if $val =~ /^\d{3}$/; return $retval; } package main; *main::is_3digits = *Foo::is_3digits; #delete $Foo::{is_3digits}; is_3digits(1234); is_3digits(123); exit; [sjs@cobra foo]$ Devel::Cover has problems with the script as shown. Uncomment the line that starts "#delete" and things work much better. Yep, that delete does remove the function from the package it was originally defined in.
Thanks very much for the report and test cases. The bug is now fixed and both test cases added to the test suite.