diff --git a/README.md b/README.md index 9154e48352f031e528750486ef610962e1679d8b..6f68f9a5c2a8aa18cc46dd37d87662c8ab5e26be 100644 --- a/README.md +++ b/README.md @@ -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. It requires the following CPAN distributions: -* CGI +* CGI-Simple * Config-Tiny * DateTime * List-MoreUtils diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm index 40d504a066f4417c72f894b29703a051c6680633..4cd6fdab33a80972789e7b0fd9f872937ecb39f6 100644 --- a/lib/AccountManager/App.pm +++ b/lib/AccountManager/App.pm @@ -3,7 +3,8 @@ package AccountManager::App; use strict; use warnings; -use CGI; +use CGI::Simple; +use CGI::Simple::Cookie; use English qw(-no_match_vars); use Log::Any::Adapter; use List::MoreUtils qw(uniq); @@ -62,11 +63,18 @@ sub new { } $self->{logger} = Log::Any->get_logger(); - $self->{cgi} = CGI->new(); + $self->{cgi} = CGI::Simple->new(); - my $lang = - $self->{cgi}->param('lang') || - $self->{cgi}->cookie('lang'); + + my $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: ()); if (!$self->{lh}) { $self->{logger}->fatal("Unable to get suitable language handle"); @@ -188,7 +196,7 @@ sub respond { binmode(STDOUT, ":utf8"); - my $cookie = $self->{cgi}->cookie( + my $cookie = CGI::Simple::Cookie->new( -name => 'lang', -value => $self->{lh}->language_tag(), -expires => undef,