[Catalyst] Re: Controllers vs Models
David Storrs
dstorrs at dstorrs.com
Mon Jun 6 06:56:14 CEST 2005
On Jun 5, 2005, at 11:54 PM, Justin Tocci wrote:
> Hi all. I don't think MVC is adequate. Catalyst works something
> like this:
>
> *start*
> --> request from browser
> --> http handler (e.g. apache)
> --> Controller
> <--> Model
> --> Controller
> --> http handler
> --> browser
> *end*
>
Urmm...well, ok, that'll do for a first-order approximation. Don't
forget about Views (not shown), and the fact that Catalyst may have
multiple Controllers and/or Models.
> Real quick and simple, I'd like to see Catalyst take a step in the
> direction of separating out the business logic from the entire design.
Ummm...huh? Separation of business logic from design is the entire /
point/ of the MVC pattern, which Catalyst implements.
> What's wrong with MVC is that business logic has to go somewhere,
> some will make room in the model, some in the controller, probably
> all three in a large application, but it could be separated out
> entirely.
I am not sure that you are really familiar with the MVC pattern. The
Platonic ideal MVC system has all business logic in the Controller,
all state in the Model, and all presentation is handled by the View.
How much more separated out can the business logic get? Or are you
saying that it could be stored off in a config file (or DB)
somewhere? If so, you program needs to interact with those business
rules somehow, so who's job is it to pull those rules in and
interpret them?
>
> *start*
> --> request from browser
> --> view handler (e.g. apache)
> --> Controller <--> bus. logic expressions component
> <--> Model
> --> Controller
> --> view handler
> --> browser
> *end*
>
> Since business logic rightly involves model, view and controller,
> it's ok to put code in the business logic that says to display a
> date a certain way, or multiply a certain field by pi before
> displaying it.
I don't know that anyone was arguing that point...and it seems to
come rather out of left field. Would you like to clarify?
> Some examples of business logic I'd like to see separated out into
> a separate file would work like this; "if user type is admin, then
> allow delete action" (this would affect all pages for admin users),
> "if page type is edit and user type is sales then show edit record
> button", "if country is usa, then date format is mm-dd-yy".
See previous comment about "who pulls this in?"
>
> You could quickly write a base set of rules for admin, sales,
> office, accounting, etc... giving groups permissions on what tables
> they can and can't see, edit, or administer.
Catalyst breaks this out into separate files. Those files happen to
be the various Models and Controllers. I don't understand what you
are trying to gain that isn't already there.
> Or, write a base set of rules for display by the user's language.
> What's "edit" in Spanish anyway?]
Localization is the job of the View.
>
> One beauty of this scheme is that you could probably work out a way
> to re-load the rules on the fly, allowing for lightning-quick
> development and testing.
http://search.cpan.org/~msergeant/Apache-Reload-0.07/Reload.pm
> Another is that you could go many miles further on standard CRUD
> views with a good base of default rules. Default rules would come
> up with good display names for columns by changing under-bars to
> spaces and capitalizing words. On top of that you could single out
> exceptions by writing rules that would override the default, for
> instance, acronyms would need to have rules like, "if column name
> is nasa, then display name is 'NASA'", note that a rule like this
> is good for any page or situation. Some rules will start "if user
> is sales" but they don't all have to. Therein lay the power of rule-
> based rapid application development, a rule has the scope you give
> it. It can affect the entire application or just a single component
> in a very particular situation.
1) Feel free to contribute the Catalyst::Model and
Catalyst::Controller classes to do these things; I would probably use
them.
2) If you write them, please do not do substitutions such as nasa ->
NASA automatically. If my DB schema happens to have been written in
Urdu, where 'nasa' means "number of users" (*), I do not want the
column presentation mangled.
(*) I'm making this up; I don't speak Urdu.
> The adept may recognize that I miss my rule file from WebObjects,
> but the truth is, he who can deliver this functionality in a simple
> way with Perl would gain fame, fortune and honor before all.
You go, then! Let me know how it works out...personally, I'm pretty
happy with Catalyst thus far.
--Dks
More information about the Catalyst
mailing list