@@ -89,18 +89,9 @@ A slightly shorter version with state variables and no ping:
89
89
90
90
# Use $self->dbh from here on ...
91
91
92
- sub some_route {
93
- my $self = shift;
94
-
95
- $self->dbh->selectrow_array(q[
96
- SELECT * FROM users
97
- WHERE clue > 0
98
- ]);
99
- }
100
-
101
92
Same methods can be used for accessing the schema of L<DBIx::Class>.
102
93
103
- =head2 Custom 404 and 500 error pages
94
+ =head2 Custom error pages
104
95
105
96
=head3 Error templates
106
97
@@ -112,49 +103,14 @@ C<< $self->res->render_error >>.
112
103
113
104
=head3 Within the route
114
105
115
- You can set the response headers and content within the route:
106
+ For one-off rendering of errors, you can alternatively set the response headers
107
+ and content within the route:
116
108
117
109
sub some_route {
118
110
my $self = shift;
119
111
$self->res->set_code(404)->template('my_404_template');
120
112
}
121
113
122
- =head3 By overriding the Kelp::Response class
123
-
124
- To make custom 500, 404 and other error pages, you will have to subclass the
125
- L<Kelp::Response> module and override the I<render_404> and I<render_500> subroutines.
126
- Let's say your app's name is Foo and its class is in I<lib/Foo.pm>. Now create a
127
- file I<lib/Foo/Response.pm>:
128
-
129
- package Foo::Response;
130
- use Kelp::Base 'Kelp::Response';
131
-
132
- sub render_404 {
133
- my $self = shift;
134
- $self->template('my_custom_404');
135
- }
136
-
137
- sub render_500 {
138
- my $self = shift;
139
- $self->template('my_custom_500');
140
- }
141
-
142
- Then, in I<lib/Foo.pm>, you have to tell Kelp to use your custom response class
143
- like this:
144
-
145
- sub response {
146
- my $self = shift;
147
- return Foo::Response->new( app => $self );
148
- }
149
-
150
- Don't forget you need to create I<views/my_custom_404.tt> and
151
- I<views/my_custom_500.tt>. You can add other error rendering subroutines too, for
152
- example:
153
-
154
- sub render_401 {
155
- # Render your custom 401 error here
156
- }
157
-
158
114
=head2 Altering the behavior of a Kelp class method
159
115
160
116
The easiest solution would be to use L<KelpX::Hooks> module available on CPAN:
@@ -228,9 +184,14 @@ use L<Plack::Middleware::ReverseProxy>.
228
184
229
185
(REMOTE_ADDR is not set at all when using the proxy via filesocket).
230
186
231
- =head2 Changing the default access logging
187
+ =head2 Changing the default logging
188
+
189
+ Default log format can be modified by configuring the C<Logger> module. See
190
+ L<Kelp::Module::Logger/date_format> and L<Kelp::Module::Logger/log_format>.
191
+ Alternatively, L<Log::Dispatch> can be configured with its own callback to
192
+ format the message to be logged.
232
193
233
- Access logs reported by Kelp through C<logger > can be modified or disabled by
194
+ Access logs reported by Kelp through C<Logger > can be modified or disabled by
234
195
writing your own customized L<Kelp/before_dispatch> method (not calling the
235
196
parent version).
236
197
0 commit comments