squelch a warning in Reaction::Class, port from BindLex to Component::ACCEPT_CONTEXT
[catagits/Reaction.git] / lib / Reaction / UI / Controller / Root.pm
1 package Reaction::UI::Controller::Root;
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) = @_;
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);
27 }
28
29 sub end :Private {
30   my ($self, $ctx) = @_;
31   $ctx->stash->{window}->flush;
32 }
33
34 1;
35
36 =head1 NAME
37
38 Reaction::UI::Controller::Root - Base component for the Root Controller
39
40 =head1 SYNOPSIS
41
42   package MyApp::Controller::Root;
43   use base 'Reaction::UI::Controller::Root';
44
45   __PACKAGE__->config(
46     view_name => 'Site',
47     window_title => 'Reaction Test App',
48     namespace => ''
49   );
50
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
59 Using this module as a base component for your L<Catalyst> Root
60 Controller provides automatic creation of a L<Reaction::UI::Window>
61 object containing an empty L<Reaction::UI::FocusStack> for your UI
62 elements. The stack is also resolved and rendered for you in the
63 C<end> action.
64
65 At the C<begin> of each request, a L<Reaction::UI::Window> object is
66 created using the configured L</view_name>, L</content_type> and
67 L</window_title>. These thus should be directly changed on the stashed
68 window object at runtime, if needed.
69
70 =head1 METHODS
71
72 =head2 view_name
73
74 =over
75
76 =item Arguments: $viewname?
77
78 =back
79
80 Set or retrieve the classname of the view used to render the UI. Can
81 also be set by a call to config. Defaults to 'XHTML'.
82
83 =head2 content_type
84
85 =over
86
87 =item Arguments: $contenttype?
88
89 =back
90
91 Set or retrieve the content type of the page created. Can also be set
92 by a call to config or in a config file. Defaults to 'text/html'.
93
94 =head2 window_title
95
96 =over
97
98 =item Arguments: $windowtitle?
99
100 =back
101
102 Set or retrieve the title of the page created. Can also be set by a
103 call to config or in a config file. No default.
104
105 =head1 AUTHORS
106
107 See L<Reaction::Class> for authors.
108
109 =head1 LICENSE
110
111 See L<Reaction::Class> for the license.
112
113 =cut