line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::ActionRole::ExpiresHeader; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
26027
|
$Catalyst::ActionRole::ExpiresHeader::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Set default Expires header for actions |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
12
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
476
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use HTTP::Date qw(time2str); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
after 'execute' => sub { |
12
|
|
|
|
|
|
|
my $self = shift; |
13
|
|
|
|
|
|
|
my ($controller, $c, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
if ( my $expires_attr = $c->action->attributes->{Expires} ) { |
16
|
|
|
|
|
|
|
my $expires = $self->_parse_Expires_attr( $expires_attr->[0] ); |
17
|
|
|
|
|
|
|
unless ( $c->response->header('Expires') ) { |
18
|
|
|
|
|
|
|
$c->response->header( |
19
|
|
|
|
|
|
|
Expires => |
20
|
|
|
|
|
|
|
$expires =~ /^\d+$/ ? time2str( $expires ) : $expires |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
my (%mult) = ( |
28
|
|
|
|
|
|
|
's' => 1, |
29
|
|
|
|
|
|
|
'm' => 60, |
30
|
|
|
|
|
|
|
'h' => 60*60, |
31
|
|
|
|
|
|
|
'd' => 60*60*24, |
32
|
|
|
|
|
|
|
'M' => 60*60*24*30, |
33
|
|
|
|
|
|
|
'y' => 60*60*24*365 |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _parse_Expires_attr { |
37
|
|
|
|
|
|
|
my ($self, $time) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# below code is copied from CGI::Util for compability with CGI::Cookie |
40
|
|
|
|
|
|
|
my($offset); |
41
|
|
|
|
|
|
|
if (!$time || (lc($time) eq 'now')) { |
42
|
|
|
|
|
|
|
$offset = 0; |
43
|
|
|
|
|
|
|
} elsif ($time=~/^\d+/) { |
44
|
|
|
|
|
|
|
return $time; |
45
|
|
|
|
|
|
|
} elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { |
46
|
|
|
|
|
|
|
$offset = ($mult{$2} || 1)*$1; |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
return $time; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
return (time+$offset); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
no Moose::Role; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; # End of Catalyst::ActionRole::ExpiresHeader |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding utf-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Catalyst::ActionRole::ExpiresHeader - Set default Expires header for actions |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.01 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
package MyApp::Controller::Foo; |
76
|
|
|
|
|
|
|
use Moose; |
77
|
|
|
|
|
|
|
use namespace::autoclean; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
BEGIN { extends 'Catalyst::Controller::ActionRole' } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__PACKAGE__->config( |
82
|
|
|
|
|
|
|
action_roles => [qw( ExpiresHeader )], |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub expire_in_one_day : Local Expires('+1d') { ... } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub already_expired : Local Expires('-1d') { ... } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Provides a ActionRole to set HTTP Expires header for actions, which will be |
92
|
|
|
|
|
|
|
set unless Expires header was already set. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Argument syntax matches the C<-expires> from |
95
|
|
|
|
|
|
|
L<CGI/CREATING_A_STANDARD_HTTP_HEADER:>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Take a look at L<Catalyst::ActionRole::NotCacheableHeaders> to make your |
100
|
|
|
|
|
|
|
action not cachable by default. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Alex J. G. BurzyÅski <ajgb@cpan.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2010 by Alex J. G. BurzyÅski <ajgb@cpan.org>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|