|
(You are
Anonymous)
|
Note: page has been moved to https://github.com/markstos/CGI--Application/wiki/MVC by Mid Life Xis MVC = Model-View-Controllerby Mark Rajcok For web development, MVC is a term used to describe how to separate a web application into the following three pieces (roughly speaking):
Both the views and controllers comprise the user interface. The model should not have any knowledge of the views. CGI::Application helps you obtain the separation:
package MyOnlineStore;
use strict;
use base 'CGI::Application';
use CGI::Application::Plugin::AutoRunmode;
use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
sub show_items_for_sale : StartRunmode {
my $self = shift;
my $t = $self->load_tmpl('list_of_items.tmpl');
... access some business objects to get the items ...
... populate the template with the data ...
return $t->output
}
sub show_single_item : Runmode {
...
}
sub new_user : Runmode {
...
}
For each runmode, you'll often have an HTML template file, which allows you to cleanly separate your view/presentation/HTML from your controller logic/code. This is particularly handy if you're working with people who don't know Perl, but you want/need them to make changes to the HTML (view/presentation). They simply modify the .tmpl files (and CSS files), while you work on the Perl code. See also |