using Dancer as WAF ::Utils

after PSGI, CPAN has a lot of parts to build Web Application Framework. It is easy making WAF yourself without uploaded WAF.

I think WAF uploaded on CPAN are just to provide a style.

Catalyst provides router system using method attribute. Web::Simple uses proto. Mojo provides WAF OO, Mojolicious::Lite provides some keyword for routing. Dancer provides many keywords. bla bla...

I didnt like any styles for my current project, but didnot want to make WAF from scratch.

So. now Im trying to use Dancer. I dont need full keywords. but "every feature is from keyword" style means Dancer looks like ::Util modules.

For example, you may use only the Dancer parts you need in this way.

package My::Web;
use strict;
use Dancer qw/:syntax config/;
use Dancer::Config;

sub new {
    my ($class, %args) = @_;
    Dancer::set($_ => $args{$_}) for keys %args; # should set "appdir"
    Dancer::Config->load;
    my $self = $instance = bless { }, $class;
}

sub psgi_app {
    my ($self) = @_;
    for my $map (list $self->config->{routing}) {
        my $class  = load($map->{class});

        Dancer::any($map->{method}, $map->{path} => sub {
            my $controller = $class->new(app => $self);
            my $method     = lc Dancer::request()->method;
            $controller->$method();
        });
    }

    return Dancer->start; # psgi app
}

Of course I know this is not an official. but this work. and shold work.

If you didnt like any styles on CPAN WAF but didnot want to make WAF from scratch, Dancer may be useful as providing WAF parts.

I know that Dancer v2 is in development, I hope v2 is also such a good WAF utility.

Excuse me for poor entry Im in a hurry to go Halloween party :)

Leave a comment

About Naoki Tomita

user-pic A perl programmer who learn ninjutsu at the weekend.