line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LWP::UserAgent::Role::CHICaching::SimpleMungeResponse; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1300
|
use 5.006000; |
|
3
|
|
|
|
|
8
|
|
4
|
3
|
|
|
3
|
|
10
|
use CHI; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
42
|
|
5
|
3
|
|
|
3
|
|
25
|
use Moo::Role; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
13
|
|
6
|
3
|
|
|
3
|
|
549
|
use Types::Standard qw(Bool); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
18
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KJETILK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=pod |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf-8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
LWP::UserAgent::Role::CHICaching::SimpleMungeResponse - A role to manipulate the response when caching |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
See L<LWP::UserAgent::Role::CHICaching>. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
When caching, it is sometimes useful to change the response, in |
26
|
|
|
|
|
|
|
particular the body in some way for caching. In some cases, you might |
27
|
|
|
|
|
|
|
not want to store the entire body, but compress it in some way, or |
28
|
|
|
|
|
|
|
store the data in a different data structure than the serialized |
29
|
|
|
|
|
|
|
version shared over the network. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The methods here are used to first manipulate the response before it |
32
|
|
|
|
|
|
|
is sent to the cache, and then a cached response before it is returned |
33
|
|
|
|
|
|
|
to the client. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Methods |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item C<< cache_set($response, $expires_in) >> |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
A method that takes the L<HTTP::Response> from the client and an |
45
|
|
|
|
|
|
|
expires time in seconds and set the actual cache. This role's |
46
|
|
|
|
|
|
|
implementation stores the response as it is. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item C<< finalize($cached) >> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
A method that takes the cached entry as an argument, and will return a |
52
|
|
|
|
|
|
|
L<HTTP::Response> to return to the client. This implementation returns |
53
|
|
|
|
|
|
|
the response directly from the cache. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 TODO |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The standard has a C<no-transform> directive that is relevant to this, |
60
|
|
|
|
|
|
|
since roles such as this can be used to transform the response. This |
61
|
|
|
|
|
|
|
needs to be dealt with. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub finalize { |
67
|
2
|
|
|
2
|
1
|
12
|
return $_[1]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub cache_set { |
71
|
4
|
|
|
4
|
1
|
10
|
my ($self, $res, $expires_in) = @_; |
72
|
4
|
|
|
|
|
27
|
return $self->cache->set($self->key, $res, { expires_in => $expires_in }); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Kjetil Kjernsmo E<lt>kjetilk@cpan.orgE<gt>. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Kjetil Kjernsmo. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
90
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |