Permalink
Browse files

Calling blocks stored on instance vars is now $.var().(). And some mi…

…nor cleanups
  • Loading branch information...
1 parent 5a5719a commit 3542fe05563f374ac84fa187c9472e8ce9f85a30 @viklund committed Jun 9, 2009
Showing with 13 additions and 16 deletions.
  1. +3 −5 lib/Dispatcher.pm
  2. +2 −9 lib/November.pm
  3. +8 −2 t/dispatcher/01-basics.t
View
8 lib/Dispatcher.pm
@@ -15,8 +15,6 @@ class Dispatcher {
}
multi method add (@rules) {
- # RAKUDO: "Return" values of for loop statements
- my $r;
# The following line of code is in relatively high flux, due to
# changes in the Spec and Rakudo when it comes to handling of
# typed arrays etc. For a long time, it said 'Object @pattern',
@@ -27,9 +25,9 @@ class Dispatcher {
# versions of Rakudo, writing 'Object @pattern' wrongly causes
# the Array not to bind, despite the fact that any Array should.
for @rules -> @pattern, $action {
- $r = self.add(@pattern, $action);
+ self.add(@pattern, $action);
}
- return $r;
+ return @.rules.elems;
}
method dispatch (@chunks) {
@@ -41,7 +39,7 @@ class Dispatcher {
return $result;
}
elsif defined $.default {
- $.default();
+ $.default().();
@viklund
Owner
viklund added a line comment Jun 9, 2009

This is what makes the errormessage show

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
else {
return Failure;
View
11 lib/November.pm
@@ -29,7 +29,7 @@ class November does Session does Cache {
method handle_request(CGI $cgi) {
$!cgi = $cgi;
- my $d = Dispatcher.new( default => { self.not_found } );
+ my $d = Dispatcher.new( default => { self.error_page } );
$d.add: [
[''], { self.view_page },
@@ -133,13 +133,6 @@ class November does Session does Cache {
);
}
- method check_utf8_error( *@strings ) {
- for @strings.split("") -> $c {
- return False if ord($c) > 127;
- }
- return True;
- }
-
method logged_in() {
my $sessions = self.read_sessions();
my $session_id = $.cgi.cookie<session_id>;
@@ -214,7 +207,7 @@ class November does Session does Cache {
self.response('logout_succeeded.tmpl');
}
- method error_page($message = "Generic Error Message") {
+ method error_page($message = "You have commited a deadly URL") {
self.response( 'error.tmpl', { MESSAGE => $message } );
}
View
10 t/dispatcher/01-basics.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 8;
+plan 9;
use Dispatcher;
ok(1,'We use Dispatcher and we are still alive');
@@ -37,7 +37,13 @@ $d.default = { "Woow" };
is( $d.dispatch(['foo', 'bar', 'baz']),
"Woow",
- 'Dispatch to default, when have no matched Rule'
+ 'Dispatch to default, when there\'s no matched Rule'
);
+$d = Dispatcher.new( default => { "Woow" } );
+
+is( $d.dispatch(['foo', 'bar', 'baz']),
+ "Woow",
+ 'Dispatch to default created on init, when there\'s no matched Rule'
+);
# vim:ft=perl6

0 comments on commit 3542fe0

Please sign in to comment.