Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

It Works! there are a few issues in rakudo yet...

  • Loading branch information...
commit 14007bce970b6a4c304bf72ca88866432db3dacd 1 parent 14156c0
@ruoso authored
View
13 example.pl
@@ -15,7 +15,6 @@
:controller($ctrl),
:private-name('(root)'),
:base('/'),
- :regex(/ \/ /),
:begin-closure({ say "root - begin" }),
:execute-closure({ say "root - execute " }),
:end-closure({ say "root - end" }) );
@@ -24,7 +23,7 @@
my $blog = Faz::Action::Chained.new( :parent($root),
:controller($ctrl),
:private-name('(root)/blog/*'),
- :regex(/ blog\/(\w+) /),
+ :regex(/ blog\/(\w+)\/ /),
:begin-closure(-> $name { say "blog $name - begin " }),
:execute-closure(-> $name { say "blog $name - execute " }),
:end-closure(-> $name { say "blog $name - end" }) );
@@ -33,13 +32,13 @@
my $viewblog = Faz::Action::Public.new( :parent($blog),
:controller($ctrl),
:private-name('(root)/blog/*/'),
- :regex(/ \/? /),
- :begin-closure({ say "viewblog - begin" }),
- :execute-closure({ say "viewblog - execute" }),
- :end-closure({ say "viewblog - end" }) );
+ :regex(/ (\w+) \/? /),
+ :begin-closure( -> $name { say "viewblog $name - begin" }),
+ :execute-closure( -> $name { say "viewblog $name - execute" }),
+ :end-closure(-> $name { say "viewblog $name - end" }) );
$app.register-action($viewblog);
-my $uri = Faz::URI.new(:path('/blog/faz'));
+my $uri = Faz::URI.new(:path('/blog/faz/bla'));
my $request is context = Faz::Request.new(:uri($uri));
my $response is context = 1;
$app.handle($request,$response);
View
13 lib/Faz/Action/Chained.pm
@@ -7,7 +7,7 @@ class Faz::Action::Chained does Faz::Action {
has Callable $.execute-closure;
has Callable $.end-closure;
- multi method begin(*@_, :$parent_action_capture, *%_) {
+ multi method begin(*@p, :$parent_action_capture, *%n) {
if $.parent {
my %named;
my @pos;
@@ -15,16 +15,15 @@ class Faz::Action::Chained does Faz::Action {
%named := %($parent_action_capture<action_capture>);
@pos := @($parent_action_capture<action_capture>);
%named<parent_action_capture> = $parent_action_capture<parent_action_capture>;
- say 'named arguments are: ' ~ named;
}
$.parent.*begin(|@pos, |%named);
}
if $.begin-closure {
- $.begin-closure.(|@_, |%_)
+ $.begin-closure.(|@p, |%n)
}
}
- multi method execute(*@_, :$parent_action_capture, *%_) {
+ multi method execute(*@p, :$parent_action_capture, *%n) {
if $.parent {
my %named;
my @pos;
@@ -36,13 +35,13 @@ class Faz::Action::Chained does Faz::Action {
$.parent.*execute(|%named, |@pos);
}
if $.execute-closure {
- $.execute-closure.(|@_, |%_)
+ $.execute-closure.(|@p, |%n)
}
}
- multi method end(*@_, :$parent_action_capture, *%_) {
+ multi method end(*@p, :$parent_action_capture, *%n) {
if $.end-closure {
- $.end-closure.(|@_, |%_)
+ $.end-closure.(|@p, |%n)
}
if $.parent {
my %named;
View
5 lib/Faz/Action/Root.pm
@@ -2,4 +2,9 @@
use Faz::Action::Chained;
class Faz::Action::Root is Faz::Action::Chained {
has $.base;
+ method regex {
+# rakudo doesnt allow that yet
+# /^ $.base /;
+ /^ \/ /;
+ }
}
View
16 lib/Faz/Dispatcher.pm
@@ -58,11 +58,10 @@ role Faz::Dispatcher {
self.compile;
# rakudo does not support contextual variables yet
# if $*request.uri.path ~~ $!regex {
- if '/blog/faz' ~~ $!regex {
+ if '/blog/faz/bla' ~~ $!regex {
my %named = %($<subrx><action_capture>);
my @pos = @($<subrx><action_capture>);
%named<parent_action_capture> = $<subrx><parent_action_capture>;
- say 'named arguments are: ' ~ %named.perl;
self.run-action($<subrx>.ast, |@pos, |%named );
} else {
say 'failed';
@@ -70,24 +69,23 @@ role Faz::Dispatcher {
}
}
- method run-action($action is context, *@_, *%_) {
+ method run-action($action is context, *@pos, *%named) {
my $errors is context<rw>;
- try {
- say 'named arguments are: ' ~ %_.perl;
- say 'positionals are: ' ~ @_.perl;
- $action.*begin(|@_, |%_);
- $action.*execute(|@_, |%_);
+ {
+ $action.*begin(|@pos, |%named);
+ $action.*execute(|@pos, |%named);
CATCH {
say $!;
$errors = $! if $!;
}
}
- $action.*end(|@_, |%_);
+ $action.*end(|@pos, |%named);
# we don't know how to handle control exceptions yet.
# CONTROL {
# when Faz::ControlExceptionDetach {
# self.run-action(%!actions{$_.path}, |$_.capture);
# }
# }
+ 1;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.