in reply to Squatting::On::Catalyst and Truly Modular Web Apps

Of course, the real question is: can it do a wiki in 20 lines or less :)

But seriously, is there some sort of shootout where we see how a web framework handles certain application tasks? Implementing petshop was done by Bivio to compare with the Java petshop, but that is a rather large task.

  • Comment on Re: Squatting::On::Catalyst and Truly Modular Web Apps

Replies are listed 'Best First'.
Re^2: Squatting::On::Catalyst and Truly Modular Web Apps
by beppu (Hermit) on Aug 15, 2008 at 02:25 UTC

    A 17-line Wiki

    Prerequisites

    • Squatting
    • Text::Textile
    • IO::All

    Code

    package MicroWiki; use base 'Squatting'; package MicroWiki::Controllers; use Squatting ':controllers'; use IO::All; @C = C( Page => ['/', '/(\w+)', '/(\w+).(edit)' ], get => sub { $_[1] ||= 'Home'; -f $_[1] || 'Edit' > io($_[1]); $x < io +($_[1]); $_[0]->v->{page} = $_[1]; $_[0]->v->{text} = $x; $_[0]->render($_[2] && 'edit' || 'page') }, post => sub { $_[0]->input->{text} > io($_[1]); $_[0]->redirect(R('Page', $_[1])) }) +; package MicroWiki::Views; use Squatting ':views'; use Text::Textile qw(textile); our @V = (V(html, page => sub { '<a href="'.R('Page',$_[1]->{page},'ed +it'). '">edit</a>'.textile($_[1]->{text}) }, edit => sub{sprintf( ' <form method="post" action="%s"><textarea name="text" rows="20">%s</te +xtarea>' .'<input type="submit"/></form>', R('Page', $_[1]->{page}), $_[1]->{text}) })); 1;

    And no line exceeds 78 characters in length. ;-) I can actually shrink this by a few more lines if I tried harder, but I'm satisfied w/ what I have.

    To run this Wiki, put the code in a file called "MicroWiki.pm" and type:

    squatting MicroWiki

    To embed this into a Catalyst app, add the following code to your Catalyst app's Root controller.

    use MicroWiki 'On::Catalyst'; MicroWiki->init; MicroWiki->relocate('/wiki'); sub wiki : Local { MicroWiki->catalyze($_[1]) }

    If you want to replace the (non-existent) layout:

    my $view = $MicroWiki::Views::V[0]; $view->{layout} = sub { my ($self, $v, $content) = @_; # return a string that wraps around $content };
      Runs great right out of the box. I have it up at http://ns4.epfarms.org:4234/ if anyone wants to give it a go. I still vote for optional alternate longer names for C(...) and V(...)... yeah yeah patches welcome :)
      A 17-line Wiki
      sa-weet.