aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm6
-rw-r--r--perllib/Utils.pm14
4 files changed, 19 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index ffbb5a161..1e6a3a088 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -666,7 +666,7 @@ sub process_report : Private {
$report->detail( $detail );
# set these straight from the params
- $report->category( _ $params{category} );
+ $report->category( _ $params{category} ) if $params{category};
my $areas = $c->stash->{all_areas};
$report->areas( ',' . join( ',', sort keys %$areas ) . ',' );
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index bf085e32a..c1a5d65c9 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -4,8 +4,6 @@ use base 'DBIx::Class::ResultSet';
use strict;
use warnings;
-use File::Slurp;
-
use mySociety::DBHandle qw(dbh);
use mySociety::EmailUtil;
use mySociety::Gaze;
@@ -189,7 +187,7 @@ sub _send_aggregated_alert_email(%) {
unless -e $template;
$template = FixMyStreet->path_to( "templates", "email", "default", "$data{template}.txt" )->stringify
unless -e $template;
- $template = File::Slurp::read_file($template);
+ $template = Utils::read_file($template);
my $sender = $cobrand->contact_email;
(my $from = $sender) =~ s/team/fms-DO-NOT-REPLY/; # XXX
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index 665e0e3e0..0cf01b6d1 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -3,7 +3,7 @@ use base 'DBIx::Class::ResultSet';
use strict;
use warnings;
-use File::Slurp;
+use Encode;
use Utils;
use mySociety::EmailUtil;
@@ -57,12 +57,12 @@ sub send_questionnaires_period {
my $template;
if ($params->{site} eq 'emptyhomes') {
($template = $period) =~ s/ //;
- $template = File::Slurp::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify );
+ $template = Utils::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify );
} else {
$template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify;
$template = FixMyStreet->path_to( "templates", "email", "default", "questionnaire.txt" )->stringify
unless -e $template;
- $template = File::Slurp::read_file( $template );
+ $template = Utils::read_file( $template );
}
my %h = map { $_ => $row->$_ } qw/name title detail category/;
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;