1 package Reaction::UI::Controller::Root;
4 use Reaction::UI::Window;
6 BEGIN { extends 'Reaction::UI::Controller'; }
10 content_type => 'text/html',
13 has 'view_name' => (isa => 'Str', is => 'rw', required => 1);
14 has 'content_type' => (isa => 'Str', is => 'rw', required => 1);
15 has 'window_title' => (
16 isa => 'Str', is => 'rw', predicate => 'has_window_title'
20 my ($self, $ctx) = @_;
22 window => Reaction::UI::Window->new(
24 view_name => $self->view_name,
25 content_type => $self->content_type,
26 ($self->has_window_title
27 ? (title => $self->window_title)
31 my $focus_stack = $ctx->stash->{window}->focus_stack;
32 $focus_stack->loc_prefix('r-vp');
33 $ctx->stash(focus_stack => $focus_stack);
37 my ($self, $ctx) = @_;
38 $ctx->stash->{window}->flush;
41 sub error_404 :Private {
43 $c->res->body("Error 404: Not Found");
45 $c->res->content_type('text/plain');
48 sub error_403 :Private {
50 $c->res->body("Error 403: Forbidden");
52 $c->res->content_type('text/plain');
59 Reaction::UI::Controller::Root - Base component for the Root Controller
63 package MyApp::Controller::Root;
64 use base 'Reaction::UI::Controller::Root';
68 window_title => 'Reaction Test App',
73 $c->self->push_viewport('Reaction::UI::ViewPort', %args);
75 # Access the window title in a template:
80 Using this module as a base component for your L<Catalyst> Root
81 Controller provides automatic creation of a L<Reaction::UI::Window>
82 object containing an empty L<Reaction::UI::FocusStack> for your UI
83 elements. The stack is also resolved and rendered for you in the
86 At the C<begin> of each request, the Window object is
87 created using the configured L</view_name>, L</content_type> and
88 L</window_title>. These thus should be directly changed on the stashed
89 window object at runtime, if needed.
97 =item Arguments: $viewname?
101 Set or retrieve the classname of the view used to render the UI. Can
102 also be set by a call to config. Defaults to 'XHTML'.
108 =item Arguments: $contenttype?
112 Set or retrieve the content type of the page created. Can also be set
113 by a call to config or in a config file. Defaults to 'text/html'.
119 =item Arguments: $windowtitle?
123 Set or retrieve the title of the page created. Can also be set by a
124 call to config or in a config file. No default.
130 Stuffs a new L<Reaction::UI::Window> object into the stash, using the
131 L</view_name> and L</content_type> provided in the
132 L<configuration|/SYNOPSIS>.
134 Make sure you call this base C<begin> action if writing your own.
138 Draws the UI via the L<Reaction::UI::Window/flush> method.
144 Sets $c->res (the L<Catalyst::Response>) body, status and content type
145 to output a 404 (File not found) error.
149 Sets $c->res (the L<Catalyst::Response>) body, status and content type
150 to output a 403 (Forbidden) error.
155 See L<Reaction::Class> for authors.
159 See L<Reaction::Class> for the license.