[Module-build-general] _build/cleanup corruption
Status: Beta
Brought to you by:
kwilliams
|
From: Uri G. <ur...@st...> - 2003-08-30 06:53:47
|
in playing with build i seemed to have corrupted the _build/cleanup
file. i don't know how it happened but i was installing various versions
of module::build to see why recursive test finding stopped working. .19
did it and .20 didn't by default. this was posted here by schwern just
before.
the problem with the corruption of the cleanup file was finding which
file was broken.
i was getting this lovely output:
Build
Bareword found where operator expected at (eval 9) line 4, near "}
blib"
(Missing operator before blib?)
syntax error at (eval 9) line 6, near "}
blib
running under -d helped me to locate it.
Bareword found where operator expected at (eval 11)[/usr/local/lib/perl5/site_perl/5.6.1/Module/Build/Base.pm:480] line 4, near "}
blib"
this is the fun code:
sub _persistent_hash_restore {
my ($self, $name) = @_;
my $ph = $self->{phash}{$name} ||= {disk => {}, new => {}};
my $file = $self->config_file($name) or die "No config file '$name'";
my $fh = IO::File->new("< $file") or die "Can't read $file: $!";
$ph->{disk} = eval do {local $/; <$fh>};
die $@ if $@;
}
if the eval fails it should print $@ and also name the corrupted file.
also i notice the slurp idiom there. if you care about speed (and build
seems slow enough at it is), then use a faster slurp technique. in fact
i am writing an article for perl.com on slurping and i will be posting
to cpan a module for this. but you can just use this and it will be much
faster:
sub read_file {
my( $file_name ) = shift ;
local( *FH ) ;
open( FH, $file_name ) || die "can't open $file_name $!" ;
return <FH> if wantarray ;
my $buf ;
sysread( FH, $buf, -s FH ) ;
return $buf ;
}
and replace the last three lines with:
$ph->{disk} = eval read_file( $file );
die "$@\ncorrupted file: $file\n" if $@;
in finding this bug, i see plenty of other ways to speed up the code and
clean it up some. maybe i will do some code review and patches. :)
having fun with build finally,
uri
--
Uri Guttman ------ ur...@st... -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
|