line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MetaCPAN::Role::Fastly::Catalyst; |
2
|
|
|
|
|
|
|
$MetaCPAN::Role::Fastly::Catalyst::VERSION = '0.04'; |
3
|
1
|
|
|
1
|
|
1010
|
use Moose::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# For dzil [AutoPreq] |
6
|
1
|
|
|
1
|
|
4883
|
use CatalystX::Fastly::Role::Response 0.04; |
|
1
|
|
|
|
|
5696
|
|
|
1
|
|
|
|
|
235
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'MetaCPAN::Role::Fastly'; |
9
|
|
|
|
|
|
|
with 'CatalystX::Fastly::Role::Response'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
requires '_format_auth_key'; |
12
|
|
|
|
|
|
|
requires '_format_dist_key'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
MetaCPAN::Role::Fastly::Catalyst - Methods for catalyst fastly API intergration |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Catalyst qw/ |
21
|
|
|
|
|
|
|
+MetaCPAN::Role::Fastly::Catalyst |
22
|
|
|
|
|
|
|
/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This role includes L<CatalystX::Fastly::Role::Response> and |
27
|
|
|
|
|
|
|
L<MetaCPAN::Role::Fastly> and therefor L<MooseX::Fastly::Role>. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Before C<finalize> this will add the content type as surrogate keys and perform |
30
|
|
|
|
|
|
|
a purge of anything added to the purge list. The headers are actually added |
31
|
|
|
|
|
|
|
by L<CatalystX::Fastly::Role::Response> |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 $c->add_author_key('Ether'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
See L<MetaCPAN::Role::Fastly/purge_author_key> |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_author_key { |
42
|
0
|
|
|
0
|
1
|
|
my ( $c, $author ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$c->add_surrogate_key( $c->_format_auth_key($author) ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 $c->add_dist_key('Moose'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
See L<MetaCPAN::Role::Fastly/purge_dist_key> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub add_dist_key { |
54
|
0
|
|
|
0
|
1
|
|
my ( $c, $dist ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$c->add_surrogate_key( $c->_format_dist_key($dist) ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
before 'finalize' => sub { |
61
|
|
|
|
|
|
|
my $c = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$c->perform_purges(); # will do any purges that has been setup |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ( $c->cdn_max_age ) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# We've decided to cache on Fastly, so throw fail overs |
68
|
|
|
|
|
|
|
# if there is an error at origin |
69
|
|
|
|
|
|
|
$c->cdn_stale_if_error('30d'); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $content_type = lc( $c->res->content_type || 'none' ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$c->add_surrogate_key( 'content_type=' . $content_type ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$content_type =~ s/\/.+$//; # text/html -> 'text' |
77
|
|
|
|
|
|
|
$c->add_surrogate_key( 'content_type=' . $content_type ); |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |