diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-09-20 15:44:22 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-09-20 15:44:22 +0100 |
commit | 891ce12c012e2c02e8f024f3701ca9ceef5a4bbf (patch) | |
tree | 769c51c48e6427cb5ded45343b2b6abbe3db5e34 /perllib/Utils.pm | |
parent | 3a05b6e399de926decfe732a8bff9f4e80fc39c5 (diff) |
Decode template files read in with read_file, to prevent double encoding (fixes #159). Also fix Welsh I18N test.
Diffstat (limited to 'perllib/Utils.pm')
-rw-r--r-- | perllib/Utils.pm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/perllib/Utils.pm b/perllib/Utils.pm index c9afff186..954561a08 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -13,6 +13,7 @@ package Utils; use strict; use Encode; +use File::Slurp qw(); use POSIX qw(strftime); use mySociety::DBHandle qw(dbh); use mySociety::GeoUtil; @@ -262,4 +263,17 @@ sub _part { } } +=head2 read_file + +Reads in a UTF-8 encoded file using File::Slurp and decodes it from UTF-8. +This appears simplest, rather than getting confused with binmodes and so on. + +=cut +sub read_file { + my $filename = shift; + my $data = File::Slurp::read_file( $filename ); + $data = Encode::decode( 'utf8', $data ); + return $data; +} + 1; |