| 1 | package Catalyst::ActionRole::ExpiresHeader; | ||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 3 | $Catalyst::ActionRole::ExpiresHeader::VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Set default Expires header for actions | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use HTTP::Date qw(time2str); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | after 'execute' => sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 12 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 13 | 17 | my ($controller, $c, @args) = @_; | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 17 | ▶ | if ( my $expires_attr = $c->action->attributes->{Expires} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 16 | 16 | my $expires = $self->_parse_Expires_attr( $expires_attr->[0] ); | |||||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | unless ( $c->response->header('Expires') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 18 | 14 | ▶ | $c->response->header( | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 19 | Expires => | ||||||||||||||||||||||||||||||||||||
| 20 | $expires =~ /^\d+$/ ? time2str( $expires ) : $expires | ||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||
| 24 | 3 | }; | |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||
| 27 | 3 | 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 | 16 | ▶ | sub _parse_Expires_attr { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_Expires_attr: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 37 | 16 | my ($self, $time) = @_; | |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | # below code is copied from CGI::Util for compability with CGI::Cookie | ||||||||||||||||||||||||||||||||||||
| 40 | 16 | my($offset); | |||||||||||||||||||||||||||||||||||
| 41 | 16 | ▶ | if (!$time || (lc($time) eq 'now')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
not $time or lc $time eq "now"
MC/DC100%2/2
not $time or lc $time eq "now"
not $time
lc $time eq "now"
Truth table100%3/3
not(A) or B
A= not $timeB= lc $time eq "now"
| |||||||||||||||||||||||||||||||||||||
| 42 | 6 | $offset = 0; | |||||||||||||||||||||||||||||||||||
| 43 | } elsif ($time=~/^\d+/) { | ||||||||||||||||||||||||||||||||||||
| 44 | 2 | return $time; | |||||||||||||||||||||||||||||||||||
| 45 | } elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { | ||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | $offset = ($mult{$2} || 1)*$1; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mult{$2} || 1
MC/DC0%0/1
$mult{$2} || 1
$mult{$2}
Truth table50%1/2
A
A= $mult{$2}
| |||||||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||||
| 48 | 2 | return $time; | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||
| 50 | 12 | return (time+$offset); | |||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | 3 | 1; # End of Catalyst::ActionRole::ExpiresHeader | |||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||||||