Re: [Maypole] Maypole or Catalyst?

From: Sebastian Riedel (sri at oook.de)
Date: Fri Feb 04 2005 - 07:16:59 GMT


David Naughton:
> One big reason I'm asking has to do with URIs. My wiki supports
> hierarchical namespaces, i.e. /path/to/page. I'm planning to use Maypole
> or Catalyst to do things like /path/to/page/edit, /path/to/page/history,
> etc. where 'edit', 'history', etc. are methods. All pages will be
> handled by a default "wiki page" plugin, but I also want to easily
> override the default with other plugins for arbitrary URIs.

It's a bit unusual scheme, but i guess you've got your reasons...

> Maypole?
>
> Maypole seems to be built around the assumption that URIs will be
> /path/to/some_class/some_method. Is it easy to override that behavior?
> Even if it is, I'm a little uncomfortable with the idea of constantly
> overriding a core feature. Am I right to be concerned about this?

Yes Maypole is bound to it's uri scheme and expects you to rewrite them
in a parse_path() method or to use mod_rewrite...
The nature of Maypole is to expose tables to the web and let the user
call methods on them (whis mostly just works for most kind of webapps).

>
> Catalyst?
>
> It seems that Catalyst may have the flexibility to support my goals
> OOTB.

Definately.

> However, the documentation is so sparse that it's hard to tell.
> Sebastian, can you provide some more complex examples? I'd also love to
> know what features you've stolen from Ruby on Rails, Springs, etc. along
> with some examples of their use.

I've stolen lots of features, and am still stealing every day. ;)
>From RoR i've mostly stolen the overall structure with multiple
controllers, optional scaffolding and automatically loading of
components.

For example a controller class.

    # lib/MyApp/C/Hunter.pm
    package Kobai::C::Hunter;

    use strict;
    use base 'Catalyst::Base';

    Kobai->action(
        '?create' => sub {
            my ( $self, $c ) = @_;
            $c->stash->{template} = 'hunter/create.tt';
            # do stuff
        }
        '?delete' => sub {
            my ( $self, $c ) = @_;
            $c->stash->{template} = 'hunter/delete.tt';
            # do stuff
        }
        'sign-in' => sub {
            my ( $self, $c ) = @_;
            $c->stash->{template} = 'sign-in.tt';
            # do stuff
        }

    );

You just create this file and Catalyst will automatically find and load
it without any configuration.

This class would magically expose /hunter/create, /hunter/delete
and /sign-in. (? is a placeholder for the actual class's moniker)

>From Spring i've mostly just taken ideas on how to apply cool design
pattern like interceptors, decorators and filters.
Which was very simple, thanks to Catalysts easy flow control with
$c->forward().

    Kobai->action(
        '?create' => sub {
            my ( $self, $c ) = @_;
            # This is the entry point /prefix/create
            return unless $c->forward('!check-roles');
            # do stuff
            $c->forward('prefix/send-new-password');
        }
        '!check-roles' => sub {
            my ( $self, $c ) = @_;
            # check the permissions,
            # which are role based in Catalyst
            return 1 if world_is_fine();
            return 0;
        }
        '?send-new-password' => sub {
            my ( $self, $c ) = @_;
            # This action can be used internally and externally!
            $c->stash->{template} ||= 'index.tt';
            # do stuff
        }
        '!end' => sub {
            my ( $self, $c ) = @_;
            # This is a built in private action
            # used to render templates at end of request
            # Automatically called by Catalyst.

            # Set a template if noone else did
            $c->stash->{template} ||= 'index.tt';

            # This will render the template
            $c->forward('Kobai::V::TT');
        }
    );

Not a perfect example but you get the idea. ;)
! indicates private actions, some are built in...

> If either of these projects would meet my needs, I'd be happy to
> contribute whatever I can.

Most of the time i'm hanging around in #maypole on irc.perl.org and am
happy to answer all kind of questions.

I also tend to extend the Catalyst Manual on request. ;)

A Catalyst powered wiki would be a great contribution.
Recipes for the manual would be cool too.

Sad thing is that currently no big examples exist, but note that
Catalyst is just a few weeks old. ;)

I'm actually working on something really big, you'll see soon. =)

You should get in contact with Marcus "draven" Ramberg (also on
#maypole), he recently started porting his Mitiki to Catalyst.

-- 
sebastian

_______________________________________________ maypole mailing list maypole at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:58 GMT