1use strict; 2use warnings; 3 4use Config; 5 6my $template; 7{ # keep all the code in an external template to keep it easy to update 8 local $/; 9 open my $FROM, '<', '__Storable__.pm' or die $!; 10 $template = <$FROM>; 11 close $FROM or die $!; 12} 13 14sub CAN_FLOCK { 15 return 16 $Config{'d_flock'} || 17 $Config{'d_fcntl_can_lock'} || 18 $Config{'d_lockf'} 19 ? 1 : 0; 20} 21 22my $CAN_FLOCK = CAN_FLOCK(); 23 24# populate the sub and preserve it if used outside 25$template =~ s{^sub CAN_FLOCK;.*$}{sub CAN_FLOCK { ${CAN_FLOCK} } # computed by Storable.pm.PL}m; 26# alternatively we could remove the sub 27#$template =~ s{^sub CAN_FLOCK;.*$}{}m; 28# replace local function calls to hardcoded value 29$template =~ s{&CAN_FLOCK}{${CAN_FLOCK}}g; 30 31{ 32 open my $OUT, '>', 'Storable.pm' or die $!; 33 print {$OUT} $template or die $!; 34 close $OUT or die $!; 35} 36