Skip to content

Commit

Permalink
Bump min perl to 5.12
Browse files Browse the repository at this point in the history
This gets us a few small wins like `package NAME VER` syntax, implicit
strictures, defined-or, and builtin `version`.

5.12 was released over a decade okay so should be plenty safe to depend
on by now.

Requiring 5.12 also lets us depend on Compress::Zlib which lets us
simplify the logic around setting default compress methods.

All in all some nice simplifications come out of requiring a slightly
newer perl.
  • Loading branch information
JRaspass committed Nov 2, 2021
1 parent 490cbc4 commit 624a612
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:

# All supported Perl versions except latest.
perl: [
'5.8', '5.10', '5.12', '5.14', '5.16', '5.18', '5.20', '5.22',
'5.24', '5.26', '5.28', '5.30', '5.32'
'5.12', '5.14', '5.16', '5.18', '5.20', '5.22', '5.24', '5.26',
'5.28', '5.30', '5.32'
]

# Variants of the latest Perl.
Expand Down
4 changes: 1 addition & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use strict;
use v5.12;
use warnings;

use ExtUtils::MakeMaker;
Expand All @@ -13,7 +13,6 @@ my %args = (
PREREQ_PM => {
'Carp' => '1.25', # For trailing dot.
'XSLoader' => '0.14', # For XSLoader::load with no arguments.
'perl' => '5.008',
},
VERSION_FROM => 'lib/Cache/Memcached/Fast.pm',
META_MERGE => {
Expand All @@ -28,7 +27,6 @@ my %args = (
},
TEST_REQUIRES => {
'Test2::Suite' => '0.000072', # For Test2::V0.
'version' => '0.77', # For version->parse.
},
);

Expand Down
2 changes: 0 additions & 2 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
requires 'Carp' => '1.25'; # For trailing dot.
requires 'XSLoader' => '0.14'; # For XSLoader::load with no arguments.
requires 'perl' => '5.008';

on test => sub {
requires 'Test2::Suite' => '0.000072'; # For Test2::V0.
requires 'version' => '0.77'; # For version->parse.
};

on develop => sub {
Expand Down
36 changes: 14 additions & 22 deletions lib/Cache/Memcached/Fast.pm
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package Cache::Memcached::Fast;
package Cache::Memcached::Fast 0.27;

use strict;
use v5.12;
use warnings;

use Carp ();
use Carp ();
use Compress::Zlib ();
use Storable;
use XSLoader;

our $VERSION = '0.27';

my %instance;
my %known_args = map { $_ => 1 } qw(
check_args close_on_error compress_algo compress_methods compress_ratio
Expand All @@ -20,7 +19,7 @@ my %known_args = map { $_ => 1 } qw(
sub new {
my ( $class, $conf ) = @_;

unless ( lc( $conf->{check_args} || '' ) eq 'skip' ) {
unless ( lc( $conf->{check_args} // '' ) eq 'skip' ) {
Carp::carp 'compress_algo was removed in 0.08, use compress_methods'
if exists $conf->{compress_algo};

Expand All @@ -30,23 +29,16 @@ sub new {
}
}

if ( not $conf->{compress_methods}
and defined $conf->{compress_threshold}
and $conf->{compress_threshold} >= 0
and eval { require Compress::Zlib } )
{
# Note that the functions below can't return false when
# operation succeed. This is because "" and "0" compress to a
# longer values (because of additional format data), and
# compress_ratio will force them to be stored uncompressed,
# thus decompression will never return them.
$conf->{compress_methods} = [
sub { ${ $_[1] } = Compress::Zlib::memGzip( ${ $_[0] } ) },
sub { ${ $_[1] } = Compress::Zlib::memGunzip( ${ $_[0] } ) }
];
}
# Note that the functions below can't return false when operation succeed.
# This is because "" and "0" compress to a longer values (because of
# additional format data), and compress_ratio will force them to be stored
# uncompressed, thus decompression will never return them.
$conf->{compress_methods} //= [
sub { ${ $_[1] } = Compress::Zlib::memGzip( ${ $_[0] } ) },
sub { ${ $_[1] } = Compress::Zlib::memGunzip( ${ $_[0] } ) },
];

$conf->{serialize_methods} ||= [ \&Storable::nfreeze, \&Storable::thaw ];
$conf->{serialize_methods} //= [ \&Storable::nfreeze, \&Storable::thaw ];

my $memd = $class->_new($conf);

Expand Down
25 changes: 11 additions & 14 deletions script/benchmark.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# or, at your option, any later version of Perl 5 you may have
# available.
#
use v5.12;
use warnings;
use strict;

# NOTE: at least on Linux (kernel 2.6.18.2) there is a certain
# artifact that affects wallclock time (but not CPU time) of some
Expand All @@ -28,6 +28,8 @@

my $value = 'x' x 40;

use Cache::Memcached::Fast;
use Benchmark qw(:hireswallclock timethese cmpthese timeit timesum timestr);
use FindBin;

die <<HELP unless @ARGV;
Expand All @@ -40,18 +42,13 @@
Cache::Memcached.
HELP

my $compare = ( $ARGV[$#ARGV] =~ /^compare$/ );
pop @ARGV if $compare;
pop @ARGV if my $compare = $ARGV[-1] eq 'compare';

my $count
= ( $ARGV[$#ARGV] =~ /^\d+$/ ? pop @ARGV : default_iteration_count );
my $count = $ARGV[-1] =~ /^\d+$/ ? pop @ARGV : default_iteration_count;
my $max_keys = $count * key_count / 2;

my @addrs = @ARGV;

use Cache::Memcached::Fast;
use Benchmark qw(:hireswallclock timethese cmpthese timeit timesum timestr);

my $old;
my $old_method = qr/^(?:add|set|replace|incr|decr|delete|get)$/;
my $old_method_multi = qr/^get$/;
Expand Down Expand Up @@ -133,15 +130,15 @@ sub merge_hash {
sub bench_finalize {
my ( $title, $code, $finalize ) = @_;

print "Benchmark: timing $count iterations of $title...\n";
say "Benchmark: timing $count iterations of $title...";
my $b1 = timeit( $count, $code );

# We call nowait_push here. Otherwise the time of gathering
# the results would be added to the following commands.
my $b2 = timeit( 1, $finalize );

my $res = timesum( $b1, $b2 );
print "$title: ", timestr( $res, 'auto' ), "\n";
say "$title: ", timestr( $res, 'auto' );

return { $title => $res };
}
Expand Down Expand Up @@ -303,10 +300,10 @@ sub run {
[ delete => \&run, 0 ],
);

print "Servers: @{[ keys %$version ]}\n";
print "Iteration count: $count\n";
print 'Keys per iteration: ', key_count, "\n";
print 'Value size: ', length($value), " bytes\n";
say "Servers: @{[ keys %$version ]}";
say "Iteration count: $count";
say 'Keys per iteration: ', key_count;
say 'Value size: ', length($value), ' bytes';

srand(1);
foreach my $args (@methods) {
Expand Down
12 changes: 5 additions & 7 deletions script/c-m-compat.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
# or, at your option, any later version of Perl 5 you may have
# available.
#
use v5.12;
use warnings;
use strict;

# NOTE: this test uses INSTANCE_COUNT x 2 file descriptors. This
# means that normally spawning more than ~500 instances won't work.

use Cache::Memcached::Fast;
use Cache::Memcached;
use FindBin;

@ARGV >= 3
Expand All @@ -23,13 +25,9 @@
$seed = time unless defined $seed;
srand($seed);

print "Instances: $instance_count, keys: $key_count, random seed: $seed\n";

my $host = '127.3.5.7';

use Cache::Memcached::Fast;
use Cache::Memcached;
say "Instances: $instance_count, keys: $key_count, random seed: $seed";

my $host = '127.3.5.7';
my $max_port = $min_port + $instance_count - 1;
my @children;

Expand Down
15 changes: 7 additions & 8 deletions script/ketama-distr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# or, at your option, any later version of Perl 5 you may have
# available.
#
use v5.12;
use warnings;
use strict;

=head1 NAME
Expand Down Expand Up @@ -39,6 +39,7 @@ =head1 OPTIONS

use Getopt::Long qw(:config gnu_getopt);
use Pod::Usage;
use String::CRC32;

my %options;
if ( !GetOptions( \%options, qw(ketama_points|k=i server|s=s@) )
Expand All @@ -50,8 +51,6 @@ =head1 OPTIONS
pod2usage(1);
}

use String::CRC32;

sub compute_old {
my ( $server, $index, $prev ) = @_;

Expand Down Expand Up @@ -118,11 +117,11 @@ sub compute {
return @continuum;
}

print "Old:\n";
say 'Old:';
compute( \&compute_old );
print "\n";
print "New:\n";
say '';
say 'New:';
my $total_points = compute( \&compute_new );
print "\n";
say '';
my $int_size = 4;
print "Continuum array size = ", $total_points * $int_size * 2, " bytes\n";
say 'Continuum array size = ', $total_points * $int_size * 2, ' bytes';
3 changes: 2 additions & 1 deletion src/Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use strict;
use v5.12;
use warnings;

use ExtUtils::MakeMaker;

my $includes = '/usr/include';
Expand Down
6 changes: 1 addition & 5 deletions t/Memd.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Memd;

use strict;
use version;
use v5.12;
use warnings;

use Cache::Memcached::Fast;
Expand All @@ -27,9 +26,6 @@ our %params = (
],
);

# 5.8 doesn't ship with Compress::Zlib, avoid lots of warnings.
delete $params{compress_threshold} unless eval { require Compress::Zlib };

sub import {
*main::memd = \Cache::Memcached::Fast->new( \%params );

Expand Down

0 comments on commit 624a612

Please sign in to comment.