Online Games Grumpy Unix Fart Contact Us

Introducing GenieMod

As I might have mentioned.. MVC isn't a framework. What I will do here, is introduce a simplified mvc package that you can use, download, incorporate into your own code and modify to suit your own needs.

For example, it totally lacks any DBI handling capabilities, yet, I've used if for such things by simply extending it.

Overview of GenieMod

GenieMod composes a handful of packages and tests, each of which can be modified. You could use it as an example, but then simply re-implement the portions that don't suit your needs.

    $conf = new Config::General(%CONF_OPTIONS); # Available at CPAN.
    # Used to map views to actions. (So you can have a "text mode" for
    # gopher or lynx if you wanted)
    $viewmap = new GenieMod::View::Map(Conf => $conf);
    #
    # Create controller.
    # 
    $controller = new GenieMod::Controller(Conf => $conf);
      
    # 
    # ... This could run in a loop, for example FastCGI
    #
    {
        $request = GenieMod::Request->create(Cgi => new CGI(), ViewMap => $viewmap);
        # Run this request.     
        $view = $controller->run($request);
          
        # display results.
        $view->display($request)
        $request->finish(); # Not really required, but a good idea.
        
    } # End of request loop, fetch next request if in FastCGI.

Config::General

GenieMod uses Config::General for it's configuration setup, this enables it to store things like the view mappings and action dispatch table in a simple conf file that resembles apache style configurations.


GenieMod::Controller

This is the package you would want to extend

    use base 'GenieMod::Controller';

Or, simply modify if you like.

In persistent environments, (such as FastCGI) it is intended that one Controller instance be kept in memory for rapid servicing.

If you are using DBI or perhaps an XSLT transformer, you'll probably want to keep a copy in the controller so that it can be re-used across requests. (Well, the XSLT transformer should probably go in the view, we'll get to that later)

GenieMod::Request

This represents an incoming request.

This is the place to stick any data that applies only to a given request. Things like account settings or bits of data that need to be passed between various portions of the controller might go here.

GenieMod::View

This represents the "view", you may wish to create your own and extend this package. It is a very simple package. A view can, for example, be an image generated by GD::Chart or a template or whatever you want.

There is a distinct create() method apart from the new() method, this allows you to cache any objects you may want to leave hanging around between views. (A template generator or XSLT transformer might appreciate this)


GenieMod::View::Map

This maps views to their associated objects. GenieMod supports multiple views based on whatever you want by way of a "viewmap" section in the configuration.

GenieMod::View::Template

This is a very fast, easy, no-frills and nothing fancy template engine, it is simply an implementation of GenieMod::View and can be replaced with whatever you want.

It is able to parse templates fast because the templates are dead simple:

  <%# filetype: aspperl; %>
  <%= 5*5; %>
  <% $view->include('file'); %>

That's about it, each template file is compiled into a perl subroutine. The syntax is "asp-like" so that you can easily use syntax highlighting. Yea.. yea.. I know.. it's not popular to put perl code in templates, so, sue me. This approach is fast and simple If you are doing a content system or XML content generation, etc.. you may want to change it. This is easy to do. (It should go without saying.. you don't want anyone to have write access to these.)

GenieMod::View::Template is no big deal!

It bears pointing out there is no reason you couldn't use any template engine or even NO template engine at all. For example, a view object that simply emits text or maybe generates a chart.

Send to a friend

[add]
Please enter code (Change Code)

Sending Message.