aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/Manual/Clipboard.pod
blob: eb92f50822513dac2fa68c64e81f4ef3859ecee9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
=head1 NAME

Reaction::Manual::Clipboard - snippets of Reaction docs



=head2 These should probably go in the glossary.

=over

=item Domain Model 

DBIx::Class::Schema, MyApp::Foo, MyApp::Bar, etc.

=item Interface Model 

InterfaceModel::DBIC::Schema, InterfaceModel::Action,
MyApp::InterfaceModel::Foo classes.

=item Controller 

Mediation and navigation.

=item ViewPort

Event handling encapsulation.

=item Widget

View logic.

=item Renderer 

MyApp::View:: classes, renders viewports.

=back


These should go in the tutorial?


=head1 SETTING UP A REACTION APPLICATION

Reaction applications are set up just like Catalyst:

    $ catalyst.pl MyApp
    # output ommited
    $ cd MyApp

=head2 Models

Reaction provides a reflector component which automagically
maps a L<DBIx::Class::Schema> into a set of Interface Models which can be used
by Reaction to build the interface components. If you're not familiar with
L<DBIx::Class> or don't have a schema handy, now is a good time to go through
L<DBIx::Class::Manual::Intro> to get a schema set up.

It is important that your Result-objects implement the meta-protocol of Moose.
One way to achive that is to do the following:

    package MyApp::Schema::Result::Bar;
    use base 'DBIx::Class';
    use Moose;
    
    has 'name' => (isa => 'Str', required => 1, rw => 1);
    
    use namespace::autoclean;
    
    __PACKAGE__->load_components(qw(Core));
    __PACKAGE__->table('bar');
    __PACKAGE__->add_columns(
        name => {
            data_type   => 'varchar',
            size        => 255,
            is_nullable => 0,
        }
    );
    __PACKAGE__->primary_key('name');
    1;
    
Once you have your schema set up like that, you can create the InferfaceModel:

    package MyApp::InterfaceModel::DBIC;

    use base 'Reaction::InterfaceModel::Object';
    use Reaction::InterfaceModel::Reflector::DBIC;

    my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new;

    $reflector->reflect_schema(
         model_class  => __PACKAGE__,
         schema_class => 'MyApp::Schema',
         sources => [qw/Foo Baz/],
    );

    1;

Then you create a MyApp::Model that uses this InferfaceModel:

    package Myapp::Model::IM;
    
    use Reaction::Class;
    
    extends 'Catalyst::Model::Reaction::InterfaceModel::DBIC';

    1;
    
=head2 Controllers

=head3 Root controller

Your Reaction application must have a Root controller which inherits from
C<Reaction::UI::Controller::Root>.

    package MyApp::Controller::Root;

    use warnings;
    use strict;
    use base qw/Reaction::UI::Controller::Root/;

    __PACKAGE__->config(
        view_name => 'Site',
        window_title => 'My Reaction App',
        namespace => ''
    );

    sub base : Chained('/') PathPart('') CaptureArgs(0) {
        # do some setup for every request
        # also provides a chain root for other controllers to use
    }

    1;

=head3 Individual controllers

For each Collection(table?) in your DB, you need to create a controller

    package MyApp::Controller::Foo;

    use base 'Reaction::UI::Controller::Collection::CRUD';
    use Reaction::Class;

    __PACKAGE__->config(
      model_name => 'IM',   # This corresponds to the name of the MyApp::Model you created earlier
      collection_name => 'Foo', # Name of one of the sources in your InterfaceModel
      action => {
        base => { Chained => '/base',  # chain to the base action in the root controller
                  PathPart => 'foo' },
      },
    );

    1;
    
XX TODO

=head2 View

One of the views in your application should look something like this:

    package MyApp::View::TT;

    use Reaction::Class;

    extends 'Reaction::UI::View::TT';

    1;

    __END__;

    
XX TODO

=head1 SEE ALSO

=over 

=item * L<Reaction::Manual::Cookbook>

=item * L<Reaction::Manual::FAQ>

=back

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut