blib/lib/Catalyst/ActionRole/ExpiresHeader.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 12 / 12 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 96.5% 56 / 58 CC 9 SCAR 13.4
CC
9
Cov
98%
_parse_Expires_attr
6.0
__ANON__
4.0
BEGIN
1.0
CRAP 3.8
↑ Summary
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
BranchTrueFalseTotal
if (my $expires_attr = $c->action->attributes->{"Expires"}) 16 1 17
16 16 my $expires = $self->_parse_Expires_attr( $expires_attr->[0] );
17 16 ▶ unless ( $c->response->header('Expires') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->response->header("Expires")) 14 2 16
18 14 ▶ $c->response->header(
Branch: 1 branch
BranchTrueFalseTotal
$expires =~ /^\d+$/ ? : 12 2 14
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
BranchTrueFalseTotal
if (not $time or lc $time eq 'now') { } 6 10 16
elsif ($time =~ /^\d+/) { } 2 8 10
elsif ($time =~ /^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) { } 6 2 8
Condition100%3/3
not $time or lc $time eq "now"
l!l&&r!l&&!r
4210
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"
ABresult
1X1
011
000
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
l!l
60
MC/DC0%0/1
$mult{$2} || 1
$mult{$2}
Truth table50%1/2
A
A= $mult{$2}
Aresult
11
00
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__
↑ Summary