From: Dylan William Hardison Date: Tue, 6 Nov 2018 20:12:09 +0000 (-0500) Subject: no bug - Remove File::Slurp and File::Slurper X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ed93b828a465c32aa61bbd81c13dfd9c6b6e463f;p=thirdparty%2Fbugzilla.git no bug - Remove File::Slurp and File::Slurper --- diff --git a/Bugzilla/Bloomfilter.pm b/Bugzilla/Bloomfilter.pm index ba1d6d6c3..10ac39b71 100644 --- a/Bugzilla/Bloomfilter.pm +++ b/Bugzilla/Bloomfilter.pm @@ -13,7 +13,7 @@ use warnings; use Bugzilla::Constants; use Algorithm::BloomFilter; -use File::Slurper qw(write_binary read_binary read_lines); +use Mojo::File qw(path); use File::Spec::Functions qw(catfile); sub _new_bloom_filter { @@ -24,33 +24,33 @@ sub _new_bloom_filter { return Algorithm::BloomFilter->new($m, $k); } -sub _filename { +sub _file { my ($name, $type) = @_; my $datadir = bz_locations->{datadir}; - return catfile($datadir, "$name.$type"); + return path(catfile($datadir, "$name.$type")); } sub populate { my ($class, $name) = @_; my $memcached = Bugzilla->memcached; - my @items = read_lines(_filename($name, 'list')); + my @items = split(/\n/, _file($name, 'list')->slurp); my $filter = _new_bloom_filter(@items + 0); $filter->add($_) foreach @items; - write_binary(_filename($name, 'bloom'), $filter->serialize); + _file($name, 'bloom')->spurt( $filter->serialize ); $memcached->clear_bloomfilter({name => $name}); } sub lookup { my ($class, $name) = @_; my $memcached = Bugzilla->memcached; - my $filename = _filename($name, 'bloom'); + my $file = _file($name, 'bloom'); my $filter_data = $memcached->get_bloomfilter( { name => $name } ); - if (!$filter_data && -f $filename) { - $filter_data = read_binary($filename); + if (!$filter_data && -f $file) { + $filter_data = $file->slurp; $memcached->set_bloomfilter({ name => $name, filter => $filter_data }); } diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 317152962..faf031d5b 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -32,8 +32,8 @@ use File::Path; use File::Basename; use File::Copy qw(move); use File::Spec; +use Mojo::File qw(path); use Cwd (); -use File::Slurp; use IO::File; use POSIX (); use English qw(-no_match_vars $OSNAME); @@ -327,30 +327,30 @@ sub FILESYSTEM { my $yui_all_css = sub { return join("\n", map { - my $css = read_file($_); + my $css = path($_)->slurp; _css_url_fix($css, $_, "skins/yui.css.list") - } read_file("skins/yui.css.list", { chomp => 1 }) + } split(/\n/, path("skins/yui.css.list")->slurp) ); }; my $yui_all_js = sub { return join("\n", - map { scalar read_file($_) } read_file("js/yui.js.list", { chomp => 1 }) + map { path($_)->slurp } split(/\n/, path("js/yui.js.list")->slurp) ); }; my $yui3_all_css = sub { return join("\n", map { - my $css = read_file($_); + my $css = path($_)->slurp; _css_url_fix($css, $_, "skins/yui3.css.list") - } read_file("skins/yui3.css.list", { chomp => 1 }) + } split(/\n/, path("skins/yui3.css.list")->slurp) ); }; my $yui3_all_js = sub { return join("\n", - map { scalar read_file($_) } read_file("js/yui3.js.list", { chomp => 1 }) + map { path($_)->slurp } split(/\n/, path('js/yui3.js.list')->slurp) ); }; diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm index 6a9492d06..41d6af16b 100644 --- a/Bugzilla/Quantum/CGI.pm +++ b/Bugzilla/Quantum/CGI.pm @@ -15,8 +15,7 @@ use Sys::Hostname; use Sub::Quote 2.005000; use Sub::Name; use Socket qw(AF_INET inet_aton); -use File::Spec::Functions qw(catfile); -use File::Slurper qw(read_text); +use Mojo::File qw(path); use English qw(-no_match_vars); use Bugzilla::Quantum::Stdout; use Bugzilla::Constants qw(bz_locations USAGE_MODE_BROWSER); @@ -37,7 +36,7 @@ sub load_all { sub load_one { my ($class, $name, $file) = @_; my $package = __PACKAGE__ . "::$name", my $inner_name = "_$name"; - my $content = read_text(catfile(bz_locations->{cgi_path}, $file)); + my $content = path(bz_locations->{cgi_path}, $file)->slurp; $content = "package $package; $content"; untaint($content); my %options = (package => $package, file => $file, line => 1, no_defer => 1,); diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 93101330b..a72a440f9 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -35,7 +35,6 @@ use Digest::MD5 qw(md5_hex); use File::Basename qw(basename dirname); use File::Find; use File::Path qw(rmtree mkpath); -use File::Slurp; use File::Spec; use IO::Dir; use List::MoreUtils qw(firstidx); diff --git a/Makefile.PL b/Makefile.PL index 156ef83d3..50f3121e8 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -57,8 +57,6 @@ my %requires = ( 'Email::MIME' => '1.904', 'Email::Send' => '1.911', 'FFI::Platypus' => 0, - 'File::Slurp' => '9999.13', - 'File::Slurper' => '0.012', 'Future' => '0.34', 'HTML::Escape' => '1.10', 'IPC::System::Simple' => 0, diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 6d654d68a..1c9922f6e 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -57,8 +57,8 @@ use List::Util qw(first); use Scalar::Util qw(blessed); use Sys::Syslog qw(:DEFAULT); use Text::Balanced qw( extract_bracketed extract_multiple ); -use File::Slurp qw(read_file); -use JSON::XS; +use JSON::MaybeXS; +use Mojo::File qw(path); use Bugzilla::Extension::BMO::Constants; use Bugzilla::Extension::BMO::FakeBug; @@ -2594,9 +2594,9 @@ sub install_filesystem { # version.json needs to have a source attribute pointing to # our repository. We already have this information in the (static) # contribute.json file, so parse that in - my $json = JSON::XS->new->pretty->utf8->canonical(); + my $json = JSON::MaybeXS->new->pretty->utf8->canonical(); my $contribute = eval { - $json->decode(scalar read_file(bz_locations()->{cgi_path} . "/contribute.json")); + $json->decode(path(bz_locations()->{cgi_path}, "/contribute.json")->slurp); }; if (!$contribute) { diff --git a/extensions/RequestNagger/bin/send-request-nags.pl b/extensions/RequestNagger/bin/send-request-nags.pl index f823fc197..824c0dc51 100755 --- a/extensions/RequestNagger/bin/send-request-nags.pl +++ b/extensions/RequestNagger/bin/send-request-nags.pl @@ -28,9 +28,9 @@ use Bugzilla::Mailer; use Bugzilla::User; use Bugzilla::Util qw(format_time datetime_from); use Email::MIME; -use File::Slurp qw(read_file); +use Mojo::File qw(path); use File::Temp qw(tempfile); -use JSON qw(encode_json decode_json); +use Mojo::JSON qw(encode_json decode_json); use Sys::Hostname qw(hostname); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); @@ -39,7 +39,7 @@ my $DO_NOT_NAG = grep { $_ eq '-d' } @ARGV; @ARGV = grep { !/^-/ } @ARGV; if (my $filename = shift @ARGV) { - _send_email(decode_json(scalar read_file($filename))); + _send_email(decode_json(path($filename)->slurp)); exit; } diff --git a/scripts/update_localconfig.pl b/scripts/update_localconfig.pl index ca3329022..9a72f0123 100755 --- a/scripts/update_localconfig.pl +++ b/scripts/update_localconfig.pl @@ -17,7 +17,7 @@ use Bugzilla::Config qw( :admin ); use Bugzilla::Constants; use Bugzilla::Install::Localconfig; -use File::Slurp; +use Mojo::File qw(path); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); @@ -28,7 +28,7 @@ die "Syntax: $0 param_name param_value\n" unless defined($param_value); die "Invalid param name: $param_name\n" unless exists $localconfig->{$param_name}; if ($localconfig->{$param_name} ne $param_value) { - my @file = read_file('localconfig'); + my @file = split(/\n/, path('localconfig')->slurp); my $updated = 0; foreach my $line (@file) { next unless $line =~ /^\s*\$([\w_]+)\s*=\s*'([^']*)'/; @@ -39,7 +39,7 @@ if ($localconfig->{$param_name} ne $param_value) { $updated = 1; } } - write_file('localconfig', @file) if $updated; + path('localconfig')->spurt(join("\n", @file)) if $updated; } else { print "'$param_name' is already '$param_value'\n"; } diff --git a/t/css.t b/t/css.t index a64cadea6..1d08ce154 100644 --- a/t/css.t +++ b/t/css.t @@ -9,7 +9,7 @@ use warnings; use 5.10.1; use lib qw( . lib local/lib/perl5 ); use File::Spec; -use File::Slurp qw(read_file); +use Mojo::File qw(path); use File::Find qw(find); use Cwd qw(realpath cwd); use Test::More; @@ -21,7 +21,7 @@ find( wanted => sub { if (/\.css$/) { my $css_file = $File::Find::name; - my $content = read_file($_); + my $content = path($_)->slurp; while ($content =~ m{url\(["']?([^\?\)"']+)(?:\?.+)?['"]?\)}g) { my $file = $1; my $file_rel_root = File::Spec->abs2rel(realpath(File::Spec->rel2abs($file)), $root);