File Coverage

blib/lib/Plack/Middleware/OptionsOK.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition 5 8 62.5
subroutine 5 5 100.0
pod 1 1 100.0
total 29 33 87.8


line stmt bran cond sub pod time code
1             package Plack::Middleware::OptionsOK;
2              
3 1     1   886 use strict;
  1         2  
  1         41  
4 1     1   6 use warnings;
  1         1  
  1         36  
5 1     1   16 use Plack::Util::Accessor qw(allow);
  1         2  
  1         10  
6 1     1   53 use parent qw( Plack::Middleware );
  1         1  
  1         8  
7              
8             our $VERSION = 0.02;
9              
10             sub call {
11 3     3 1 28461 my ( $self, $env ) = @_;
12              
13 3 50 66     30 if ($env->{REQUEST_METHOD} eq 'OPTIONS'
      66        
14             && ( $env->{REQUEST_URI} eq '*'
15             || $env->{REQUEST_URI} eq '/'
16             || $env->{REQUEST_URI} eq '/*' )
17             )
18             {
19              
20             # We match /* because of the tests
21 2   50     10 my $allow = $self->allow || 'GET HEAD OPTIONS';
22 2         38 return [ 200, [ 'Allow' => $allow ], [] ];
23             }
24              
25             # Not an OPTIONS * request, carry on...
26 1         16 return $self->app->($env);
27              
28             }
29              
30             1;
31              
32             __END__