more POD!
[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
8996aa3f 12has 'view_name' => (isa => 'Str', is => 'rw', required => 1);
13has 'content_type' => (isa => 'Str', is => 'rw', required => 1);
14has 'window_title' => (
15 isa => 'Str', is => 'rw', predicate => 'has_window_title'
16);
7adfd53f 17
18sub begin :Private {
19 my ($self, $ctx) = @_;
1810d302 20 $ctx->stash(
21 window => Reaction::UI::Window->new(
22 ctx => $ctx,
23 view_name => $self->view_name,
24 content_type => $self->content_type,
8996aa3f 25 ($self->has_window_title
26 ? (title => $self->window_title)
27 : ()),
1810d302 28 )
29 );
30 $ctx->stash(focus_stack => $ctx->stash->{window}->focus_stack);
7adfd53f 31}
32
33sub end :Private {
1810d302 34 my ($self, $ctx) = @_;
35 $ctx->stash->{window}->flush;
7adfd53f 36}
37
cb92a3a3 38sub error_404 :Private {
39 my ($self, $c) = @_;
cff2e7ec 40 $c->res->body("Error 404: Not Found");
cb92a3a3 41 $c->res->status(404);
cff2e7ec 42 $c->res->content_type('text/plain');
cb92a3a3 43}
44
45sub error_403 :Private {
46 my ($self, $c) = @_;
47 $c->res->body("Error 403: Forbidden");
48 $c->res->status(403);
cff2e7ec 49 $c->res->content_type('text/plain');
cb92a3a3 50}
51
7adfd53f 521;
53
54=head1 NAME
55
68f88d4e 56Reaction::UI::Controller::Root - Base component for the Root Controller
7adfd53f 57
58=head1 SYNOPSIS
59
60 package MyApp::Controller::Root;
68f88d4e 61 use base 'Reaction::UI::Controller::Root';
7adfd53f 62
c2bd9d41 63 __PACKAGE__->config(
64 view_name => 'Site',
65 window_title => 'Reaction Test App',
66 namespace => ''
67 );
68
7adfd53f 69 # Create UI elements:
f1cd5548 70 $c->self->push_viewport('Reaction::UI::ViewPort', %args);
7adfd53f 71
72 # Access the window title in a template:
73 [% window.title %]
74
75=head1 DESCRIPTION
76
77Using this module as a base component for your L<Catalyst> Root
78Controller provides automatic creation of a L<Reaction::UI::Window>
79object containing an empty L<Reaction::UI::FocusStack> for your UI
80elements. The stack is also resolved and rendered for you in the
81C<end> action.
82
f1cd5548 83At the C<begin> of each request, the Window object is
bdc404da 84created using the configured L</view_name>, L</content_type> and
85L</window_title>. These thus should be directly changed on the stashed
86window object at runtime, if needed.
87
f1cd5548 88=head1 ATTRIBUTES
7adfd53f 89
90=head2 view_name
91
92=over
93
94=item Arguments: $viewname?
95
96=back
97
c2bd9d41 98Set or retrieve the classname of the view used to render the UI. Can
99also be set by a call to config. Defaults to 'XHTML'.
7adfd53f 100
101=head2 content_type
102
103=over
104
105=item Arguments: $contenttype?
106
107=back
108
c2bd9d41 109Set or retrieve the content type of the page created. Can also be set
110by a call to config or in a config file. Defaults to 'text/html'.
7adfd53f 111
112=head2 window_title
113
114=over
115
116=item Arguments: $windowtitle?
117
118=back
119
c2bd9d41 120Set or retrieve the title of the page created. Can also be set by a
121call to config or in a config file. No default.
7adfd53f 122
f1cd5548 123=head1 ACTIONS
124
125=head2 begin
126
127Stuffs a new L<Reaction::UI::Window> object into the stash, using the
128L</view_name> and L</content_type> provided in the
129L<configuration|/SYNOPSIS>.
130
131Make sure you call this base C<begin> action if writing your own.
132
133=head2 end
134
135Draws the UI via the L<Reaction::UI::Window/flush> method.
136
137=head1 METHODS
138
139=head2 error_404
140
141Sets $c->res (the L<Catalyst::Response>) body, status and content type
142to output a 404 (File not found) error.
143
144=head2 error_403
145
146Sets $c->res (the L<Catalyst::Response>) body, status and content type
147to output a 403 (Forbidden) error.
148
149
7adfd53f 150=head1 AUTHORS
151
152See L<Reaction::Class> for authors.
153
154=head1 LICENSE
155
156See L<Reaction::Class> for the license.
157
158=cut