line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RapidApp::Responder; |
2
|
6
|
|
|
6
|
|
2836
|
use Moose; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
27
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RapidApp::Responder |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package MyModule; |
11
|
|
|
|
|
|
|
sub content { |
12
|
|
|
|
|
|
|
if ($error) die RapidApp::Responser::MyErrorResponder->new(\%params); |
13
|
|
|
|
|
|
|
return RapidApp::Responser::MyNormalResponder->new(\%params); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
A "Responder" is much like a Catalyst::View, except it is designed to be allocated per request, |
19
|
|
|
|
|
|
|
and it can be thrown. This is much more convenient and less error-prone than setting view |
20
|
|
|
|
|
|
|
parameters, putting the view name in the stash, and forwarding to the view. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
In fact, I would have naamed the class "View" if that weren't so likely to lead to confusion. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 action |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
For interoperability with Catalyst, a Responder can be converted into a Catalyst::Action. This |
29
|
|
|
|
|
|
|
attribute will create or return a cached Action object which runs this responder. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'action' => ( is => 'ro', lazy_build => 1, init_arg => undef ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_action { |
36
|
0
|
|
|
0
|
|
|
my $self= shift; |
37
|
0
|
|
|
|
|
|
my $cls= ref $self; |
38
|
0
|
|
|
|
|
|
return Catalyst::Action->new({ |
39
|
|
|
|
|
|
|
name => 'writeResponse', |
40
|
|
|
|
|
|
|
code => $self->can('writeResponse'), |
41
|
|
|
|
|
|
|
reverse => $cls.'->writeResponse', |
42
|
|
|
|
|
|
|
class => $self, |
43
|
|
|
|
|
|
|
namespace => $cls, |
44
|
|
|
|
|
|
|
}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 $responder->writeResponde($c) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This is the main processing method of Responder, much like View->process($c); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
It fills in the fields of $c->response |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub writeResponse { |
58
|
0
|
|
|
0
|
0
|
|
my ($self, $c)= @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$c->response->status(500); |
61
|
0
|
|
|
|
|
|
$c->response->content_type("text/plain"); |
62
|
0
|
|
|
|
|
|
$c->response->body("Unable to generate content for ".$c->stash->{requestContentType}); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
6
|
|
32791
|
no Moose; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
35
|
|
66
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
67
|
|
|
|
|
|
|
1; |