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.