John Napiorkowski > CatalystX-Syntax-Action-0.01 > CatalystX::Syntax::Action

Download:
CatalystX-Syntax-Action-0.01.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

CatalystX::Syntax::Action - Semantically meaningful Catalyst Actions with signatures

SYNOPSIS ^

    package MyApp::Web::Controller::Foo;

    use Moose;
    use CatalystX::Syntax::Action;
    use namespace::autoclean;

    extends 'Catalyst::Controller';

    action my_action($arg) : Path('my_special_action') Args(1)
    {
      $ctx->response->body('Look ma, no "my ($self, $ctx, $arg) = @_;"
    }

    __PACKAGE__->meta->make_immutable;

DESCRIPTION ^

This module uses a bit of lightweight Devel::Declare magic to add a new keyword into your Catalyst::Controller called action. It works just like Method::Signatures::Simple, except it also shifts off the context argument, saving you a bit of boilerplate. Additionally you might find that calling an action 'action' more meaningfully separates it visually from methods in your Catalyst::Controller that are normal methods.

On the other hand, it might break some IDE highlighting and so forth. Buyer beware.

The test suite has a working example of this for your review.

CAVEATS ^

When using Moose style method modifiers you'll need to drop back to using 'classic' Perl subroutine syntax, or something like Function::Parameters since method modifiers change the incoming arguments. So for example:

    action myaction :path('foo') Args(1) { ... }

Would need to be modified (as say in a ControllerRole) using:

    use Moose::Role;

    around 'myaction', sub {
      my ($orig, $self, $ctx, @args) = @_;
      ...
    };

This is because we can't detect the fact that $orig as the first argument is a coderef to the modified method rather than a blessed reference to an instance of Catalyst::Controller. If you are attached to the method signatures in your code you could use Function::Parameters:

    use Moose::Role;
    use Function::Parameters;

    around 'myaction', fun($orig, $self, $ctx, @args) {
      ...
    };

use syntax ^

You can use the alternative syntax module to activate this extention. This would allow you to easily and cleanly enable multiple extenstions. For example:

    package MyApp::Web::Controller::Root;

    use Moose;
    use syntax 'method', 'catalyst_action';

    extends 'Catalyst::Controller';

    action myaction { ... }
    method mymethod { ...}

    __PACKAGE__->meta->make_immutable;

THANKS ^

I basically just copied the known working code in Method::Signatures::Simple to make this. I also pretty much copied Syntax::Feature::Method. My thanks to the authors and maintainers of those modules. I wouldn't have such a decent low version offering without that stuff to guide me.

AUTHOR ^

John Napiorkowski email:jjnapiork@cpan.org

SEE ALSO ^

Catalyst, Method::Signatures::Simple, syntax, Devel::Declare, Syntax::Feature::Method.

COPYRIGHT & LICENSE ^

Copyright 2011, John Napiorkowski email:jjnapiork@cpan.org

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: