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

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

by beppu (Hermit)
on Aug 15, 2008 at 02:25 UTC ( [id://704467]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^3: Squatting::On::Catalyst and Truly Modular Web Apps
by awwaiid (Friar) on Aug 15, 2008 at 04:10 UTC
    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 :)
Re^3: Squatting::On::Catalyst and Truly Modular Web Apps
by metaperl (Curate) on Aug 15, 2008 at 14:31 UTC
    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://704467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found