From: Jarkko Hietaniemi Date: Sat, 31 May 2003 05:28:56 +0000 (+0000) Subject: Upgrade to Tie::File 0.96. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29aee836bb3b584432697a769829ca79c9a751c8;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Tie::File 0.96. p4raw-id: //depot/perl@19643 --- diff --git a/lib/Tie/File.pm b/lib/Tie/File.pm index 678e739..f32bf23 100644 --- a/lib/Tie/File.pm +++ b/lib/Tie/File.pm @@ -7,7 +7,7 @@ use Fcntl 'O_CREAT', 'O_RDWR', 'LOCK_EX', 'LOCK_SH', 'O_WRONLY', 'O_RDONLY'; sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY } -$VERSION = "0.95"; +$VERSION = "0.96"; my $DEFAULT_MEMORY_SIZE = 1<<21; # 2 megabytes my $DEFAULT_AUTODEFER_THRESHHOLD = 3; # 3 records my $DEFAULT_AUTODEFER_FILELEN_THRESHHOLD = 65536; # 16 disk blocksful @@ -901,8 +901,7 @@ sub _read_record { $rec = <$fh>; } return unless defined $rec; - if (! $self->{sawlastrec} && - substr($rec, -$self->{recseplen}) ne $self->{recsep}) { + if (substr($rec, -$self->{recseplen}) ne $self->{recsep}) { # improperly terminated final record --- quietly fix it. # my $ac = substr($rec, -$self->{recseplen}); # $ac =~ s/\n/\\n/g; @@ -1994,7 +1993,7 @@ Tie::File - Access the lines of a disk file via a Perl array =head1 SYNOPSIS - # This file documents Tie::File version 0.95 + # This file documents Tie::File version 0.96 use Tie::File; tie @array, 'Tie::File', filename or die ...; @@ -2304,6 +2303,11 @@ internally. If you passed it a filehandle as above, you "own" the filehandle, and are responsible for closing it after you have untied the @array. +Note that Tie::File will only close any filehandles that it opened +internally. If you passed it a filehandle as above, you "own" the +filehandle, and are responsible for closing it after you have untied +the @array. + =head1 Deferred Writing (This is an advanced feature. Skip this section on first reading.) @@ -2517,7 +2521,7 @@ any news of importance, will be available at =head1 LICENSE -C version 0.95 is copyright (C) 2002 Mark Jason Dominus. +C version 0.96 is copyright (C) 2002 Mark Jason Dominus. This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself. @@ -2545,7 +2549,7 @@ For licensing inquiries, contact the author at: =head1 WARRANTY -C version 0.95 comes with ABSOLUTELY NO WARRANTY. +C version 0.96 comes with ABSOLUTELY NO WARRANTY. For details, see the license. =head1 THANKS @@ -2567,7 +2571,9 @@ optimizations. Additional thanks to: Edward Avis / Mattia Barbon / +Tom Christiansen / Gerrit Haase / +Gurusamy Sarathy / Jarkko Hietaniemi (again) / Nikola Knezevic / John Kominetz / diff --git a/lib/Tie/File/t/00_version.t b/lib/Tie/File/t/00_version.t index 9285257..68e13ff 100644 --- a/lib/Tie/File/t/00_version.t +++ b/lib/Tie/File/t/00_version.t @@ -2,7 +2,7 @@ print "1..1\n"; -my $testversion = "0.95"; +my $testversion = "0.96"; use Tie::File; if ($Tie::File::VERSION != $testversion) { diff --git a/lib/Tie/File/t/09_gen_rs.t b/lib/Tie/File/t/09_gen_rs.t index 7d70e3e..c1ef740 100644 --- a/lib/Tie/File/t/09_gen_rs.t +++ b/lib/Tie/File/t/09_gen_rs.t @@ -1,8 +1,9 @@ #!/usr/bin/perl +use lib '/home/mjd/src/perl/Tie-File2/lib'; my $file = "tf$$.txt"; -print "1..58\n"; +print "1..59\n"; my $N = 1; use Tie::File; @@ -128,7 +129,7 @@ if (setup_badly_terminated_file(4)) { check_contents("x", "y"); } -# (57-58) 20020402 The modifiaction would have failed if $\ were set wrong. +# (57-58) 20020402 The modification would have failed if $\ were set wrong. # I hate $\. if (setup_badly_terminated_file(2)) { $o = tie @a, 'Tie::File', $file, @@ -140,6 +141,23 @@ if (setup_badly_terminated_file(2)) { check_contents($badrec); } +# (59) 20030527 Tom Christiansen pointed out that FETCH returns the wrong +# data on the final record of an unterminated file if the file is opened +# in read-only mode. Note that the $#a is necessary here. +# There's special-case code to fix the final record when it is read normally. +# But the $#a forces it to be read from the cache, which skips the +# termination. +$badrec = "world\nhello"; +if (setup_badly_terminated_file(1)) { + tie(@a, "Tie::File", $file, mode => 0, recsep => $RECSEP) + or die "Couldn't tie file: $!"; + my $z = $#a; + $z = $a[1]; + print $z eq "hello" ? "ok $N\n" : + "not ok $N \# got $z, expected hello\n"; + $N++; +} + sub setup_badly_terminated_file { my $NTESTS = shift; open F, "> $file" or die "Couldn't open $file: $!";