line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nephia::Plugin::Cookie; |
2
|
11
|
|
|
11
|
|
7089
|
use strict; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
3245
|
|
3
|
11
|
|
|
11
|
|
65
|
use warnings; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
281
|
|
4
|
11
|
|
|
11
|
|
58
|
use parent 'Nephia::Plugin'; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
62
|
|
5
|
11
|
|
|
11
|
|
608
|
use Scalar::Util (); |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
177
|
|
6
|
11
|
|
|
11
|
|
53
|
use Nephia::Response; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
6466
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub exports { |
9
|
30
|
|
|
30
|
1
|
90
|
qw/cookie/; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
19
|
|
|
19
|
0
|
63
|
my ($class, %opts) = @_; |
14
|
19
|
|
|
|
|
131
|
my $self = $class->SUPER::new(%opts); |
15
|
19
|
|
|
|
|
98
|
my $app = $self->app; |
16
|
19
|
|
|
|
|
66
|
$app->action_chain->prepend(CookieEater => $self->can('_eat_cookie')); |
17
|
19
|
|
|
|
|
69
|
$app->action_chain->append(CookieImprinter => $self->can('_imprint_cookie')); |
18
|
19
|
|
|
|
|
67
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub cookie { |
22
|
48
|
|
|
48
|
1
|
76
|
my ($self, $context) = @_; |
23
|
|
|
|
|
|
|
return sub (;$$) { |
24
|
4
|
|
|
4
|
|
138
|
my $cookies = $context->get('cookies'); |
25
|
4
|
|
50
|
|
|
12
|
$cookies ||= {}; |
26
|
4
|
100
|
33
|
|
|
18
|
if ($_[0] && $_[1]) { |
27
|
2
|
|
|
|
|
5
|
$cookies->{$_[0]} = $_[1]; |
28
|
2
|
|
|
|
|
6
|
$context->set(cookies => $cookies); |
29
|
|
|
|
|
|
|
} |
30
|
4
|
50
|
|
|
|
11
|
my $rtn = $_[0] ? $cookies->{$_[0]} : $cookies; |
31
|
4
|
|
|
|
|
12
|
return $rtn; |
32
|
48
|
|
|
|
|
522
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _eat_cookie { |
36
|
17
|
|
|
17
|
|
32
|
my ($app, $context) = @_; |
37
|
17
|
|
|
|
|
72
|
my $req = $context->get('req'); |
38
|
17
|
|
50
|
|
|
122
|
my $cookies = $req->cookies || {}; |
39
|
17
|
|
|
|
|
405
|
$context->set(cookies => $cookies); |
40
|
17
|
|
|
|
|
49
|
return $context; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _imprint_cookie { |
44
|
17
|
|
|
17
|
|
38
|
my ($app, $context) = @_; |
45
|
17
|
|
|
|
|
104
|
my $res = $context->get('res'); |
46
|
17
|
50
|
|
|
|
216
|
$res = Scalar::Util::blessed($res) ? $res : Nephia::Response->new(@$res); |
47
|
17
|
|
|
|
|
1294
|
my $cookies = $context->get('cookies'); |
48
|
17
|
50
|
|
|
|
62
|
if ($cookies) { |
49
|
17
|
|
|
|
|
90
|
$res->cookies->{$_} = $cookies->{$_} for keys %$cookies; |
50
|
17
|
|
|
|
|
85
|
$context->set(res => $res); |
51
|
|
|
|
|
|
|
} |
52
|
17
|
|
|
|
|
70
|
return $context; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |