line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use strict; |
2
|
25
|
|
|
25
|
|
2852967
|
use warnings; |
|
25
|
|
|
|
|
203
|
|
|
25
|
|
|
|
|
735
|
|
3
|
25
|
|
|
25
|
|
137
|
use 5.008001; |
|
25
|
|
|
|
|
52
|
|
|
25
|
|
|
|
|
640
|
|
4
|
25
|
|
|
25
|
|
674
|
use Amon2::Util (); |
|
25
|
|
|
|
|
88
|
|
5
|
25
|
|
|
25
|
|
9078
|
use Plack::Util (); |
|
25
|
|
|
|
|
79
|
|
|
25
|
|
|
|
|
562
|
|
6
|
25
|
|
|
25
|
|
8846
|
use Carp (); |
|
25
|
|
|
|
|
145497
|
|
|
25
|
|
|
|
|
472
|
|
7
|
25
|
|
|
25
|
|
152
|
use Amon2::Config::Simple; |
|
25
|
|
|
|
|
72
|
|
|
25
|
|
|
|
|
438
|
|
8
|
25
|
|
|
25
|
|
10381
|
use Amon2::ContextGuard; |
|
25
|
|
|
|
|
76
|
|
|
25
|
|
|
|
|
758
|
|
9
|
25
|
|
|
25
|
|
9404
|
|
|
25
|
|
|
|
|
72
|
|
|
25
|
|
|
|
|
8134
|
|
10
|
|
|
|
|
|
|
our $VERSION = '6.16'; |
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
our $CONTEXT; # You can localize this variable in your application. |
13
|
|
|
|
|
|
|
Amon2::ContextGuard->new($_[0], \$CONTEXT); |
14
|
16
|
|
|
16
|
1
|
106
|
} |
15
|
3
|
|
|
3
|
1
|
8
|
} |
16
|
|
|
|
|
|
|
|
17
|
23
|
|
|
23
|
1
|
128
|
my $class = shift; |
18
|
|
|
|
|
|
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
19
|
|
|
|
|
|
|
bless { %args }, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
43
|
|
|
43
|
1
|
4264
|
# For CLI. |
23
|
43
|
50
|
|
|
|
182
|
my $class = shift; |
|
0
|
|
|
|
|
0
|
|
24
|
43
|
|
|
|
|
199
|
my $self = $class->new(@_); |
25
|
|
|
|
|
|
|
$class->set_context($self); |
26
|
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
4
|
|
492
|
# Class method. |
30
|
4
|
|
|
|
|
55
|
my $proto = ref $_[0] || $_[0]; |
31
|
4
|
|
|
|
|
49
|
my $base_dir = Amon2::Util::base_dir($proto); |
32
|
4
|
|
|
|
|
11
|
Amon2::Util::add_method($proto, 'base_dir', sub { $base_dir }); |
33
|
|
|
|
|
|
|
$base_dir; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $class = shift; |
37
|
0
|
|
0
|
0
|
1
|
0
|
$class = ref $class || $class; |
38
|
0
|
|
|
|
|
0
|
die "Do not call Amon2->config() directly." if __PACKAGE__ eq $class; |
39
|
0
|
|
|
0
|
|
0
|
no strict 'refs'; |
|
0
|
|
|
|
|
0
|
|
40
|
0
|
|
|
|
|
0
|
my $config = $class->load_config(); |
41
|
|
|
|
|
|
|
*{"$class\::config"} = sub { $config }; # Class cache. |
42
|
|
|
|
|
|
|
return $config; |
43
|
0
|
|
|
0
|
1
|
0
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
1
|
2
|
|
46
|
1
|
|
33
|
|
|
8
|
|
47
|
1
|
50
|
|
|
|
4
|
my ($class, $key, $hash) = @_; $hash or Carp::croak("missing args: \$hash"); |
48
|
25
|
|
|
25
|
|
194
|
Carp::cluck("Amon2->add_config() method was deprecated."); |
|
25
|
|
|
|
|
67
|
|
|
25
|
|
|
|
|
10708
|
|
49
|
1
|
|
|
|
|
6
|
|
50
|
1
|
|
|
5
|
|
10
|
# This method will be deprecated. |
|
1
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
24
|
|
51
|
1
|
|
|
|
|
7
|
$class->config->{$key} = +{ |
52
|
|
|
|
|
|
|
%{$class->config->{$key} || +{}}, |
53
|
|
|
|
|
|
|
%{$hash}, |
54
|
0
|
|
|
0
|
1
|
0
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
2
|
100
|
|
2
|
1
|
5789
|
|
57
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
# Pluggable things. |
59
|
2
|
50
|
|
2
|
1
|
149
|
|
|
2
|
|
|
|
|
8
|
|
60
|
2
|
|
|
|
|
324
|
my ($class, @args) = @_; |
61
|
|
|
|
|
|
|
while (@args) { |
62
|
|
|
|
|
|
|
my $module = shift @args; |
63
|
|
|
|
|
|
|
my $conf = @args>0 && ref($args[0]) eq 'HASH' ? shift @args : undef; |
64
|
2
|
50
|
|
|
|
12
|
$class->load_plugin($module, $conf); |
65
|
2
|
|
|
|
|
82
|
} |
|
2
|
|
|
|
|
8
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my ($class, $module, $conf) = @_; |
69
|
|
|
|
|
|
|
$module = Plack::Util::load_class($module, 'Amon2::Plugin'); |
70
|
|
|
|
|
|
|
$module->init($class, $conf); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
11
|
|
|
11
|
1
|
26661
|
# ------------------------------------------------------------------------- |
74
|
11
|
|
|
|
|
43
|
# Local context maker. |
75
|
13
|
|
|
|
|
42
|
|
76
|
13
|
100
|
100
|
|
|
74
|
my $class = shift; |
77
|
13
|
|
|
|
|
101
|
|
78
|
|
|
|
|
|
|
## Mo critic. |
79
|
|
|
|
|
|
|
eval sprintf(q{ |
80
|
|
|
|
|
|
|
package %s; |
81
|
|
|
|
|
|
|
|
82
|
15
|
|
|
15
|
1
|
362
|
sub context { $%s::CONTEXT } |
83
|
15
|
|
|
|
|
74
|
|
84
|
15
|
|
|
|
|
239
|
sub set_context { $%s::CONTEXT = $_[1] } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub context_guard { |
87
|
|
|
|
|
|
|
Amon2::ContextGuard->new($_[0], \$%s::CONTEXT); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
}, $class, $class, $class, $class); |
90
|
|
|
|
|
|
|
die $@ if $@; |
91
|
1
|
|
|
1
|
0
|
134
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
1
|
|
|
7
|
|
87
|
|
|
7
|
|
|
1
|
|
8539
|
|
|
1
|
|
|
3
|
|
32
|
|
|
3
|
|
|
|
|
32
|
|
95
|
|
|
|
|
|
|
=encoding utf-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Amon2 - lightweight web application framework |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package MyApp; |
104
|
|
|
|
|
|
|
use parent qw/Amon2/; |
105
|
1
|
50
|
|
|
|
19
|
use Amon2::Config::Simple; |
106
|
|
|
|
|
|
|
sub load_config { Amon2::Config::Simple->load(shift) } |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Amon2 is simple, readable, extensible, B<STABLE>, B<FAST> web application framework based on L<Plack>. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 CLASS METHODS for C<< Amon2 >> class |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item my $c = MyApp->context(); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Get the context object. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item MyApp->set_context($c) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Set your context object(INTERNAL USE ONLY). |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 CLASS METHODS for inherited class |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 4 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item C<< MyApp->config() >> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This method returns configuration information. It is generated by C<< MyApp->load_config() >>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item C<< MyApp->mode_name() >> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This is a mode name for Amon2. The default implementation of this method is: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub mode_name { $ENV{PLACK_ENV} } |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
You can override this method if you want to determine the mode by other method. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item C<< MyApp->new() >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Create new context object. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item C<< MyApp->bootstrap() >> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $c = MyApp->bootstrap(); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Create new context object and set it to global context. When you are writing CLI script, setup the global context object by this method. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item C<< MyApp->base_dir() >> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This method returns the application base directory. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item C<< MyApp->load_plugin($module_name[, \%config]) >> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This method loads the plugin for the application. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
I<$module_name> package name of the plugin. You can write it as two form like L<DBIx::Class>: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
__PACKAGE__->load_plugin("Web::CSRFDefender"); # => loads Amon2::Plugin::Web::CSRFDefender |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
If you want to load a plugin in your own name space, use the '+' character before a package name, like following: |
167
|
|
|
|
|
|
|
__PACKAGE__->load_plugin("+MyApp::Plugin::Foo"); # => loads MyApp::Plugin::Foo |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C<< MyApp->load_plugins($module_name[, \%config ], ...) >> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Load multiple plugins at one time. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
If you want to load a plugin in your own name space, use the '+' character before a package name like following: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__PACKAGE__->load_plugins("+MyApp::Plugin::Foo"); # => loads MyApp::Plugin::Foo |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item C<< MyApp->load_config() >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
You can get a configuration hashref from C<< config/$ENV{PLACK_ENV}.pl >>. You can override this method for customizing configuration loading method. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item C<< MyApp->add_config() >> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
DEPRECATED. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item C<< MyApp->debug_mode() >> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
B<((EXPERIMENTAL))> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This method returns a boolean value. It returns true when $ENV{AMON2_DEBUG} is true value, false otherwise. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
You can override this method if you need. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=back |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 PROJECT LOCAL MODE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
B<THIS MODE IS HIGHLY EXPERIMENTAL> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Normally, Amon2's context is stored in a global variable. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This module makes the context to project local. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
It means, normally context class using Amon2 use C<$Amon2::CONTEXT> in each project, but context class using L</PROJECT LOCAL MODE> use C<$MyApp::CONTEXT>. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
B<<< It means you can't use code depend C<<Amon2->context>> and C<<Amon2->context>> under this mode. >>>> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 NOTES ABOUT create_request |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Older L<Amon2::Web::Request> has only 1 argument like following, it uses C<< Amon2->context >> to get encoding: |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub create_request { |
212
|
|
|
|
|
|
|
my ($class, $env) = @_; |
213
|
|
|
|
|
|
|
Amon2::Web::Request->new($env); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
If you want to use L</PROJECT LOCAL MODE>, you need to pass class name of context class, as following: |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub create_request { |
219
|
|
|
|
|
|
|
my ($class, $env) = @_; |
220
|
|
|
|
|
|
|
Amon2::Web::Request->new($env, $class); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 HOW DO I ENABLE PROJECT LOCAL MODE? |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
C< MyApp->make_local_context() > turns on the project local mode. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
There is no way to revert it, thanks. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 METHODS |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This module inserts 3 methods to your context class. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=over 4 |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item MyApp->context() |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Shorthand for $MyApp::CONTEXT |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item MyApp->set_context($context) |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
It's the same as: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
$MyApp::CONTEXT = $context |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item my $guard = MyApp->context_guard() |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Create new context guard class. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
It's the same as: |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Amon2::ContextGuard->new(shift, \$MyApp::CONTEXT); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=back |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 DOCUMENTS |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
More complicated documents are available on L<http://amon.64p.org/> |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 SUPPORTS |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
#amon at irc.perl.org is also available. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 AUTHOR |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=over 4 |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item noblejasper |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item hiratara |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item s-aska |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item Kentaro Kuribayashi |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item Yuki Ibe |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item mattn |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item Masahiro Nagano |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item rightgo09 |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item karupanerura |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item hatyuki |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item Keiji, Yoshimi |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item Nishibayashi Takuji |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item dragon3 |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item Fuji, Goro |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=item issm |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item hisaichi5518 |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item Adrian |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=item Fuji, Goro |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=item ITO Nobuaki |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=item Geraud CONTINSOUZAS |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=item Syohei YOSHIDA |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item magnolia |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item Katsuhiro Konishi |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=back |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head1 LICENSE |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |