# parse declarations
until (do { $ctx->skipspace; $ctx->peek_next_char } eq any qw( ; { } )) {
- warn "LINESTR[" . pp($ctx->get_linestr) . "]\n";
$ctx->skipspace;
);
}
- pp \%attributes;
-
AttributeRole->meta->apply($method);
my @attributes = map {
$ctx->set_linestr($linestr);
return $1;
}
- elsif ($rest =~ /^ ' ( (?:[a-z0-9]|\/)* ) ' /ix) {
+ elsif ($rest =~ /^ ' ( (?:[.:;,_a-z0-9]|\/)* ) ' /ix) {
substr($linestr, $ctx->offset, length($1) + 2) = '';
$ctx->set_linestr($linestr);
return $1;
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 7;
+use Catalyst::Test 'TestApp';
+
+# simple stuff
+is get('/foo'), 'Welcome to TestApp!', 'simple root action';
+
+# with arguments
+is get('/foo/with_args/hello/cthulhu'), 'Hello, Cthulhu!', 'simple argument';
+is get('/foo/with_args/at_end/2/3'), 6, 'two arguments at the end';
+is get('/foo/with_args/in_the_middle/3/4/end_of_the_middle'), 24, 'two arguments in the middle';
+is get('/foo/with_args/4/8/fhtagn/15/16/23/42'), '4, 8, 15, 16, 23, 42', 'complex arguments in both';
+
+# under keyword
+is get('/foo/under/23'), 'under 23', 'under as keyword';
+
+# comma separation
+is get('/foo/,comma/iaia'), 'iaia', 'comma separation';
controller TestApp::Controller::Foo {
- has bar => (is => 'rw');
- method baz { }
+ #
+ # look, a Moose!
+ #
- under '/', action base, as '';
+ has title => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'TestApp',
+ );
- action root under base as '' is final { }
- action list under base is final { }
+ #
+ # normal methods are very useful too
+ #
- under base, as 'id', action object ($id) { }
+ method welcome_message { sprintf 'Welcome to %s!', $self->title }
- action view under object is final { $ctx->res->body('Hello World!') }
+ method greet (Str $name) { "Hello, $name!" }
- action edit under object is final { }
- action tag (@tags) under object is final { }
+ #
+ # the simple stuff
+ #
+
+ action base under '/base' as 'foo';
+
+ action root under base as '' is final {
+ $ctx->response->body( $self->welcome_message );
+ }
+
+
+ #
+ # with arguments
+ #
+
+ action with_args under base;
+
+ action hello (Str $name) under with_args is final {
+ $ctx->response->body($self->greet(ucfirst $name));
+ }
+
+ action at_end (Int $x, Int $y) under with_args is final {
+ $ctx->response->body( $x * $y );
+ }
+
+ action in_the_middle (Int $x, Int $y) under with_args {
+ $ctx->stash(result => $x * $y);
+ }
+ action end_of_the_middle under in_the_middle is final {
+ $ctx->response->body($ctx->stash->{result} * 2);
+ }
+
+ action all_the_way (Int $x) under with_args as '' {
+ $ctx->stash(x => $x);
+ }
+ action through_the_sky (Int $y) under all_the_way as '' {
+ $ctx->stash(y => $y);
+ }
+ action and_beyond (@rest) under through_the_sky as fhtagn is final {
+ $ctx->response->body(join ', ',
+ $ctx->stash->{x},
+ $ctx->stash->{y},
+ @rest,
+ );
+ }
+
+
+ #
+ # under is also a valid keyword
+ #
+
+ under base action under_base as under;
+
+ under under_base as '' action even_more_under (Int $i) is final {
+ $ctx->response->body("under $i");
+ }
+
+
+ #
+ # too many words? go comma go!
+ #
+
+ action comma_base, as '', under base;
+
+ under comma_base, is final, action comma ($str), as ',comma' {
+ $ctx->response->body($str);
+ }
+
}