summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Util.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2016-10-13 02:41:36 +0200
committerGitHub <noreply@github.com>2016-10-13 02:41:36 +0200
commitdf4677439d7b3658e2d896ffaab903b01c2e2fe6 (patch)
treed9013dcffb7c60cd83c23865d1a086d632f17d84 /Bugzilla/Util.pm
parent31651c978e921e9e46cddd455f103fcf4b1a332a (diff)
downloadbugzilla-df4677439d7b3658e2d896ffaab903b01c2e2fe6.tar.gz
bugzilla-df4677439d7b3658e2d896ffaab903b01c2e2fe6.tar.xz
Bug 1301887 - File::Slurp triggers warnings on perl 5.24 and it is recommended to not use it (#21)
r=mtyson
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r--Bugzilla/Util.pm25
1 files changed, 24 insertions, 1 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index 78376c6fe..565cda19d 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -24,7 +24,7 @@ use parent qw(Exporter);
validate_email_syntax check_email_syntax clean_text
get_text template_var display_value disable_utf8
detect_encoding email_filter
- join_activity_entries);
+ join_activity_entries read_text write_text);
use Bugzilla::Constants;
use Bugzilla::RNG qw(irand);
@@ -39,6 +39,8 @@ use Scalar::Util qw(tainted blessed);
use Text::Wrap;
use Encode qw(encode decode resolve_alias);
use Encode::Guess;
+use File::Basename qw(dirname);
+use File::Temp qw(tempfile);
sub trick_taint {
require Carp;
@@ -101,6 +103,27 @@ sub html_quote {
return $var;
}
+sub read_text {
+ my ($filename) = @_;
+ open my $fh, '<:encoding(utf-8)', $filename;
+ local $/ = undef;
+ my $content = <$fh>;
+ close $fh;
+ return $content;
+}
+
+sub write_text {
+ my ($filename, $content) = @_;
+ my ($tmp_fh, $tmp_filename) = tempfile('.tmp.XXXXXXXXXX',
+ DIR => dirname($filename),
+ UNLINK => 0,
+ );
+ binmode $tmp_fh, ':encoding(utf-8)';
+ print $tmp_fh $content;
+ close $tmp_fh;
+ rename $tmp_filename, $filename;
+}
+
sub html_light_quote {
my ($text) = @_;
# admin/table.html.tmpl calls |FILTER html_light| many times.