A 17-line Wiki

Prerequisites

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 };

In reply to Re^2: Squatting::On::Catalyst and Truly Modular Web Apps by beppu
in thread Squatting::On::Catalyst and Truly Modular Web Apps by beppu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.