Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: RFC: Apache::Controller

by Joost (Canon)
on Dec 02, 2004 at 23:26 UTC ( [id://411993]=note: print w/replies, xml ) Need Help??


in reply to RFC: Apache::Controller

First things first: I don't think the "perfect" framework for web applications has been invented yet, so ++ for giving it a shot.

One thing I don't like is that the template is too tightly coupled to the action - it's entirely possible that several related actions want to use the same template, or for an action to have more than one resulting template.

For instance:
form -> (submit action) -> form again, with missing data highlighted -> (submit action) -> confirmation screen.

By deriving the template name from the classname of the action you need to create extra templates that will probably only include the "real" template.

Also, I'm sceptical about using classes to describe actions. See my comment in the CGI::Prototype thread.

Lastly, I would like more hooks in the code - some place to do general setup or session management would be nice for instance (maybe by inheriting from the Apache::Controller). See CGI::Application and CGI::Prototype for examples :-)

Replies are listed 'Best First'.
Re^2: RFC: Apache::Controller
by revdiablo (Prior) on Dec 03, 2004 at 18:30 UTC

    Thanks for your comments! I will definitely give them some more thought, but here are some of my initial reactions.

    First things first: I don't think the "perfect" framework for web applications has been invented yet

    I agree, but before we start off with the wrong idea, I'm not really attempting to build an entire framework. I'm only trying to make one part of it -- the controller. And a very limited controller at that.

    One thing I don't like is that the template is too tightly coupled to the action - it's entirely possible that several related actions want to use the same template

    This is true, and probably something I'll put in eventually. I could easily extend the contructor to take in template names for the actions, along with the module names. I'd keep the default behavior of template name being the same as action name, though, because it's quite convenient.

    or for an action to have more than one resulting template.

    I'm not so sure about this. I would either make the template flexible enough to handle everything the action needs, or to create two different actions.

    Also, I'm sceptical about using classes to describe actions.

    Well, I don't know if this has any bearing on your argument or not, but I'm not really using classes. Just plain old Perl packages. The main purpose they serve is to contain the handler subroutines, but they also make for a nice separation at the filesystem level, which I like.

    Lastly, I would like more hooks in the code - some place to do general setup or session management would be nice for instance

    This is a perfect example of why I don't like the name I've chosen. I'm not attempting to write an end-all, be-all solution, just something that lets me get some stuff done. These features would definitely be useful in many applications, but for what I'm doing, they'd just get in the way. Maybe there's a better way to name my module that conveys that message?

      or for an action to have more than one resulting template.
      I'm not so sure about this. I would either make the template flexible enough to handle everything the action needs, or to create two different actions
      But how do you know what action is going to get run, then?

      See my example about form validation above. Basically, you recieve data from "form 1" ( to an action) , and you want to either a) go back to a form 1. b) proceed to form 2, and try to submit that (repeat for form 2, 3 etc.).

      In your system you will need to include form 1 and form 2 into one template just because the action can't choose the template for you. It's certainly possible to do that, but I think it will get ugly very quickly.

        Basically, you recieve data from "form 1" ( to an action) , and you want to either a) go back to a form 1. b) proceed to form 2, and try to submit that (repeat for form 2, 3 etc.).

        I would make Form 1 and Form 2 two separate actions. Form 1 would submit to itself. If stuff was missing, it would return parameters that let the Form 1 template give an appropriate error message. If everything was fine, it would redirect to Form 2.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found