blib/lib/Catalyst/Plugin/DetachIfNotModified.pm

filter: Statementstmt 100% 33 / 33 Branchbran 83.3% 5 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 94.1% 48 / 51 CC 5 SCAR 9.9
CC
5
Cov
95%
detach_if_not_modified_since
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
↑ Summary
1 package Catalyst::Plugin::DetachIfNotModified;
2  
3 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Short-circuit requests with If-Modified-Since headers
6  
7 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use HTTP::Headers 5.18;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTTP::Status qw/ HTTP_NOT_MODIFIED /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::Util qw/ max /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Ref::Util qw/ is_blessed_ref /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # RECOMMEND PREREQ: Plack::Middleware::ConditionalGET
15 # RECOMMEND PREREQ: Ref::Util::XS
16  
17 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = 'v0.3.1';
20  
21  
22 4 ▶sub detach_if_not_modified_since {
Subroutine detach_if_not_modified_since: called CC=5 SCAR=16.2
Pod documented
23 4 my ($c, @times) = @_;
24  
25 4 ▶ my @epochs = grep defined, map { is_blessed_ref($_) ? $_->epoch : $_ } @times;
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_blessed_ref($_) ? : 0 4 4
26 4 ▶ my $time = max(@epochs) // return;
Condition50%1/2
&max(@epochs) // (return)
l!l
40
MC/DC0%0/1
&max(@epochs) // (return)
&max(@epochs)
Truth table50%1/2
A
A= &max(@epochs)
Aresult
11
00
27 4 my $res = $c->res;
28 4 $res->headers->last_modified($time);
29  
30 4 my $hdr = $c->req->headers;
31 4 ▶ if (my $since = $hdr->if_modified_since) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $since = $hdr->if_modified_since) 3 1 4
32 3 ▶ if ($since >= $time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($since >= $time) 2 1 3
33 2 $res->code(HTTP_NOT_MODIFIED);
34 2 $c->detach;
35 }
36 }
37 }
38  
39  
40 1 1;
41  
42 __END__
↑ Summary