Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Squatting::On::Catalyst and Truly Modular Web Apps

by metaperl (Curate)
on Aug 14, 2008 at 15:32 UTC ( [id://704372]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://704372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found