add a default 404 and 403 action, use the 404 on collection controller, make html...
[catagits/Reaction.git] / lib / Reaction / UI / Controller / Root.pm
CommitLineData
89b70ba7 1package Reaction::UI::Controller::Root;
7adfd53f 2
3use base qw/Reaction::UI::Controller/;
4use Reaction::Class;
5use Reaction::UI::Window;
6
7__PACKAGE__->config(
8 view_name => 'XHTML',
9 content_type => 'text/html',
10);
11
12has 'view_name' => (isa => 'Str', is => 'rw');
13has 'content_type' => (isa => 'Str', is => 'rw');
14has 'window_title' => (isa => 'Str', is => 'rw');
15
16sub begin :Private {
17 my ($self, $ctx) = @_;
1810d302 18 $ctx->stash(
19 window => Reaction::UI::Window->new(
20 ctx => $ctx,
21 view_name => $self->view_name,
22 content_type => $self->content_type,
23 title => $self->window_title,
24 )
25 );
26 $ctx->stash(focus_stack => $ctx->stash->{window}->focus_stack);
7adfd53f 27}
28
29sub end :Private {
1810d302 30 my ($self, $ctx) = @_;
31 $ctx->stash->{window}->flush;
7adfd53f 32}
33
cb92a3a3 34sub error_404 :Private {
35 my ($self, $c) = @_;
36 $c->res->body("Error 404: File not Found");
37 $c->res->status(404);
38}
39
40sub error_403 :Private {
41 my ($self, $c) = @_;
42 $c->res->body("Error 403: Forbidden");
43 $c->res->status(403);
44}
45
7adfd53f 461;
47
48=head1 NAME
49
68f88d4e 50Reaction::UI::Controller::Root - Base component for the Root Controller
7adfd53f 51
52=head1 SYNOPSIS
53
54 package MyApp::Controller::Root;
68f88d4e 55 use base 'Reaction::UI::Controller::Root';
7adfd53f 56
c2bd9d41 57 __PACKAGE__->config(
58 view_name => 'Site',
59 window_title => 'Reaction Test App',
60 namespace => ''
61 );
62
7adfd53f 63 # Create UI elements:
64 $c->stash->{focus_stack}->push_viewport('Reaction::UI::ViewPort');
65
66 # Access the window title in a template:
67 [% window.title %]
68
69=head1 DESCRIPTION
70
71Using this module as a base component for your L<Catalyst> Root
72Controller provides automatic creation of a L<Reaction::UI::Window>
73object containing an empty L<Reaction::UI::FocusStack> for your UI
74elements. The stack is also resolved and rendered for you in the
75C<end> action.
76
bdc404da 77At the C<begin> of each request, a L<Reaction::UI::Window> object is
78created using the configured L</view_name>, L</content_type> and
79L</window_title>. These thus should be directly changed on the stashed
80window object at runtime, if needed.
81
7adfd53f 82=head1 METHODS
83
84=head2 view_name
85
86=over
87
88=item Arguments: $viewname?
89
90=back
91
c2bd9d41 92Set or retrieve the classname of the view used to render the UI. Can
93also be set by a call to config. Defaults to 'XHTML'.
7adfd53f 94
95=head2 content_type
96
97=over
98
99=item Arguments: $contenttype?
100
101=back
102
c2bd9d41 103Set or retrieve the content type of the page created. Can also be set
104by a call to config or in a config file. Defaults to 'text/html'.
7adfd53f 105
106=head2 window_title
107
108=over
109
110=item Arguments: $windowtitle?
111
112=back
113
c2bd9d41 114Set or retrieve the title of the page created. Can also be set by a
115call to config or in a config file. No default.
7adfd53f 116
117=head1 AUTHORS
118
119See L<Reaction::Class> for authors.
120
121=head1 LICENSE
122
123See L<Reaction::Class> for the license.
124
125=cut