Skip to content
Snippets Groups Projects
Commit 786c0e4b authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

switch from CGI to CGI::Simple

parent 1ca8dc19
Branches
Tags
No related merge requests found
...@@ -14,7 +14,7 @@ It is actually composed of two parts: ...@@ -14,7 +14,7 @@ It is actually composed of two parts:
This is a web application developed in Perl, allowing SP admins to create test accounts with multiple user profiles. This is a web application developed in Perl, allowing SP admins to create test accounts with multiple user profiles.
It requires the following CPAN distributions: It requires the following CPAN distributions:
* CGI * CGI-Simple
* Config-Tiny * Config-Tiny
* DateTime * DateTime
* List-MoreUtils * List-MoreUtils
......
...@@ -3,7 +3,8 @@ package AccountManager::App; ...@@ -3,7 +3,8 @@ package AccountManager::App;
use strict; use strict;
use warnings; use warnings;
use CGI; use CGI::Simple;
use CGI::Simple::Cookie;
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Log::Any::Adapter; use Log::Any::Adapter;
use List::MoreUtils qw(uniq); use List::MoreUtils qw(uniq);
...@@ -62,11 +63,18 @@ sub new { ...@@ -62,11 +63,18 @@ sub new {
} }
$self->{logger} = Log::Any->get_logger(); $self->{logger} = Log::Any->get_logger();
$self->{cgi} = CGI->new(); $self->{cgi} = CGI::Simple->new();
my $lang =
$self->{cgi}->param('lang') || my $lang;
$self->{cgi}->cookie('lang'); my $cookies = CGI::Simple::Cookie->fetch();
if ($lang = $self->{cgi}->param('lang')) {
$self->{logger}->debugf("setting language from parameter: %s", $lang);
} elsif ($lang = $cookies->{lang} ? $cookies->{lang}->value() : undef) {
$self->{logger}->debugf("setting language from cookie: %s", $lang);
} else {
$self->{logger}->debugf("setting language from HTTP_ACCEPT_LANGUAGE header: %s", $ENV{HTTP_ACCEPT_LANGUAGE});
}
$self->{lh} = AccountManager::L10N->get_handle($lang ? $lang: ()); $self->{lh} = AccountManager::L10N->get_handle($lang ? $lang: ());
if (!$self->{lh}) { if (!$self->{lh}) {
$self->{logger}->fatal("Unable to get suitable language handle"); $self->{logger}->fatal("Unable to get suitable language handle");
...@@ -188,7 +196,7 @@ sub respond { ...@@ -188,7 +196,7 @@ sub respond {
binmode(STDOUT, ":utf8"); binmode(STDOUT, ":utf8");
my $cookie = $self->{cgi}->cookie( my $cookie = CGI::Simple::Cookie->new(
-name => 'lang', -name => 'lang',
-value => $self->{lh}->language_tag(), -value => $self->{lh}->language_tag(),
-expires => undef, -expires => undef,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment