Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Implementing Model-View-Controller

by philcrow (Priest)
on Jan 04, 2006 at 14:51 UTC ( #520927=note: print w/replies, xml ) Need Help??


in reply to Implementing Model-View-Controller

You have to specify a bit more about your problem to know which way to go. So, allow me to assume you are writing a web app to manage a database.

You could use something like Class::DBI (or DBIx::Class) as your modeler. Then you would make a module inheriting from it that describes a table in your database. That's a model. It maps rows in the database to objects in memory.

Then you need a controller to take data from the user, validate it, calculate additional fields, etc. It interacts closely with the model, by creating new objects (rows) or updating/deleting existing ones.

Finally, you need a way for the user to see the process. That's the view. If you design well with a templating system, you could have a set of standard viewing templates that work for many different controllers even crossing apps. For example, in our system we have a single viewing template for virtually all of our add/edit forms. The controller populates it based on business rules (should the field be visible or calculated later, etc.) and on what is in the model (does the row exist, if so, show the user the data from it).

So, in summary, we use a model class for each table, a controller for each table (usually), and a set of stock viewing templates which are shared by many controllers (with most controllers using at least three templates: add/edit, delete confirmation, and listing of rows).

Phil

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://520927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2021-04-18 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?