blib/lib/Plack/Middleware/RevisionPlate.pm

filter: Statementstmt 100% 51 / 51 Branchbran 85.7% 12 / 14 Conditioncond 84.6% 11 / 13 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 92.9% 92 / 99 CC 14 SCAR 16.1
CC
14
Cov
95%
_may_handle_request
10.0
_revision_filename
3.0
_read_revision_file_at_first
2.0
CRAP 5.0
↑ Summary
1 package Plack::Middleware::RevisionPlate;
2 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Plack::Util::Accessor qw/path revision_filename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Plack::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Slurp qw/read_file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use parent qw/Plack::Middleware/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our $VERSION = "0.01";
12  
13 12 ▶sub call {
Subroutine call: called CC=2 SCAR=7.0
Pod documented
14 12 my $self = shift;
15 12 my $env = shift;
16 12 ▶ return $self->_may_handle_request($env) // $self->app->($env);
Condition66%2/3
$self->_may_handle_request($env) // $self->app->($env)
l!l&&r!l&&!r
840
MC/DC0%0/2
$self->_may_handle_request($env) // $self->app->($env)
$self->_may_handle_request($env) $self->app->($env)
Truth table66%2/3
A // B
A= $self->_may_handle_request($env)B= $self->app->($env)
ABresult
1X1
011
000
17 }
18  
19 2 ▶sub prepare_app {
Subroutine prepare_app: called CC=1 SCAR=0.0
Pod documented
20 2 my $self = shift;
21 2 $self->_read_revision_file_at_first;
22 }
23  
24 4 ▶sub _read_revision_file_at_first {
Subroutine _read_revision_file_at_first: called CC=2 SCAR=7.1
25 4 my $self = shift;
26 4 ▶ $self->{revision} = -e $self->_revision_filename && read_file($self->_revision_filename);
Condition66%2/3
-e $self->_revision_filename && read_file($self->_revision_filename)
!ll&&!rl&&r
202
MC/DC50%1/2
-e $self->_revision_filename && read_file($self->_revision_filename)
-e $self->_revision_filename read_file($self->_revision_filename)
Truth table66%2/3
A && B
A= -e $self->_revision_filenameB= read_file($self->_revision_filename)
ABresult
0X0
100
111
27 }
28  
29 12 ▶sub _may_handle_request {
Subroutine _may_handle_request: called CC=10 SCAR=23.0
30 12 my ($self, $env) = @_;
31 12 ▶ my $path_match = $self->path or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path_match = $self->path or return 12 0 12
32 12 my $path = $env->{PATH_INFO};
33  
34 12 for ($path) {
35 12 ▶ my $matched = 'CODE' eq ref $path_match ? $path_match->($_, $env) : $_ =~ $path_match;
Branch: 1 branch
BranchTrueFalseTotal
'CODE' eq ref $path_match ? : 0 12 12
36 12 ▶ return unless $matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched 4 8 12
37 }
38  
39 8 my $method = $env->{REQUEST_METHOD};
40 8 ▶ return Plack::Response->new(405)->finalize if $method ne 'GET' && $method ne 'HEAD'; # 405: method not allowed
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "GET" and $method ne "HEAD" 2 6 8
Condition100%3/3
$method ne "GET" and $method ne "HEAD"
!ll&&!rl&&r
422
MC/DC100%2/2
$method ne "GET" and $method ne "HEAD"
$method ne "GET" $method ne "HEAD"
Truth table100%3/3
A and B
A= $method ne "GET"B= $method ne "HEAD"
ABresult
0X0
100
111
41  
42 6 my $res = Plack::Response->new;
43 6 $res->content_type('text/plain');
44 6 ▶ if (defined $self->{revision}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'revision'}) { } 3 3 6
45 3 ▶ if (-e $self->_revision_filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->_revision_filename) { } 2 1 3
46 2 $res->status(200);
47 2 $res->body($self->{revision});
48 } else {
49 1 $res->status(404);
50 1 $res->body("REVISION_FILE_REMOVED\n");
51 }
52 } else {
53 3 $res->status(404);
54 3 $res->body("REVISION_FILE_NOT_FOUND\n");
55 }
56  
57 6 ▶ $res->body('') if $method eq 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" 2 4 6
58 6 return $res->finalize;
59 }
60  
61 11 ▶sub _revision_filename {
Subroutine _revision_filename: called CC=3 SCAR=11.0
62 11 my $self = shift;
63 11 ▶ $self->{_revision_filename} //= $self->revision_filename // './REVISION';
Condition100%4/4
$self->{"_revision_filename"} //= $self->revision_filename // "./REVISION"
l!l
74
$self->revision_filename // "./REVISION"
l!l
31
MC/DC100%1/1
$self->{"_revision_filename"} //= $self->revision_filename // "./REVISION"
$self->{"_revision_filename"}
Truth table100%2/2
A
A= $self->{"_revision_filename"}
Aresult
11
00
64 }
65  
66 3 1;
67 __END__
↑ Summary