declaring ->ctx as a weak ref to avoid memory leaks
[catagits/Reaction.git] / lib / Reaction / Manual / Clipboard.pod
CommitLineData
cc4f29bf 1=head1 NAME
2
3Reaction::Manual::Clipboard - snippets of Reaction docs
4
5
6
7=head2 These should probably go in the glossary.
8
9=over
10
11=item Domain Model
12
13DBIx::Class::Schema, MyApp::Foo, MyApp::Bar, etc.
14
15=item Interface Model
16
17InterfaceModel::DBIC::Schema, InterfaceModel::Action,
18MyApp::InterfaceModel::Foo classes.
19
20=item Controller
21
22Mediation and navigation.
23
24=item ViewPort
25
26Event handling encapsulation.
27
28=item Widget
29
30View logic.
31
32=item Renderer
33
34MyApp::View:: classes, renders viewports.
35
36=back
37
38
39These should go in the tutorial?
40
41
42=head1 SETTING UP A REACTION APPLICATION
43
44Reaction applications are set up just like Catalyst:
45
46 $ catalyst.pl MyApp
47 # output ommited
48 $ cd MyApp
49
50=head2 Models
51
52Reaction provides a reflector component which automagically
53maps a L<DBIx::Class::Schema> into a set of Interface Models which can be used
54by Reaction to build the interface components. If you're not familiar with
55L<DBIx::Class> or don't have a schema handy, now is a good time to go through
56L<DBIx::Class::Manual::Intro> to get a schema set up.
57
58It is important that your Result-objects implement the meta-protocol of Moose
59One way to achive that is to do the following:
60
61 package MyApp::Schema::Result::Bar;
62 use base 'DBIx::Class';
63 use Moose;
64
65 has 'name' => (isa => 'Str', required => 1, rw => 1);
66
67 use namespace::clean -except => [ 'meta' ];
68
69 __PACKAGE__->load_components(qw(Core));
70 __PACKAGE__->table('bar');
71 __PACKAGE__->add_columns(
72 name => {
73 data_type => 'varchar',
74 size => 255,
75 is_nullable => 0,
76 }
77 );
78 __PACKAGE__->primary_key('name');
79 1;
80
81Once you have your schema set up like that, you can create the InferfaceModel:
82
83 package MyApp::InterfaceModel::DBIC;
84
85 use base 'Reaction::InterfaceModel::Object';
86 use Reaction::InterfaceModel::Reflector::DBIC;
87
88 my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new;
89
90 $reflector->reflect_schema(
91 model_class => __PACKAGE__,
92 schema_class => 'MyApp::Schema',
93 sources => [qw/Foo Baz/],
94 );
95
96 1;
97
98Then you create a MyApp::Model that uses this InferfaceModel:
99
100 package Myapp::Model::IM;
101
102 use Reaction::Class;
103
104 extends 'Catalyst::Model::Reaction::InterfaceModel::DBIC';
105
106 1;
107
108=head2 Controllers
109
110=head3 Root controller
111
112Your Reaction application must have a Root controller which inherits from
113C<Reaction::UI::Controller::Root>.
114
115 package MyApp::Controller::Root;
116
117 use warnings;
118 use strict;
119 use base qw/Reaction::UI::Controller::Root/;
120
121 __PACKAGE__->config(
122 view_name => 'Site',
123 window_title => 'My Reaction App',
124 namespace => ''
125 );
126
127 sub base : Chained('/') PathPart('') CaptureArgs(0) {
128 # do some setup for every request
129 # also provides a chain root for other controllers to use
130 }
131
132 1;
133
134=head3 Individual controllers
135
136For each Collection(table?) in your DB, you need to create a controller
137
138 package MyApp::Controller::Foo;
139
140 use base 'Reaction::UI::Controller::Collection::CRUD';
141 use Reaction::Class;
142
143 __PACKAGE__->config(
144 model_name => 'IM', # This corresponds to the name of the MyApp::Model you created earlier
145 collection_name => 'Foo', # Name of one of the sources in your InterfaceModel
146 action => {
147 base => { Chained => '/base', # chain to the base action in the root controller
148 PathPart => 'foo' },
149 },
150 );
151
152 1;
153
154XX TODO
155
156=head2 View
157
158One of the views in your application should look something like this:
159
160 package MyApp::View::TT;
161
162 use Reaction::Class;
163
164 extends 'Reaction::UI::View::TT';
165
166 1;
167
168 __END__;
169
170
171XX TODO
172
173=head1 SEE ALSO
174
175=over
176
177=item * L<Reaction::Manual::Cookbook>
178
179=item * L<Reaction::Manual::FAQ>
180
181=back
182
183=head1 AUTHORS
184
185See L<Reaction::Class> for authors.
186
187=head1 LICENSE
188
189See L<Reaction::Class> for the license.
190
191=cut