line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Sticker; |
2
|
|
|
|
|
|
|
$Mojolicious::Plugin::Sticker::VERSION = 'v0.0.2'; |
3
|
1
|
|
|
1
|
|
84458
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub register { |
6
|
2
|
|
|
2
|
1
|
183
|
my ( $self, $app, $child ) = @_; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
|
|
12
|
my $embed = Mojo::Server->new->load_app( $child->{app} ); |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
|
|
18971
|
return $app->routes->add_child( $embed->routes ); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
1; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: turns baubles into trinkets |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=pod |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=encoding utf8 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Mojolicious::Plugin::Sticker - Stick apps together |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 VERSION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
0.0.2 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A simple Mojolicious plugin inspired by L |
32
|
|
|
|
|
|
|
to join several small mojo apps into a single one. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Differently from L you won't provide a |
35
|
|
|
|
|
|
|
prefix. The small apps an their routes are just glued together "as is". |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
It is like a C for mojo apps. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# app foo.pl |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use Mojolicious::Lite -signarues; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
get '/foo' => sub($c) { $c->render( json => { foo => 123 } ) }; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
app->start; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
################################################## |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# app bar.pl |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use Mojolicious::Lite -signatures; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
get '/bar' => sub($c) { $c->render( json => { bar => 456 } ) }; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
post '/baz' => sub($c) { |
56
|
|
|
|
|
|
|
my $baz = $c->req->json->{baz} || 0; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$c->render( json => { baz => $baz + 42 } ); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
app->start; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
################################################## |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# app main.pl |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Mojolicious::Lite; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
plugin Sticker => { app => 't/lib/apps/foo' }; |
70
|
|
|
|
|
|
|
plugin Sticker => { app => 't/lib/apps/bar' }; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
app->start; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# main.pl does all that both foo.pl and bar.pl does |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Sometimes we have some small apps that we may want to glue together |
79
|
|
|
|
|
|
|
into a bigger one. This is pretty straightforward with L. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
L is a very nice tool to add small apps |
82
|
|
|
|
|
|
|
under a prefix into another app. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This plugin goes down to a slightly different approach. We just glue |
85
|
|
|
|
|
|
|
the apps together keeping its original routes. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This is exclty what this plugin does: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Mojolicious::Lite -signtures; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $embed = Mojo::Server->new->load_app('my-app'); |
92
|
|
|
|
|
|
|
app->routes->add_child( $embed->routes ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L inherits all methods from |
98
|
|
|
|
|
|
|
L and implements the following new ones. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 register |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Mount an aplication and attach its routes as children of |
103
|
|
|
|
|
|
|
main app routes. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L, |
108
|
|
|
|
|
|
|
L, |
109
|
|
|
|
|
|
|
L, |
110
|
|
|
|
|
|
|
L. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Blabos de Blebe, C<< >> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|