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 my $focus_stack = $ctx->stash->{window}->focus_stack;
31 $focus_stack->loc_prefix('r-vp');
32 $ctx->stash(focus_stack => $focus_stack);
36 my ($self, $ctx) = @_;
37 $ctx->stash->{window}->flush;
40 sub error_404 :Private {
42 $c->res->body("Error 404: Not Found");
44 $c->res->content_type('text/plain');
47 sub error_403 :Private {
49 $c->res->body("Error 403: Forbidden");
51 $c->res->content_type('text/plain');
58 Reaction::UI::Controller::Root - Base component for the Root Controller
62 package MyApp::Controller::Root;
63 use base 'Reaction::UI::Controller::Root';
67 window_title => 'Reaction Test App',
72 $c->self->push_viewport('Reaction::UI::ViewPort', %args);
74 # Access the window title in a template:
79 Using this module as a base component for your L<Catalyst> Root
80 Controller provides automatic creation of a L<Reaction::UI::Window>
81 object containing an empty L<Reaction::UI::FocusStack> for your UI
82 elements. The stack is also resolved and rendered for you in the
85 At the C<begin> of each request, the Window object is
86 created using the configured L</view_name>, L</content_type> and
87 L</window_title>. These thus should be directly changed on the stashed
88 window object at runtime, if needed.
96 =item Arguments: $viewname?
100 Set or retrieve the classname of the view used to render the UI. Can
101 also be set by a call to config. Defaults to 'XHTML'.
107 =item Arguments: $contenttype?
111 Set or retrieve the content type of the page created. Can also be set
112 by a call to config or in a config file. Defaults to 'text/html'.
118 =item Arguments: $windowtitle?
122 Set or retrieve the title of the page created. Can also be set by a
123 call to config or in a config file. No default.
129 Stuffs a new L<Reaction::UI::Window> object into the stash, using the
130 L</view_name> and L</content_type> provided in the
131 L<configuration|/SYNOPSIS>.
133 Make sure you call this base C<begin> action if writing your own.
137 Draws the UI via the L<Reaction::UI::Window/flush> method.
143 Sets $c->res (the L<Catalyst::Response>) body, status and content type
144 to output a 404 (File not found) error.
148 Sets $c->res (the L<Catalyst::Response>) body, status and content type
149 to output a 403 (Forbidden) error.
154 See L<Reaction::Class> for authors.
158 See L<Reaction::Class> for the license.