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