blib/lib/Kelp/Middleware.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 50.0% 2 / 4 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 81.4% 35 / 43 CC 6 SCAR 13.7
CC
6
Cov
85%
wrap
6.4
__ANON__
1.1
BEGIN
1.0
CRAP 4.0
« blib/lib/Kelp/Module/Template.pm ↑ Summary blib/lib/Kelp.pm »
1 package Kelp::Middleware;
2  
3 25 ▶use Kelp::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use Kelp::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶attr -app => sub { croak 'app is required' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
9  
10 sub wrap
11 251 ▶{
Subroutine wrap: called CC=6 SCAR=18.6
Pod documented
12 251 my ($self, $psgi) = @_;
13  
14 251 ▶ if (defined(my $middleware = $self->app->config('middleware'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $middleware = $self->app->config("middleware"))) 251 0 251
15 251 for my $class (@$middleware) {
16  
17 # Make sure the middleware was not already loaded
18 # This does not apply for testing, in which case we want
19 # the middleware to wrap every single time
20 10 ▶ next if $self->{_loaded_middleware}->{$class}++ && !$ENV{KELP_TESTING};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_loaded_middleware"}{$class}++ and not $ENV{"KELP_TESTING"} 0 10 10
Condition33%1/3
$self->{"_loaded_middleware"}{$class}++ and not $ENV{"KELP_TESTING"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$self->{"_loaded_middleware"}{$class}++ and not $ENV{"KELP_TESTING"}
$self->{"_loaded_middleware"}{$class}++ not $ENV{"KELP_TESTING"}
Truth table33%1/3
A and not(B)
A= $self->{"_loaded_middleware"}{$class}++B= not $ENV{"KELP_TESTING"}
ABresult
0X0
100
111
21  
22 10 my $mw = Plack::Util::load_class($class, 'Plack::Middleware');
23 10 ▶ my $args = $self->app->config("middleware_init.$class") // {};
Condition100%2/2
$self->app->config("middleware_init.$class") // {}
l!l
73
MC/DC100%1/1
$self->app->config("middleware_init.$class") // {}
$self->app->config("middleware_init.$class")
Truth table100%2/2
A
A= $self->app->config("middleware_init.$class")
Aresult
11
00
24  
25 10 Kelp::Util::_DEBUG(modules => "Wrapping app in $mw middleware with args: ", $args);
26  
27 10 $psgi = $mw->wrap($psgi, %$args);
28 }
29 }
30  
31 251 return $psgi;
32 }
33  
34 25 1;
35  
36 __END__
37  
38 =pod
39  
40 =head1 NAME
41  
42 Kelp::Middleware - Kelp app wrapper (PSGI middleware)
43  
44 =head1 SYNOPSIS
45  
46 middleware => [qw(TrailingSlashKiller Static)],
47 middleware_init => {
48 TrailingSlashKiller => {
49 redirect => 1,
50 },
51 Static => {
52 path => qr{^/static},
53 root => '.',
54 },
55 }
56  
57 =head1 DESCRIPTION
58  
59 This is a small helper class which wraps Kelp in PSGI middleware. It is loaded
60 and constructed by Kelp based on the value of L<Kelp/middleware_obj> (class
61 name).
62  
63 This class only handles global middleware declared in configuration. Middleware
64 localized to routes cannot be adjusted by customizing this class.
65  
66 =head1 ATTRIBUTES
67  
68 =head2 app
69  
70 Main application object. Required.
71  
72 =head1 METHODS
73  
74 =head2 wrap
75  
76 $wrapped_psgi = $object->wrap($psgi)
77  
78 Wraps the object in all middlewares according to L</app> configuration.
79  
« blib/lib/Kelp/Module/Template.pm ↑ Summary blib/lib/Kelp.pm »