About code generators

| No TrackBacks
Today someone on IRC brought up a good point, the code currently generated by Mojolicious helpers demonstrates just features and not best practices.
# This is a templateless action
sub test {
    my ($self, $c) = @_;

    # Response object
    my $res = $c->res;

    # Code
    $res->code(200);

    # Headers
    $res->headers->content_type('text/html');

    # Content
    my $url = $c->url_for;
    $url->path->parse('/index.html');
    $res->body(qq/<a href="$url">Forward to a static document.<\/a>/);
}
This snippet generated by Mojolicious::Script::Generate::App shows the possibilities of manipulating the response object directly, in a way nobody would ever do in a real application.
I never thought about the possibility of people misinterpreting the example as "the right way" to do something.

Maybe it's a good idea to keep misleading examples like this one buried in a manual, even though people won't be able to see the full potential of the API at first glance.
For the next release i might try a new example app using only best practices and see how it works out.

No TrackBacks

TrackBack URL: http://labs.kraih.com/cgi-bin/mt-tb.cgi/7