views:

910

answers:

8

Hi I'm looking for a Perl RESTful framework that have to :

  • work under apache2/mod_perl2
  • be simple
  • be elegant
  • be light
  • be flexible

Am I just dreaming or can I avoid the 'Roll our own' approach?

What framework would you recommend?

+3  A: 

Catalyst is a MVC framework that you can use to make Restfull services

  • It runs under apache2/mod_perl2
  • It is simple and elegant but IMHO not as much as most of the "new" MVC frameworks
  • Yeah .. it is light.
  • Dont think it is really flexible .. :( ..

EDIT: - The "new" frameworks I said are the ones that have good test frameworks to use (like rails/spring/Seam, with catalyst it is not easy to do tests besides the normal unit tests) and also a lot of developers working to build applications to them (the community around these frameworks are far more active). That's why I dont think Catalyst is really flexible too.

Diego Dias
Thx. What are the "new" MVC frameworks you're referring to?
jeje
I edited the poThink that would be enough to explain
Diego Dias
There's something wrong with your perception of Catalyst then. It's probably the most flexible of all of the various web frameworks out there. And I'm not sure why you think it's hard to test.
singingfish
I dont't think it is hard to test... I just think that the test frameworks you have are far away from a RSpec or even JUnit/Testng.
Diego Dias
Catalyst, and in fact, most of the perl community relies on the ample test frameworks that come from Test::Builder, Test::Harness, and Test::More lineages. For functional testing of websites, there's Test::WWW::Selenium for the Selenium users among us, or for simpler non-ajaxy websites, Test::WWW::Mechaninze. All of these interfaces can then be layered inside an object oriented testing skeleton with classes like Test::Class, a fantastic xunit style testing framework. I'm not exactly sure what testing frameworks you're looking for, or if you're just not familiar with what's out there.
Robert P
I'm not sure why you would not suggest Catalyst, it is very flexable, and with the move to Moose, is getting even more so. With Catalyst you can also build REST services really easily. See: http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.78/lib/Catalyst/Action/REST.pm. As for testing goes, like the rest of Perl there is a lot of testing capabailty build into Catalyst. Take a look at http://search.cpan.org/~flora/Catalyst-Runtime-5.80013/lib/Catalyst/Test.pm and related modules. All in all I would say catalyst is a good choice.
gdey
+1 for Catalyst, but -1 for misplaced comment about flexibility/testability.
RET
I don't think I've ever heard anyone call Catalyst "lightweight" before - even without the addition of Moose, it's long been CPAN's poster child for massive dependency chain horror stories. (And, if someone's complaining about dependency chains in something other than Catalyst, it's probably Moose they're complaining about, so Moosifying Catalyst won't help with that.)
Dave Sherohman
+6  A: 

My favorite Perl web application framework is CGI::Application. It is very lightweight (a single base class that you can inherit from) and does the bare minimum necessary to handle the repetitive tasks of web app programming and otherwise stay out of your way. You can use it in a formal MVC design, or do things more ad hoc if that's what you want.

It has a simple plugin architecture, allowing you to easily add support for Template Toolkit (HTML::Template is supported out of the box) sessions, authentication, JSON, streaming, and so on.

Finally, for creating REST-like friendly URLs, there is the excellent CGI::Application::Dispatch, which gives you a powerful rules-based engine for URL-based dispatch.

Also, despite its name, it works seamlessly under mod_perl 1 and 2.

friedo
+4  A: 

I think you will find that Squatting ticks all those boxes!

I've written quite a few small RESTful apps with it. Its ideally suited for this and its been a pleasure to work with.

Here are some more links:

Here is a simple "hello world!" example:

use strict;
use warnings;

{
  package Simple;
  use base 'Squatting';
}

{ 
  package Simple::Controllers;
  use Squatting ':controllers';

  our @C = (
    C(
      Index => [ '/' ],
      get   => sub { 
        my ($self) = @_;
        my $v = $self->v;
        $v->{hello} = 'Hello World!';
        $self->render( 'hello' );
      },
    ),
  );
}

{
  package Simple::Views;
  use Squatting ':views';
  use HTML::AsSubs;

  our @V = (
    V(  'html',

      layout => sub { 
        my ($self, $v, @yield) = @_;
        html(
          head( title('Simple web app') ),
          body( @yield ),
        )->as_HTML;
      },

      hello => sub {
        my ($self, $v) = @_;
        p( $v->{hello} );
      },
    ),
  );
}

Save above as Simple.pm in relevant place and make sure the following is in your Apache config:

<Perl>
  use Simple 'On::MP20';
  Simple->init
</Perl>

<Location />
  SetHandler perl-script
  PerlHandler Simple->mp20
</Location>

And away you go!

While here I would also give a passing mention to a couple of other frameworks which should fit the bill:

I say "passing mention" because I haven't used either of these and I'm not sure if either work (out of the box) with mod_perl2. Still with PSGI / Plack just around the corner this wouldn't be an issue for too long ;-)

/I3az/

draegtun
+2  A: 

Another to consider would be Mojo/Mojolicious, which looks very promising, but, at the moment, is woefully under-documented. That should be getting fixed within the next month or two, though, and there are several people (other than the author) already using it successfully even without full docs.

Dave Sherohman
+6  A: 

I've used Dancer (github) for some smaller projects of mine. It's very elegant and very easy to get things done quickly with. It was inspired by the Ruby framework Sinatra.

It's as easy as:

#!/usr/bin/env perl
use Dancer;

get '/' => sub {
    'Hello world!'
};

dance;
jeekl
+4  A: 

Dancer is pretty well documented and trustable if you look at the test suite: ~500 tests that cover more than 80% of the source tree.

It's PSGI/Plack compliant and has few dependencies. The version 1.0 should be released very soon (maybe this weekend).

See http://github.com/sukria/Dancer to stay tuned.

sukria
A: 

I finally rolled my own pure mod_perl2 RESTful API dedicated framework: http://code.google.com/p/apache2rest/

Nothing is built-in except the essential. The rest is extensible (or will be). I had a look at all your suggestions, and they all seem to address too many things (DBI management, ORM, template engine, embedded server...).

That's why I wrote this one. I hope you'll find it useful.

jeje
A: 

Sorry about answering a bit late, but I described a REST framework in link text which has worked well for me. It makes adding new resources very simple; I barely have to write more than the resource-specific business logic; the framework takes care of the rest.

DougWebb