File Coverage

blib/lib/KelpX/Symbiosis/Engine/Kelp.pm
Criterion Covered Total %
statement 14 15 93.3
branch 4 6 66.6
condition 3 6 50.0
subroutine 4 4 100.0
pod 2 2 100.0
total 27 33 81.8


line stmt bran cond sub pod time code
1             package KelpX::Symbiosis::Engine::Kelp;
2             $KelpX::Symbiosis::Engine::Kelp::VERSION = '2.11';
3 6     6   3368 use Kelp::Base 'KelpX::Symbiosis::Engine';
  6         15  
  6         38  
4 6     6   1273 use Carp;
  6         10  
  6         2504  
5              
6             attr router => sub { shift->adapter->app->routes };
7              
8             sub mount
9             {
10 10     10 1 82 my ($self, $path, $app) = @_;
11 10         58 my $adapter = $self->adapter;
12              
13 10 50 33     103 croak "Symbiosis: application tries to mount itself under $path in kelp mode"
14             if ref $app && $app == $adapter->app;
15              
16             # Add slurpy suffix
17 10 100 66     118 if (!ref $path) {
    50          
18 7         105 $path =~ s{/?$}{/>subpath};
19             }
20             elsif (ref $path eq 'ARRAY' && !ref $path->[1]) {
21 0         0 $path->[1] =~ s{/?$}{/>subpath};
22             }
23              
24             $self->router->add(
25 10         34 $path, {
26             to => $self->run_app($app),
27             psgi => 1,
28             }
29             );
30             }
31              
32             sub run
33             {
34 32     32 1 225 my $self = shift;
35 32         119 return $self->adapter->app->run;
36             }
37              
38             1;
39             __END__
40              
41             =head1 NAME
42              
43             KelpX::Symbiosis::Engine::Kelp - Use Kelp routes as an engine
44              
45             =head1 DESCRIPTION
46              
47             This is a reimplementation of L<KelpX::Symbiosis::Engine> using Kelp itself as
48             a runner. All other apps will have to go through Kelp first, which will be the
49             center of the application.
50              
51             =head1 CAVEATS
52              
53             =head2 All system routing goes through the Kelp router
54              
55             You can mix apps and Kelp actions, set bridges and build urls to all application components.
56              
57             =head2 Slurpy parameter will be added to the non-regex path
58              
59             C<'/static'> will be turned into C<< '/static/>subpath' >> in order to be able
60             to match any subpath and pass it into the app. Same with C<< [GET => '/static']
61             >>. This way it will allow the same mount points as other engines without extra
62             work. Regex patterns will not be altered in any way.
63              
64             =head2 C<mount> cannot be configured for the main Kelp app
65              
66             Kelp will always be mounted at the very root. The module will throw an
67             exception if you try to configure a different C<mount>.
68              
69             =head2 Does not allow to assign specific middleware for the Kelp app
70              
71             Middleware from the top-level C<middleware> will be wrapping the app the same
72             as Symbiosis middleware, and all other apps will have to go through it. It's
73             impossible to have middleware just for the Kelp app.
74              
75             =head2 Middleware redundancy
76              
77             Wrapping some apps in the same middleware as your main app may be redundant at
78             times. For example, wrapping a static app in session middleware is probably
79             only going to reduce its performance. If it bothers you, you may want to switch
80             to URLMap engine and only mount specific apps under kelp using C<< psgi => 1 >>.
81