If you've peeked at the Controller then you've noticed, it's pretty bare.
The sole function of the controller is to provide you with a package to override your methods in.
For example:
use base 'GenieMod::Controller';
sub action_this_or_that {
my($self,$req) = (shift,shift);
return($req->get_view('ok');
}
If you don't like the way it looks up the actions, you can change the find_action() method, if
you have any initialization methods (and you want to make it easy on yourself) go ahead and
override the init() method.
If you've read about MVC, it should be obvious at this point that sending any output to the browser while in the controller is a bad idea, this is the logic behind returning a view. (the "return($req->get_view())" bit)
In FastCGI environments, the controller object remains intact for each request. This is a very important thing to bear in mind, as it allows you to cache expensive objects (database handles are a classic example) It has a downside however, if you place any data specific to a request, (such as a client code) that information may hang around for the next page request.
For this reason, all the methods take as a second parameter a GenieMod::Request
object. This " $req" as it's known, is the correct place to store such information.
The default way GenieMod::Controller locates an action is via form variables. This works out
nice since you can have multiple submit buttons.
If you'd rather use a "path based" approach, you can simply change the find_action() method (or
override it, your choice)
At this point I'll remind the casual reader that the whole point of this exercises is that MVC isn't hard to implement yourself, the package presented here are merely provided as a starting ground. Go ahead and copy them to your project and make modifications directly to the source if you like. (Of course you may wish to change their package names too, this is up to you)
This simply returns a hash of keys, it is used to map form variable names to their method names. (You wouldn't want people to be able to run arbitrary methods in your controller would you?)
By default, these are from the configuration object. (Config::General).
If no action is found, the controller will run default_index($request)