File: //scripts.20110531.215904.25158/patch_storable
#!/usr/bin/perl
# cpanel - patch_storable Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::SafeRun::Simple ();
use Cpanel::SafeFile ();
use Cpanel::LoadFile ();
use Cpanel::Logger ();
eval 'local $SIG{__DIE__}; use Storable;';
my $module_path = $INC{'Storable.pm'};
my $logger = Cpanel::Logger->new();
my $txt = Cpanel::LoadFile::loadfile($module_path);
if ( $txt !~ /(require|use) DynaLoader/ ) { exit; }
if ( $txt =~ /XSLoader/ ) { exit; }
print "Removing bloated DynaLoader Dep from Storable.\n";
if ( !-e $module_path ) { $logger->die("Could not find $module_path"); }
my $mod_fh = Cpanel::SafeFile::safeopen( \*ER, '+<', $module_path );
if ( !$mod_fh ) { $logger->die("Could not edit $module_path"); }
my @EN = <ER>;
seek( ER, 0, 0 );
my $inconfig = 0;
foreach (@EN) {
s/require DynaLoader/use XSLoader/g;
s/use DynaLoader/use XSLoader/g;
s/DynaLoader/XSLoader/g;
s/^bootstrap.*/XSLoader::load 'Storable', \$VERSION\;/g;
print ER $_;
}
truncate( ER, tell(ER) );
Cpanel::SafeFile::safeclose( \*ER, $mod_fh );
my $is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_storable' ? '/usr/local/cpanel/scripts/check_storable' : '/scripts/check_storable' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
print "Patching Failed, restoring previous Storable!\n";
my $mod_fh2 = Cpanel::SafeFile::safeopen( \*ER, '>', $module_path );
if ( !$mod_fh2 ) { $logger->warn("Could not write to $module_path"); exit; }
print ER $txt;
Cpanel::SafeFile::safeclose( \*ER, $mod_fh2 );
}
my $is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_storable' ? '/usr/local/cpanel/scripts/check_storable' : '/scripts/check_storable' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
system '/scripts/perlinstaller', '--force', 'Storable';
}