Permalink
Browse files

Clean version! it fails if I try to use Faz::Action::Root...

  • Loading branch information...
1 parent 5b820a8 commit ec2bdf4a481cc4047c95d34da404cfc11ff66e64 @ruoso committed May 14, 2009
Showing with 17 additions and 8 deletions.
  1. +5 −2 examples/yarn/lib/Yarn.pm
  2. +1 −1 lib/Faz/Action/Chained.pm
  3. +1 −0 lib/Faz/Action/Private.pm
  4. +10 −5 lib/Faz/Dispatcher.pm
View
7 examples/yarn/lib/Yarn.pm
@@ -12,8 +12,11 @@ class Yarn is Faz::Application {
method setup {
$.dispatcher = Faz::Dispatcher.new;
- my $root = Faz::Action::Root.new\
- ( :begin-closure({
+ my $root = Faz::Action::Chained.new\
+ ( :parent(False),
+ :regex(/^ /),
+ :private-name('root'),
+ :begin-closure({
%*stash<posts> = 'data/posts' ~~ :f
?? @(eval(slurp('data/posts')))
!! ();
View
2 lib/Faz/Action/Chained.pm
@@ -9,7 +9,7 @@ class Faz::Action::Chained does Faz::Action {
method private-name {
my $name = '';
- if defined $.parent {
+ if $.parent {
$name = $.parent.private-name ~ '/';
}
$name ~= $!private-name;
View
1 lib/Faz/Action/Private.pm
@@ -1,3 +1,4 @@
+use Faz::Action;
class Faz::Action::Private does Faz::Action {
has $.begin-closure;
has $.execute-closure;
View
15 lib/Faz/Dispatcher.pm
@@ -11,17 +11,20 @@ role Faz::Dispatcher {
fail 'Duplicated action'
if %!actions.exists($a.private-name);
%!actions{$a.private-name} = $a;
- @!public = @(grep { $_ ~~ Faz::Action::Public }, %!actions.values).sort: { $_.priority }
+ @!public = @(%!actions.values.grep: { $_ ~~ Faz::Action::Public }).sort: { $_.priority }
}
# this method freezes the regexes, combining them into a single
# regular expression that will evaluate the request and return the
# desired action.
method compile {
+ warn "Registered Actions ({%!actions.keys.elems}):";
+ warn join "\n", %!actions.keys;
+
+ warn "Public Actions ({@!public.elems}):";
+ warn join "\n", map { .private-name }, @!public;
- warn "Public Actions:";
my sub buildspec($act) {
- warn $act.private-name;
my &action_capture = $act.regex;
my &closure = -> $/ {
make $act;
@@ -64,17 +67,19 @@ role Faz::Dispatcher {
self.compile;
}
if $*request.uri.path ~~ $!regex {
+ my $action = $<subrx>.ast;
+ warn "Path '{$*request.uri.path}' matched '{$action.private-name}'";
my %named = %($<subrx><action_capture>);
my @pos = @($<subrx><action_capture>);
%named<parent_action_capture> = $<subrx><parent_action_capture>;
- self.run-action($<subrx>.ast, |@pos, |%named );
+ self.run-action($action, |@pos, |%named );
} else {
warn "No action matched '{$*request.uri.path}'";
1;
}
}
- method run-action($action is context, *@pos, *%named) {
+ method run-action($action, *@pos, *%named) {
$*action = $action;
my $errors is context<rw>;
{

0 comments on commit ec2bdf4

Please sign in to comment.