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