Commit | Line | Data |
89b70ba7 |
1 | package Reaction::UI::Controller::Root; |
7adfd53f |
2 | |
3 | use base qw/Reaction::UI::Controller/; |
4 | use Reaction::Class; |
5 | use Reaction::UI::Window; |
6 | |
7 | __PACKAGE__->config( |
8 | view_name => 'XHTML', |
9 | content_type => 'text/html', |
10 | ); |
11 | |
8996aa3f |
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' |
16 | ); |
7adfd53f |
17 | |
18 | sub 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 | |
33 | sub end :Private { |
1810d302 |
34 | my ($self, $ctx) = @_; |
35 | $ctx->stash->{window}->flush; |
7adfd53f |
36 | } |
37 | |
cb92a3a3 |
38 | sub 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 | |
45 | sub 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 |
52 | 1; |
53 | |
54 | =head1 NAME |
55 | |
68f88d4e |
56 | Reaction::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: |
70 | $c->stash->{focus_stack}->push_viewport('Reaction::UI::ViewPort'); |
71 | |
72 | # Access the window title in a template: |
73 | [% window.title %] |
74 | |
75 | =head1 DESCRIPTION |
76 | |
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 |
81 | C<end> action. |
82 | |
bdc404da |
83 | At the C<begin> of each request, a L<Reaction::UI::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. |
87 | |
7adfd53f |
88 | =head1 METHODS |
89 | |
90 | =head2 view_name |
91 | |
92 | =over |
93 | |
94 | =item Arguments: $viewname? |
95 | |
96 | =back |
97 | |
c2bd9d41 |
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'. |
7adfd53f |
100 | |
101 | =head2 content_type |
102 | |
103 | =over |
104 | |
105 | =item Arguments: $contenttype? |
106 | |
107 | =back |
108 | |
c2bd9d41 |
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'. |
7adfd53f |
111 | |
112 | =head2 window_title |
113 | |
114 | =over |
115 | |
116 | =item Arguments: $windowtitle? |
117 | |
118 | =back |
119 | |
c2bd9d41 |
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. |
7adfd53f |
122 | |
123 | =head1 AUTHORS |
124 | |
125 | See L<Reaction::Class> for authors. |
126 | |
127 | =head1 LICENSE |
128 | |
129 | See L<Reaction::Class> for the license. |
130 | |
131 | =cut |