Skip to content

Commit

Permalink
Tie::File: remove 5.005 compatibility code
Browse files Browse the repository at this point in the history
- Ever since 5926ffc, Tie::File has been using warnings.pm and
  'our', making the code incompatible with 5.005 ('use warnings'
  wouldn't even compile anymore), so remove the old compatibility
  code.
- Update code for v5.8 (the "Unknown discipline" error from v5.6 was
  changed to "IO layers (...) unavailable" then).
- 'use constant' to declare constants.
- Remove redundant 'use strict "vars"' (the whole file is under 'use
  strict').
  • Loading branch information
mauke committed Feb 27, 2024
1 parent 5719985 commit ed37371
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
3 changes: 3 additions & 0 deletions dist/Tie-File/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ WriteMakefile(
MailingList => 'http://lists.perl.org/list/perl5-porters.html',
},
},
PREREQ_PM => {
'constant' => '1.03',
},
);
# generated by Makepmdist (mkpmdist) v1.01

Expand Down
44 changes: 19 additions & 25 deletions dist/Tie-File/lib/Tie/File.pm
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package Tie::File;

require 5.005;

use strict;
use warnings;

use Carp ':DEFAULT', 'confess';
use POSIX 'SEEK_SET';
use Fcntl 'O_CREAT', 'O_RDWR', 'LOCK_EX', 'LOCK_SH', 'O_WRONLY', 'O_RDONLY';
sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY }
use constant O_ACCMODE => O_RDONLY | O_RDWR | O_WRONLY;


our $VERSION = "1.08";
our $VERSION = "1.09";
my $DEFAULT_MEMORY_SIZE = 1<<21; # 2 megabytes
my $DEFAULT_AUTODEFER_THRESHHOLD = 3; # 3 records
my $DEFAULT_AUTODEFER_FILELEN_THRESHHOLD = 65536; # 16 disk blocksful
Expand Down Expand Up @@ -106,21 +104,14 @@ sub TIEARRAY {
} elsif (ref $file) {
croak "usage: tie \@array, $pack, filename, [option => value]...";
} else {
# $fh = \do { local *FH }; # XXX this is buggy
if ($] < 5.006) {
# perl 5.005 and earlier don't autovivify filehandles
require Symbol;
$fh = Symbol::gensym();
}
sysopen $fh, $file, $opts{mode}, 0666 or return;
binmode $fh;
++$opts{ourfh};
}
{ my $ofh = select $fh; $| = 1; select $ofh } # autoflush on write
if (defined $opts{discipline} && $] >= 5.006) {
# This avoids a compile-time warning under 5.005
eval 'binmode($fh, $opts{discipline})';
croak $@ if $@ =~ /unknown discipline/i;
if (defined $opts{discipline}) {
eval { binmode($fh, $opts{discipline}) };
croak $@ if $@ =~ /Unknown discipline|IO layers .* unavailable/;
die if $@;
}
$opts{fh} = $fh;
Expand Down Expand Up @@ -1451,14 +1442,15 @@ package Tie::File::Cache;
$Tie::File::Cache::VERSION = $Tie::File::VERSION;
use Carp ':DEFAULT', 'confess';

sub HEAP () { 0 }
sub HASH () { 1 }
sub MAX () { 2 }
sub BYTES() { 3 }
#sub STAT () { 4 } # Array with request statistics for each record
#sub MISS () { 5 } # Total number of cache misses
#sub REQ () { 6 } # Total number of cache requests
use strict 'vars';
use constant {
HEAP => 0,
HASH => 1,
MAX => 2,
BYTES => 3,
#STAT => 4, # Array with request statistics for each record
#MISS => 5, # Total number of cache misses
#REQ => 6, # Total number of cache requests
};

sub new {
my ($pack, $max) = @_;
Expand Down Expand Up @@ -1740,9 +1732,11 @@ sub delink {
package Tie::File::Heap;
use Carp ':DEFAULT', 'confess';
$Tie::File::Heap::VERSION = $Tie::File::Cache::VERSION;
sub SEQ () { 0 };
sub KEY () { 1 };
sub DAT () { 2 };
use constant {
SEQ => 0,
KEY => 1,
DAT => 2,
};

sub new {
my ($pack, $cache) = @_;
Expand Down

0 comments on commit ed37371

Please sign in to comment.