Subject: | unpack templates and older perl versions (pre 5.8) |
The attached patch file fixes a dependency on a perl 5.8 feature of pack/unpack.
It thus allows Plucene to remain backwards compatible to perl 5.6.1
The bug can be reproduced by running the unit tests (make;make test) using a perl version prior to 5.8
For more details see the bottom half of:
http://www.kasei.com/pipermail/plucene/2005-March/000339.html
and all of
http://www.kasei.com/pipermail/plucene/2005-April/000353.html
Note that this patch implements the "compile time folding", such that newer perls use the templating feature of unpack, where older perls figure it out the hard way.
46a47,48
> use constant PERL_VERSION => $];
>
185c187,199
< my @fields = unpack "w/(w/aC)", read_file($file->[1]);
---
> my @fields;
> # pack templates don't exist prior to 5.8
> # see perlpacktut.html section on Template-Grouping
> if (PERL_VERSION >= 5.008) {
> @fields = unpack "w/(w/aC)", read_file($file->[1]);
> }
> else {
> my $data = read_file($file->[1]);
> my $count = unpack "w", $data;
> my $template = "w" . ("w/a*C" x $count);
> my $null;
> ($null, @fields) = unpack $template, $data;
> }