Subject: | Missing DESTROY method / install tests fail |
(Also seen at http://www.issociate.de/board/goto/465877/problem_with_Barcode::Code128.html )
I unpacked Barcode-Code128-2.00.tar.gz from CPAN, and tried to build. The tests for install fail as follows,
deskpro261[mca]46: cd Barcode-Code128-2.00
deskpro261[mca]47: ls
Changes lib Makefile.PL MANIFEST README t
deskpro261[mca]48: perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Barcode::Code128
deskpro261[mca]49: make test
cp lib/Barcode/Code128.pm blib/lib/Barcode/Code128.pm
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/barcode....ok 2/2 (in cleanup) Unrecognized option (destroy) for Barcode::Code128 at t/barcode.t line 0
t/barcode....ok
t/gif........ok 1/0skipped
all skipped: no reason given
t/png........NOK 2 (in cleanup) Unrecognized option (destroy) for Barcode::Code128 at t/png.t line 0
t/png........FAILED test 2
Failed 1/2 tests, 50.00% okay
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/png.t 2 1 50.00% 2
1 test skipped.
Failed 1/3 test scripts, 66.67% okay. 0/4 subtests failed, 100.00% okay.
make: *** [test_dynamic] Error 255
deskpro261[mca]50: uname -a
Linux deskpro261 2.6.8-2-686 #1 Mon Jan 24 03:58:38 EST 2005 i686 GNU/Linux
deskpro261[mca]51: cat /etc/debian_version
3.1
deskpro261[mca]52: dpkg -s perl
[...]
Version: 5.8.4-8
[...]
This because the object destructor DESTROY is being interpretted by AUTOLOAD as an option. The CPAN installer will correctly install the module if you tell it "force install Barcode::Code128".
Here's a fix to v2.00 that might be suitable for distribution,
deskpro261[mca]59: diff -u lib/Barcode/Code128.pm{~,}
--- lib/Barcode/Code128.pm~ 2001-05-28 22:39:54.000000000 +0100
+++ lib/Barcode/Code128.pm 2005-09-30 12:16:58.000000000 +0100
@@ -286,6 +286,7 @@
my($self, @args) = @_;
use vars qw($AUTOLOAD);
(my $opt = lc $AUTOLOAD) =~ s/^.*:://;
+ return if $opt eq 'destroy';
$self->option($opt, @args);
}
In my code using this module I took a patch-it approach, but this is rather fragile:
sub _barcode_pattern {
my ($widg, $data) = @_;
my $bc = Barcode::Code128->new();
[...]
my $str = $bc->barcode($data); # string /^[ #]+$/ for light & dark stripes
undef $bc;
# Barcode::Code128 v2.00 thinks DESTROY is an invalid
# configuration option, and therefore croaks in its own
# destructor. Null implementation provided below.
return $str;
}
# Trickery to fix croaking noise, see above
BEGIN {
no strict 'refs';
die "About to replace Barcode::Code128::DESTROY - ok in v2.00 but this is $Barcode::Code128::VERSION"
if *{"Barcode::Code128::DESTROY"}{CODE};
}
sub Barcode::Code128::DESTROY { }
I add the null DESTROY method prevents AUTOLOAD being called, after first checking that I'm not replacing some existing code.