Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moving onward... getting weirdness

  • Loading branch information...
commit 14156c09b204235903478567fa06f10b8b17fd51 1 parent d6326a5
@ruoso authored
Showing with 73 additions and 40 deletions.
  1. +3 −3 example.pl
  2. +43 −15 lib/Faz/Action/Chained.pm
  3. +27 −22 lib/Faz/Dispatcher.pm
View
6 example.pl
@@ -25,9 +25,9 @@
:controller($ctrl),
:private-name('(root)/blog/*'),
:regex(/ blog\/(\w+) /),
- :begin-closure({ say "blog - begin" }),
- :execute-closure(-> $name { say "blog($name) - execute " }),
- :end-closure({ say "blog - end" }) );
+ :begin-closure(-> $name { say "blog $name - begin " }),
+ :execute-closure(-> $name { say "blog $name - execute " }),
+ :end-closure(-> $name { say "blog $name - end" }) );
$app.register-action($blog);
my $viewblog = Faz::Action::Public.new( :parent($blog),
View
58 lib/Faz/Action/Chained.pm
@@ -7,24 +7,52 @@ class Faz::Action::Chained does Faz::Action {
has Callable $.execute-closure;
has Callable $.end-closure;
- multi method begin {
- $.parent.*begin
- if $.parent;
- $.begin-closure.(self)
- if $.begin-closure;
+ multi method begin(*@_, :$parent_action_capture, *%_) {
+ if $.parent {
+ my %named;
+ my @pos;
+ if $parent_action_capture {
+ %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.(|@_, |%_)
+ }
}
- multi method execute(*@_, :$_parent_action_capture, *%_) {
- $.parent.*execute(|$_parent_action_capture);
- if $.parent;
- $.execute-closure.(self, |@_, |%_)
- if $.execute-closure;
+ multi method execute(*@_, :$parent_action_capture, *%_) {
+ if $.parent {
+ my %named;
+ my @pos;
+ if $parent_action_capture {
+ %named := %($parent_action_capture<action_capture>);
+ @pos := @($parent_action_capture<action_capture>);
+ %named<parent_action_capture> = $parent_action_capture<parent_action_capture>;
+ }
+ $.parent.*execute(|%named, |@pos);
+ }
+ if $.execute-closure {
+ $.execute-closure.(|@_, |%_)
+ }
}
- multi method end {
- $.parent.*end
- if $.parent;
- $.end-closure.(self)
- if $.end-closure;
+ multi method end(*@_, :$parent_action_capture, *%_) {
+ if $.end-closure {
+ $.end-closure.(|@_, |%_)
+ }
+ if $.parent {
+ my %named;
+ my @pos;
+ if $parent_action_capture {
+ %named := %($parent_action_capture<action_capture>);
+ @pos := @($parent_action_capture<action_capture>);
+ %named<parent_action_capture> = $parent_action_capture<parent_action_capture>;
+ }
+ $.parent.*end(|%named, |@pos);
+ }
}
}
View
49 lib/Faz/Dispatcher.pm
@@ -22,21 +22,25 @@ role Faz::Dispatcher {
method compile {
my sub buildspec($act) {
- my &rx = $act.regex;
- my &closure = -> $/ { make $act; my $in = $/.new($/); $in.to = $in.from; $in };
+ my &action_capture = $act.regex;
+ my &closure = -> $/ {
+ make $act;
+ my $in = $/.new($/);
+ $in.to = $in.from; $in;
+ };
if $act.parent {
- my &pr = buildspec($act.parent);
- return token { $<actcap> = ( $<_parent_action_capture> = <pr> <rx> ) <closure> };
+ my &parent_action_capture = buildspec($act.parent);
+ return token { <parent_action_capture> <action_capture> <?closure> };
} else {
- return token { $<actcap> = <rx> <closure> };
+ return token { <action_capture> <?closure> };
}
}
my @subregexes = map { buildspec($_) }, @!public;
- my sub subrx ($/) {
- for @subregexes -> &subrx {
- my $result = subrx($/);
+ my &subrx = sub ($/) {
+ for @subregexes -> &eachrx {
+ my $result = eachrx($/);
if $result {
return $result;
};
@@ -44,7 +48,7 @@ role Faz::Dispatcher {
return Match.new($/);
};
- $!regex = token { ( <subrx> ) };
+ $!regex = token { <subrx> };
# I get a null pmc in isa_pmc() if without this line...
1;
@@ -55,29 +59,30 @@ role Faz::Dispatcher {
# rakudo does not support contextual variables yet
# if $*request.uri.path ~~ $!regex {
if '/blog/faz' ~~ $!regex {
- say $/;
- say $/[0];
- say $/[0].elems;
-# self.run-action($/[0]<?>, |$/[0]<actcap>);
- self.run-action($/[0]<?>);
+ 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';
fail 'No action matched';
}
}
-# method run-action($action, *@_, *%_) {
- method run-action($action) {
- say $action.private-name;
+ method run-action($action is context, *@_, *%_) {
my $errors is context<rw>;
try {
- $action.*begin;
- $action.*execute();
+ say 'named arguments are: ' ~ %_.perl;
+ say 'positionals are: ' ~ @_.perl;
+ $action.*begin(|@_, |%_);
+ $action.*execute(|@_, |%_);
CATCH {
- $_.handled = 1;
- $errors = $_;
+ say $!;
+ $errors = $! if $!;
}
}
- $action.*end;
+ $action.*end(|@_, |%_);
# we don't know how to handle control exceptions yet.
# CONTROL {
# when Faz::ControlExceptionDetach {
Please sign in to comment.
Something went wrong with that request. Please try again.