Revision f28c26b9
Von Sven Schöling vor etwa 4 Jahren hinzugefügt
SL/Request.pm | ||
---|---|---|
14 | 14 |
use SL::MoreCommon qw(uri_encode uri_decode); |
15 | 15 |
use SL::Layout::None; |
16 | 16 |
use SL::Presenter; |
17 |
use SL::Util qw(trim); |
|
17 | 18 |
|
18 | 19 |
our @EXPORT_OK = qw(flatten unflatten); |
19 | 20 |
|
20 | 21 |
use Rose::Object::MakeMethods::Generic |
21 | 22 |
( |
22 | 23 |
scalar => [ qw(applying_database_upgrades post_data) ], |
23 |
'scalar --get_set_init' => [ qw(cgi layout presenter is_ajax type) ], |
|
24 |
'scalar --get_set_init' => [ qw(cgi layout presenter is_ajax type cookies) ],
|
|
24 | 25 |
); |
25 | 26 |
|
26 | 27 |
sub init_cgi { |
... | ... | |
47 | 48 |
$ENV{HTTPS} && 'on' eq lc $ENV{HTTPS}; |
48 | 49 |
} |
49 | 50 |
|
51 |
sub init_cookies { |
|
52 |
my $raw_cookie = $ENV{HTTP_COOKIE} || $ENV{COOKIE}; |
|
53 |
my @pairs = split /[;,] ?/, $raw_cookie; |
|
54 |
my %results; |
|
55 |
for my $pair (@pairs) { |
|
56 |
my ($key, $value) = split /=/, trim($pair); |
|
57 |
$value //= ''; |
|
58 |
$results{$key} = $value; |
|
59 |
} |
|
60 |
\%results; |
|
61 |
} |
|
62 |
|
|
50 | 63 |
sub cache { |
51 | 64 |
my ($self, $topic, $default) = @_; |
52 | 65 |
|
Auch abrufbar als: Unified diff
SL::Request: cookie parser
CGI benutzt dafür CGI::Cookie, aber das Meiste davon ist völliger
Overkill. Die relevante Schleife besteht aus 5 Zeilen, und kann unser
SL::Request genauso machen.