Permalink
Browse files

yarn vrsion working;

  • Loading branch information...
1 parent 6db6cb4 commit 87832e041757572dee24ddfd9e56031f1adfa0a3 @ruoso committed May 13, 2009
Showing with 27 additions and 19 deletions.
  1. +18 −10 examples/yarn/lib/Yarn.pm
  2. +9 −9 examples/yarn/yarn.pl
View
@@ -17,15 +17,21 @@ class Yarn is Faz::Application {
method setup {
$.dispatcher = Faz::Dispatcher.new;
- my $root = Faz::Action::Root.new\
- ( :private-name('(root)'),
+ my $root = Faz::Action::Chained.new\
+ ( :parent(0),
+ :private-name('(root)'),
+ :regex(/ ^ /),
+ :execute-closure({ 1; }),
+ :finish-closure({ 1; }),
:begin-closure({ %*stash<posts> = get-posts() }) );
- $.register-action($root);
+ self.register-action($root);
my $index = Faz::Action::Public.new\
( :private-name('(root)/'),
- :regex(/ $/),
- :chained($root),
+ :regex(/ \/ $ /),
+ :parent($root),
+ :begin-closure({ 1; }),
+ :finish-closure({ 1; }),
:execute-closure({
$*response.write(show {
html {
@@ -45,12 +51,14 @@ class Yarn is Faz::Application {
})
})
);
- $.register-action($index);
+ self.register-action($index);
my $create = Faz::Action::Public.new\
( :private-name('(root)/create'),
- :regex(/ create \/? $/),
- :chained($root),
+ :regex(/ \/create \/? $/),
+ :parent($root),
+ :begin-closure({ 1; }),
+ :finish-closure({ 1; }),
:execute-closure({
when $*request.GET<title> ne '' {
my $p = $*request.GET;
@@ -76,14 +84,14 @@ class Yarn is Faz::Application {
});
})
);
- $.register-action($create);
+ self.register-action($create);
$.dispatcher.compile;
}
method call($env) {
my Web::Request $req .= new($env);
my Web::Response $res .= new;
- $.handle($req, $res);
+ self.handle($req, $res);
$res.finish();
}
}
View
@@ -1,30 +1,30 @@
use v6;
use HTTP::Daemon;
use Yarn;
-defined @*ARGS[0] && @*ARGS[0] eq '--request' ?? request() !! daemon();
my $yarn = Yarn.new;
$yarn.setup;
+defined @*ARGS[0] && @*ARGS[0] eq '--request' ?? request() !! daemon();
+
+
# Serve one page
sub request($c) {
my $r = $c.get_request;
warn "{hhmm} {$r.req_method} {$r.url.path} {$r.header('User-Agent')}";
if $r.req_method eq 'GET' {
- my $qs = $r.url.path ~~ / '?' (.*) $/
- ?? ~$0
- !! '';
+ $r.url.path ~~ /^ (<-[?]>*) [ '?' (.*) ]? $/;
$c.send_response(
- ~([~] $yarn.call({"QUERY_STRING" => $qs}).[2])
+ ~([~] $yarn.call({"QUERY_STRING" => $/[1],
+ "SCRIPT_NAME" => $/[0]}).[2])
);
}
elsif $r.req_method eq 'POST' {
- my $qs = $r.url.path ~~ / '?' (.*) $/
- ?? ~$0
- !! '';
+ $r.url.path ~~ /^ (<-[?]>*) [ '?' (.*) ]? $/;
$c.send_response(
~([~] $yarn.call({"REQUEST_METHOD" => 'POST',
- "QUERY_STRING" => $qs}).[2])
+ "QUERY_STRING" => $/[1],
+ "SCRIPT_NAME" => $/[0]}).[2])
);
}
else {

0 comments on commit 87832e0

Please sign in to comment.