1 package Reaction::UI::Controller::Root;
3 use base qw/Reaction::UI::Controller/;
5 use Reaction::UI::Window;
9 content_type => 'text/html',
12 has 'view_name' => (isa => 'Str', is => 'rw', required => 1);
13 has 'content_type' => (isa => 'Str', is => 'rw', required => 1);
14 has 'window_title' => (
15 isa => 'Str', is => 'rw', predicate => 'has_window_title'
19 my ($self, $ctx) = @_;
21 window => Reaction::UI::Window->new(
23 view_name => $self->view_name,
24 content_type => $self->content_type,
25 ($self->has_window_title
26 ? (title => $self->window_title)
30 $ctx->stash(focus_stack => $ctx->stash->{window}->focus_stack);
34 my ($self, $ctx) = @_;
35 $ctx->stash->{window}->flush;
38 sub error_404 :Private {
40 $c->res->body("Error 404: Not Found");
42 $c->res->content_type('text/plain');
45 sub error_403 :Private {
47 $c->res->body("Error 403: Forbidden");
49 $c->res->content_type('text/plain');
56 Reaction::UI::Controller::Root - Base component for the Root Controller
60 package MyApp::Controller::Root;
61 use base 'Reaction::UI::Controller::Root';
65 window_title => 'Reaction Test App',
70 $c->self->push_viewport('Reaction::UI::ViewPort', %args);
72 # Access the window title in a template:
77 Using this module as a base component for your L<Catalyst> Root
78 Controller provides automatic creation of a L<Reaction::UI::Window>
79 object containing an empty L<Reaction::UI::FocusStack> for your UI
80 elements. The stack is also resolved and rendered for you in the
83 At the C<begin> of each request, the Window object is
84 created using the configured L</view_name>, L</content_type> and
85 L</window_title>. These thus should be directly changed on the stashed
86 window object at runtime, if needed.
94 =item Arguments: $viewname?
98 Set or retrieve the classname of the view used to render the UI. Can
99 also be set by a call to config. Defaults to 'XHTML'.
105 =item Arguments: $contenttype?
109 Set or retrieve the content type of the page created. Can also be set
110 by a call to config or in a config file. Defaults to 'text/html'.
116 =item Arguments: $windowtitle?
120 Set or retrieve the title of the page created. Can also be set by a
121 call to config or in a config file. No default.
127 Stuffs a new L<Reaction::UI::Window> object into the stash, using the
128 L</view_name> and L</content_type> provided in the
129 L<configuration|/SYNOPSIS>.
131 Make sure you call this base C<begin> action if writing your own.
135 Draws the UI via the L<Reaction::UI::Window/flush> method.
141 Sets $c->res (the L<Catalyst::Response>) body, status and content type
142 to output a 404 (File not found) error.
146 Sets $c->res (the L<Catalyst::Response>) body, status and content type
147 to output a 403 (Forbidden) error.
152 See L<Reaction::Class> for authors.
156 See L<Reaction::Class> for the license.