Skip to content
This repository
Browse code

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

…nor cleanups
  • Loading branch information...
commit 3542fe05563f374ac84fa187c9472e8ce9f85a30 1 parent 5a5719a
Johan Viklund authored
8 lib/Dispatcher.pm
@@ -15,8 +15,6 @@ class Dispatcher {
15 15 }
16 16
17 17 multi method add (@rules) {
18   - # RAKUDO: "Return" values of for loop statements
19   - my $r;
20 18 # The following line of code is in relatively high flux, due to
21 19 # changes in the Spec and Rakudo when it comes to handling of
22 20 # typed arrays etc. For a long time, it said 'Object @pattern',
@@ -27,9 +25,9 @@ class Dispatcher {
27 25 # versions of Rakudo, writing 'Object @pattern' wrongly causes
28 26 # the Array not to bind, despite the fact that any Array should.
29 27 for @rules -> @pattern, $action {
30   - $r = self.add(@pattern, $action);
  28 + self.add(@pattern, $action);
31 29 }
32   - return $r;
  30 + return @.rules.elems;
33 31 }
34 32
35 33 method dispatch (@chunks) {
@@ -41,7 +39,7 @@ class Dispatcher {
41 39 return $result;
42 40 }
43 41 elsif defined $.default {
44   - $.default();
  42 + $.default().();
45 43 }
46 44 else {
47 45 return Failure;
11 lib/November.pm
@@ -29,7 +29,7 @@ class November does Session does Cache {
29 29 method handle_request(CGI $cgi) {
30 30 $!cgi = $cgi;
31 31
32   - my $d = Dispatcher.new( default => { self.not_found } );
  32 + my $d = Dispatcher.new( default => { self.error_page } );
33 33
34 34 $d.add: [
35 35 [''], { self.view_page },
@@ -133,13 +133,6 @@ class November does Session does Cache {
133 133 );
134 134 }
135 135
136   - method check_utf8_error( *@strings ) {
137   - for @strings.split("") -> $c {
138   - return False if ord($c) > 127;
139   - }
140   - return True;
141   - }
142   -
143 136 method logged_in() {
144 137 my $sessions = self.read_sessions();
145 138 my $session_id = $.cgi.cookie<session_id>;
@@ -214,7 +207,7 @@ class November does Session does Cache {
214 207 self.response('logout_succeeded.tmpl');
215 208 }
216 209
217   - method error_page($message = "Generic Error Message") {
  210 + method error_page($message = "You have commited a deadly URL") {
218 211 self.response( 'error.tmpl', { MESSAGE => $message } );
219 212 }
220 213
10 t/dispatcher/01-basics.t
... ... @@ -1,7 +1,7 @@
1 1 use v6;
2 2
3 3 use Test;
4   -plan 8;
  4 +plan 9;
5 5
6 6 use Dispatcher;
7 7 ok(1,'We use Dispatcher and we are still alive');
@@ -37,7 +37,13 @@ $d.default = { "Woow" };
37 37
38 38 is( $d.dispatch(['foo', 'bar', 'baz']),
39 39 "Woow",
40   - 'Dispatch to default, when have no matched Rule'
  40 + 'Dispatch to default, when there\'s no matched Rule'
41 41 );
42 42
  43 +$d = Dispatcher.new( default => { "Woow" } );
  44 +
  45 +is( $d.dispatch(['foo', 'bar', 'baz']),
  46 + "Woow",
  47 + 'Dispatch to default created on init, when there\'s no matched Rule'
  48 +);
43 49 # vim:ft=perl6

0 comments on commit 3542fe0

Johan Viklund

This is what makes the errormessage show

Please sign in to comment.
Something went wrong with that request. Please try again.