PrePAN

Sign in to PrePAN

MVC::Neaf Not Even A (Web) Framework

Good

Synopsis

use strict;
use warnings;
use MVC::Neaf;

my $tpl = '<h1>Hello, [% name %]!</h1>
<form action="GET">
<input name="name">
<input type="submit" value="Change name">
</form>
';

MVC::Neaf->route( "/" => sub {
    my $req = shift;

    return {
        -template => \$tpl,
        -type     => 'text/html',
        name      => $req->param( name => qr/\w+/, "Stranger" ),
    },
});

MVC::Neaf->run;

Description

Neaf [ni:f] stands for Not Even A Framework.

Much like Dancer, it splits an application into a set of handler subroutines associated with URI paths. Unlike Dancer, however, it doesn't export anything (except one tiny auxiliary sub) into the application namespace. Instead, a know-it-all Request object is fed to a handler when serving request, like in object-oriented CGI.pm or Kelp.

The response is expected in the form of unblessed hash reference which is in turn fed to the view object for rendering (Template Toolkit and JSON/JSONP currently supported, also Data::Dumper for debugging). Also the return value may contain some dash-prefixed switches altering the behavior of Neaf itself - awful looking, yet visible and simple way of doing it without going for a more complex structure.

Unlike anything I've seen so far, and much like Perl's own -T switch, it offers no (easy) way to get user inputs without validation, either through regexp, or through a form validator. (Regexp-based one is in stock, Validator::LIVR also supported, more planned).

My not-so-impressive feature list so far:

  • GET, POST, and HEAD requests, query parameters (multivalues not done yet), uploads, cookies, and redirects;
  • Template::Toolkit, JSON::XS view out of the box;
  • Can serve raw generated content (e.g. images) and static files (like css/js);
  • CLI-based debugging that can simulate posts, uploads, cookies etc;
  • Can serve delayed or unspecified length replies, or do custom actions after the request is finished;
  • cookie-based sessions supported (no storage drivers available out of the box yet, though);
  • Form validation and resubmission;
  • Same program can work as a CGI script, PSGI app, or Apache mod_perl handler;
  • Half-decent example directory and 79% overall test coverage.

I mostly wrote it for my own education, and to look at possible ways of amending the hurdles that were plaguing me throughout my last two jobs. Now I'd like to share it, but still in doubt whether CPAN needs another framework.

Comments

The entire class of web application frameworks seems to be in constant evolution. Many of the old stalwarts are no longer seeing any development and so new ones arrive to take their place in the popularity charts. There's no reason why yours shouldn't be added.

Subjectively, I like the sound of what you've done here and would be interested to test it out. No doubt others would too.

The name of the dist seems fine and the idea of starting a dedicated top-level MVC::* space where all these should live does rather appeal.
Thanks for your support! I'll upload then.
Uploaded to CPAN now.

https://metacpan.org/pod/MVC::Neaf

Please sign up to post a review.