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