File: cookies-unicode.cgi

package info (click to toggle)
libcgi-tiny-perl 1.003-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: perl: 1,307; makefile: 2
file content (25 lines) | stat: -rwxr-xr-x 652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use CGI::Tiny;
use Unicode::UTF8 qw(decode_utf8 encode_utf8);
use MIME::Base64 qw(decode_base64 encode_base64);

cgi {
  my $cgi = $_;

  my $value = $cgi->param('cookie_value');
  unless (defined $value) {
    my $cookie = $cgi->cookie('unicode');
    $value = decode_utf8 decode_base64 $cookie if defined $cookie;
  }

  if (defined $value) {
    my $encoded_value = encode_base64 encode_utf8($value), '';
    $cgi->add_response_cookie(unicode => $encoded_value, Path => '/');
    $cgi->render(text => "Set cookie value: $value");
  } else {
    $cgi->render(text => "No cookie value set");
  }
};