3 Reaction::Manual::Intro - Introduction to Reaction
7 Reaction is basically an extended MVC:
13 DBIx::Class::Schema, MyApp::Foo, MyApp::Bar, etc.
17 InterfaceModel::DBIC::Schema, InterfaceModel::Action,
18 MyApp::InterfaceModel::Foo classes.
22 Mediation and navigation.
26 Event handling encapsulation.
34 MyApp::View:: classes, renders viewports.
38 =head1 THE REACTION WAY
40 The idea is you separate your domain model, which encapsulates the domain
41 itself from your interface model, which is a model of how a particular app or
42 class of apps interact with that domain and provides objects/methods to
43 encapsulate the common operations it does.
45 =head2 Domain Models vs Interface Models
47 Domain models are expected to drive the application business logic and data.
48 All domain models that need to be effectively displayed somehow at the user
49 interface (a table, for instance) must interact with an interface model.
50 These should provide the common methods needed in order to carry out
51 user-generated events.
53 =head1 SETTING UP A REACTION APPLICATION
55 Reaction applications are set up just like Catalyst:
63 Reaction provides a reflector component which automagically
64 maps a L<DBIx::Class::Schema> into a set of Interface Models which can be used
65 by Reaction to build the interface components. If you're not familiar with
66 L<DBIx::Class> or don't have a schema handy, now is a good time to go through
67 L<DBIx::Class::Manual::Intro> to get a schema set up.
69 It is important that your Result-objects implement the meta-protocol of Moose
70 One way to achive that is to do the following:
72 package MyApp::Schema::Result::Bar;
73 use base 'DBIx::Class';
76 has 'name' => (isa => 'Str', required => 1, rw => 1);
78 use namespace::clean -except => [ 'meta' ];
80 __PACKAGE__->load_components(qw(Core));
81 __PACKAGE__->table('bar');
82 __PACKAGE__->add_columns(
84 data_type => 'varchar',
89 __PACKAGE__->primary_key('name');
92 Once you have your schema set up like that, you can create the InferfaceModel:
94 package MyApp::InterfaceModel::DBIC;
96 use base 'Reaction::InterfaceModel::Object';
97 use Reaction::InterfaceModel::Reflector::DBIC;
99 my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new;
101 $reflector->reflect_schema(
102 model_class => __PACKAGE__,
103 schema_class => 'MyApp::Schema',
104 sources => [qw/Foo Baz/],
109 Then you create a MyApp::Model that uses this InferfaceModel:
111 package Myapp::Model::IM;
115 extends 'Catalyst::Model::Reaction::InterfaceModel::DBIC';
121 =head3 Root controller
123 Your Reaction application must have a Root controller which inherits from
124 C<Reaction::UI::Controller::Root>.
126 package MyApp::Controller::Root;
130 use base qw/Reaction::UI::Controller::Root/;
134 window_title => 'My Reaction App',
138 sub base : Chained('/') PathPart('') CaptureArgs(0) {
139 # do some setup for every request
140 # also provides a chain root for other controllers to use
145 =head3 Individual controllers
147 For each Collection(table?) in your DB, you need to create a controller
149 package MyApp::Controller::Foo;
151 use base 'Reaction::UI::Controller::Collection::CRUD';
155 model_name => 'IM', # This corresponds to the name of the MyApp::Model you created earlier
156 collection_name => 'Foo', # Name of one of the sources in your InterfaceModel
158 base => { Chained => '/base', # chain to the base action in the root controller
169 One of the views in your application should look something like this:
171 package MyApp::View::TT;
175 extends 'Reaction::UI::View::TT';
188 =item * L<Reaction::Manual::Cookbook>
190 =item * L<Reaction::Manual::FAQ>
196 See L<Reaction::Class> for authors.
200 See L<Reaction::Class> for the license.