Skip to content
Browse files

use syntax support;

  • Loading branch information...
1 parent f9cc58d commit bbc8448b1458cdd607ffe312742c8ce1461775ca @jjn1056 committed
Showing with 119 additions and 5 deletions.
  1. +4 −0 dist.ini
  2. +4 −3 lib/CatalystX/Syntax/Action.pm
  3. +76 −0 lib/Syntax/Feature/CatalystAction.pm
  4. +4 −0 t/basic.t
  5. +26 −0 t/lib/TestApp/Controller/Syntax.pm
  6. +5 −2 t/use.t
View
4 dist.ini
@@ -10,11 +10,15 @@ version = 0.01
[Prereqs]
Devel::Declare = 0.006004
parent = 0.225
+B::Hooks::EndOfScope = 0.09
+Carp = 0
[Prereqs / TestRequires]
Moose = 2.0007
Test::More = 0.98
Catalyst::Runtime = 5.80
namespace::autoclean = 0.12
+syntax = 0.003
HTTP::Request::Common = 0
FindBin = 0
+
View
7 lib/CatalystX/Syntax/Action.pm
@@ -42,20 +42,21 @@ sub parse_proto {
=head1 NAME
-CatalystX::Syntax::Action - Semantically meaningfull Catalyst Actions with signatures
+CatalystX::Syntax::Action - Semantically meaningful Catalyst Actions with signatures
=head1 SYNOPSIS
package MyApp::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) = @_;"
+ $ctx->response->body('Look ma, no "my ($self, $ctx, $arg) = @_;"
}
__PACKAGE__->meta->make_immutable;
@@ -108,7 +109,7 @@ would allow you to easily and cleanly enable multiple extenstions. For example:
package MyApp::Web::Controller::Root;
use Moose;
- use syntax 'method', 'action';
+ use syntax 'method', 'catalyst_action';
extends 'Catalyst::Controller'l
View
76 lib/Syntax/Feature/CatalystAction.pm
@@ -0,0 +1,76 @@
+package Syntax::Feature::CatalystAction;
+
+use strict;
+use warnings FATAL =>'all';
+
+use CatalystX::Syntax::Action ();
+use B::Hooks::EndOfScope;
+use Carp ();
+use namespace::clean;
+
+$Carp::Internal{ +__PACKAGE__ }++;
+
+sub install {
+ my ($class, %args) = @_;
+ my $target = $args{into};
+ my $name = $args{options}{ -as } || 'action';
+ my $invocant = $args{options}{ -invocant } || '$self';
+
+ CatalystX::Syntax::Action->import(
+ into => $target,
+ name => $name,
+ invocant => $invocant,
+ );
+
+ on_scope_end {
+ namespace::clean->clean_subroutines($target, $name);
+ };
+
+ return 1;
+}
+
+1;
+
+=head1 NAME
+
+Syntax::Feature::CatalystAction - Provide an action keyword to Catalyst Controllers
+
+
+=head1 SYNOPSIS
+
+ package MyApp::Controller::Foo;
+
+ use Moose;
+ use namespace::autoclean;
+ use syntax 'catalyst_action';
+
+ 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;
+
+=head1 DESCRIPTION
+
+This module is a L<syntax> compatible wrapper for L<CatalystX::Syntax::Action>.
+Please see that module for documentation and examples.
+
+=head1 AUTHOR
+
+John Napiorkowski L<email:jjnapiork@cpan.org>
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Syntax::Feature::Method>, L<syntax>, L<Devel::Declare>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2011, John Napiorkowski L<email:jjnapiork@cpan.org>
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
View
4 t/basic.t
@@ -14,4 +14,8 @@ is request(GET '/root')->content, 'root_0';
is request(GET '/root/100')->content, 'root_1';
is request(GET '/root/foo/100')->content, 'root_foo_1';
+is request(GET '/syntax')->content, 'syntax_root_0';
+is request(GET '/syntax/100')->content, 'syntax_root_1';
+is request(GET '/syntax/foo/100')->content, 'syntax_root_foo_1';
+
done_testing;
View
26 t/lib/TestApp/Controller/Syntax.pm
@@ -0,0 +1,26 @@
+package TestApp::Controller::Syntax;
+
+use Moose;
+use namespace::autoclean;
+use syntax 'catalyst_action';
+
+BEGIN {
+ extends 'Catalyst::Controller';
+}
+
+action root : Chained('/') PathPrefix CaptureArgs(0) {}
+
+ action root_0 : Chained('root') PathPart('') Args(0) {
+ $ctx->response->body('syntax_root_0');
+ }
+
+ action root_1 : Chained('root') PathPart('') Args(1) {
+ $ctx->response->body('syntax_root_1');
+ }
+
+ action root_foo_1 : Chained('root') PathPart('foo') Args(1) {
+ $ctx->response->body('syntax_root_foo_1');
+ }
+
+__PACKAGE__->meta->make_immutable;
+
View
7 t/use.t
@@ -1,5 +1,8 @@
use strict;
use warnings FATAL =>'all';
-use Test::More tests => 1;
+use Test::More tests => 2;
-BEGIN { use_ok 'CatalystX::Syntax::Action' }
+BEGIN {
+ use_ok 'CatalystX::Syntax::Action';
+ use_ok 'Syntax::Feature::CatalystAction';
+}

0 comments on commit bbc8448

Please sign in to comment.
Something went wrong with that request. Please try again.