| 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)
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)
| |||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 36 | 12 | ▶ | return unless $matched; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$method ne "GET" and $method ne "HEAD"
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"
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | my $res = Plack::Response->new; | |||||||||||||||||||||||||||
| 43 | 6 | $res->content_type('text/plain'); | |||||||||||||||||||||||||||
| 44 | 6 | ▶ | if (defined $self->{revision}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | if (-e $self->_revision_filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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"
$self->revision_filename // "./REVISION"
MC/DC100%1/1
$self->{"_revision_filename"} //= $self->revision_filename // "./REVISION"
$self->{"_revision_filename"}
Truth table100%2/2
A
A= $self->{"_revision_filename"}
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 3 | 1; | |||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||