[cgiapp] Re: RFC: declarative run modes (inspired by Method::Signatures)

Mark Stosberg mark at summersault.com
Tue Sep 23 21:54:38 EDT 2008


> Inspired by Method::Signatures, I've been hacking on something specifically 
> for use with cgiapp.
> 
>    package My::App;
> 
>    use base 'CGI::Application';
>    use Runmode::Declare; # proof-of-concept name
> 
>    startmode hello { "Hello" }
>    runmode world { $self->hello . ", World!" }
> 
> Most of the time, you won't need to call setup() anymore, because this takes 
> care of setting the start/run modes for you.
> Obviously, it checks that you only have one startmode. And it all works fine 
> with inheritance too.
> 
> 
> Using signatures:
> 
>    # script?rm=invite;party_id=42;names=larry;names=guido;names=matz
> 
>    runmode invite($party_id, @names) {
>      my $party = party_from_id($party_id);
>      $party->add_invitees(@names);
>    }
> 
>    # somewhere else:
>    $self->invite( 36, qw(me myself I) );
> 
> This pulls the named parameters from @_, or $self->query->param, or $self->param.
> 
> Is anyone interested in seeing this on CPAN? Or should I just keep this to 
> myself, and report back to the asylum? :-)

I agree this code is attractive and elegant. (And I hope it also provides
"$self" or "$c") to run modes).  I would like to see on CPAN.

But having just looked at the scary guts of Devel::Declare, I don't expect
to use it for real work soon. This just-filed bug report is the kind of thing
I worry about it:

http://rt.cpan.org/Public/Bug/Display.html?id=34417

Devel::Declare just became incompatible with the latest "bleadperl", and
because of the deep C magic, I wouldn't be able to patch it myself, as I would
be for many other CPAN modules I use.

Still, I hope features like this make their way towards stability, and I
applaud and support your efforts to help towards that goal. Plus, it looks fun
to try!

A suggested alternate name:

 CGI::Application::Plugin::RunmodeDeclare;

    Mark

-- 
http://mark.stosberg.com/





More information about the cgiapp mailing list