| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Kelp::Module::Raisin; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '1.00'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 2 |  |  | 2 |  | 66141 | use Kelp::Base qw(Kelp::Module::Symbiosis::Base); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 6 | 2 |  |  | 2 |  | 3323 | use Plack::Util; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 7 | 2 |  |  | 2 |  | 10 | use Scalar::Util qw(blessed); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 485 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 5 |  |  | 5 | 1 | 157 | sub name { 'raisin' } | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # since Raisin::API is really a singleton we have to keep it that way. If we | 
| 12 |  |  |  |  |  |  | # wouldn't, test suite would be full of Raisin route redefinition warnings and | 
| 13 |  |  |  |  |  |  | # would likely lead to buggy code | 
| 14 |  |  |  |  |  |  | my $psgi; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub psgi | 
| 17 |  |  |  |  |  |  | { | 
| 18 | 5 |  |  | 5 | 1 | 54015 | my ($self) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 5 |  | 66 |  |  | 24 | return $psgi //= $self->app->raisin->run; | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub build | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 5 |  |  | 5 | 1 | 8790 | my ($self, %args) = @_; | 
| 26 | 5 |  |  |  |  | 25 | $self->SUPER::build(%args); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | die 'Raisin module requires "class" configuration' | 
| 29 | 5 | 100 |  |  |  | 31 | unless $args{class}; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 4 |  |  |  |  | 11 | my $class = Plack::Util::load_class($args{class}); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # let it bug out with regular error message if it can't app | 
| 34 | 3 |  |  |  |  | 948 | my $raisin = $class->app; | 
| 35 | 2 | 100 | 66 |  |  | 66 | die "$class not isa Raisin" | 
| 36 |  |  |  |  |  |  | unless defined blessed $raisin && $raisin->isa('Raisin'); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 1 |  |  |  |  | 6 | $self->register(raisin => $raisin); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | 1; | 
| 42 |  |  |  |  |  |  | __END__ | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =head1 NAME | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | Kelp::Module::Raisin - Raisin integration with Kelp | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # in config - order matters | 
| 51 |  |  |  |  |  |  | modules => [qw(Symbiosis Raisin)], | 
| 52 |  |  |  |  |  |  | modules_init => { | 
| 53 |  |  |  |  |  |  | # optional | 
| 54 |  |  |  |  |  |  | Symbiosis => { | 
| 55 |  |  |  |  |  |  | mount => '/path', # will mount Kelp under /path | 
| 56 |  |  |  |  |  |  | }, | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # required | 
| 59 |  |  |  |  |  |  | Raisin => { | 
| 60 |  |  |  |  |  |  | mount => '/api', # will mount Raisin under /api | 
| 61 |  |  |  |  |  |  | class => 'My::Raisin', # required - full class name of Raisin app | 
| 62 |  |  |  |  |  |  | }, | 
| 63 |  |  |  |  |  |  | }, | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | # in application's build method | 
| 66 |  |  |  |  |  |  | $self->raisin->add_route( | 
| 67 |  |  |  |  |  |  | method => 'GET', | 
| 68 |  |  |  |  |  |  | path => '/from-kelp', | 
| 69 |  |  |  |  |  |  | params => {}, | 
| 70 |  |  |  |  |  |  | code => sub { 'Hello World from Kelp, in Raisin!' }, | 
| 71 |  |  |  |  |  |  | ); | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | # in psgi script | 
| 74 |  |  |  |  |  |  | $app = MyKelpApp->new; | 
| 75 |  |  |  |  |  |  | $app->run_all; | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | This is a very straightforward module that integrates the L<Kelp> framework with the L<Raisin> API framework using L<Kelp::Module::Symbiosis>. See the documentation for L<Kelp::Module::Symbiosis> and L<Kelp::Module::Symbiosis::Base> for a full reference on how this module behaves. | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head1 MODULE INFORMATION | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | This module name is I<'raisin'>. You can refer to it with that name in Symbiosis methods - I<loaded> and I<mounted>. There shouldn't be a need to, since it will be mounted automatically if you specify L</mount> in configuration. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | The module class itself does not expose anything particularly interesting, it is just a wrapper for Raisin. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head1 METHODS INTRODUCED TO KELP | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head2 raisin | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | my $raisin = $kelp->raisin; | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | Returns the running instance of Raisin. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head2 middleware, middleware_init | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | Same as L<Kelp::Module::Symbiosis::Base/middleware, middleware_init>. Since Raisin can wrap itself in its own middleware it will likely not be that useful. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head2 mount | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | See L<Kelp::Module::Symbiosis::Base/mount> for details. | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head2 class | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | Should be a full name of the package that defines an api using L<Raisin::API>. Keep in mind that Raisin::API is really a singleton so it is not suitable for multiple app setup. | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =over 2 | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =item * L<Kelp>, the framework | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =item * L<Raisin>, the API framework | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =back | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =head1 AUTHOR | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | Bartosz Jarzyna, E<lt>brtastic.dev@gmail.comE<gt> | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | Copyright (C) 2020 by Bartosz Jarzyna | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 129 |  |  |  |  |  |  | it under the same terms as Perl itself, either Perl version 5.10.1 or, | 
| 130 |  |  |  |  |  |  | at your option, any later version of Perl 5 you may have available. | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =cut |