« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/Text/CSV_XS.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/SQLBuilder/Query.pm »
| 1 | package Dwarf::Session::State::Cookie; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use parent 'HTTP::Session::State::Cookie'; | ||
| 4 | use Dwarf::Accessor qw/param_name httponly/; | ||
| 5 | |||
| 6 | sub get_session_id { | ||
| 7 | my ($self, $req) = @_; | ||
| 8 | Carp::croak "missing req" unless $req; | ||
| 9 | my $id = $self->SUPER::get_session_id($req); | ||
| 10 | if (ref $self->param_name eq 'ARRAY') { | ||
| 11 | for my $param_name (@{ $self->param_name }) { | ||
| 12 | $id ||= $req->param($param_name); | ||
| 13 | } | ||
| 14 | } else { | ||
| 15 | $id ||= $req->param($self->param_name); | ||
| 16 | } | ||
| 17 | return $id; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub header_filter { | ||
| 21 | my ($self, $session_id, $res) = @_; | ||
| 22 | Carp::croak "missing session_id" unless $session_id; | ||
| 23 | |||
| 24 | my $cookie = HTTP::Session::State::Cookie::_cookie_class()->new( | ||
| 25 | sub { | ||
| 26 | my %options = ( | ||
| 27 | -name => $self->name, | ||
| 28 | -value => $session_id, | ||
| 29 | -path => $self->path, | ||
| 30 | ); | ||
| 31 | $options{'-domain'} = $self->domain if $self->domain; | ||
| 32 | $options{'-expires'} = $self->expires if $self->expires; | ||
| 33 | $options{'-secure'} = $self->secure if $self->secure; | ||
| 34 | $options{'-httponly'} = $self->httponly if $self->httponly; | ||
| 35 | %options; | ||
| 36 | }->() | ||
| 37 | ); | ||
| 38 | if (Scalar::Util::blessed($res)) { | ||
| 39 | $res->headers->push_header( 'Set-Cookie' => $cookie->as_string ); | ||
| 40 | $res; | ||
| 41 | } else { | ||
| 42 | push @{$res->[1]}, 'Set-Cookie' => $cookie->as_string; | ||
| 43 | $res; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; |