- Added a bunch of comments to new dispatcher code
Matt S Trout [Sat, 22 Oct 2005 05:18:08 +0000 (05:18 +0000)]
lib/Catalyst/DispatchType/Default.pm
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/DispatchType/Regex.pm
lib/Catalyst/Dispatcher.pm

index 4825647..1c0d5bf 100644 (file)
@@ -7,12 +7,15 @@ sub prepare_action {
     my ($self, $c, $path) = @_;
     return if $path =~ m!/!; # Not at root yet, wait for it ...
     my $result = @{$c->get_action('default', $c->req->path, 1) || []}[-1];
+        # Find default on namespace or super
     if ($result) {
         $c->action( $result->[0] );
         $c->namespace( $c->req->path );
         $c->req->action('default');
         $c->req->match('');
+        return 1;
     }
+    return 0;
 }
 
 1;
index f51387c..7f291db 100644 (file)
@@ -19,21 +19,24 @@ sub prepare_action {
 
 sub register_action {
     my ( $self, $c, $action ) = @_;
+
     my $attrs = $action->attributes;
     my @register;
+
     foreach my $r (@{$attrs->{Path} || []}) {
-        unless ($r =~ m!^/!) {
+        unless ($r =~ m!^/!) {    # It's a relative path
             $r = $action->prefix."/$r";
         }
         push(@register, $r);
     }
 
     if ($attrs->{Global} || $attrs->{Absolute}) {
-        push(@register, $action->name);
+        push(@register, $action->name); # Register sub name against root
     }
 
     if ($attrs->{Local} || $attrs->{Relative}) {
         push(@register, join('/', $action->prefix, $action->name));
+            # Register sub name as a relative path
     }
 
     foreach my $r (@register) {
index 8f99f75..0d639b1 100644 (file)
@@ -7,6 +7,7 @@ sub prepare_action {
     my ($self, $c, $path) = @_;
 
     return if $self->SUPER::prepare_action($c, $path);
+        # Check path against plain text first
 
     foreach my $compiled (@{$self->{compiled}||[]}) {
         if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
@@ -27,8 +28,8 @@ sub register_action {
     my $attrs = $action->attributes;
     my @register = map { @{$_ || []} } @{$attrs}{'Regex', 'Regexp'};
     foreach my $r (@register) {
-        $self->{paths}{$r} = $action;
-        push(@{$self->{compiled}},
+        $self->{paths}{$r} = $action; # Register path for superclass
+        push(@{$self->{compiled}},    # and compiled regex for us
             {
                 re => qr#$r#,
                 action => $action,
index e129748..32a60a0 100644 (file)
@@ -221,10 +221,15 @@ sub prepare_action {
   DESCEND: while (@path) {
         $path = join '/', @path;
 
+        # Check out dispatch types to see if any will handle the path at
+        # this level
+
         foreach my $type (@{$self->dispatch_types}) {
             last DESCEND if $type->prepare_action($c, $path);
         }
 
+        # If not, move the last part path to args
+
         unshift @args, pop @path;
     }
 
@@ -312,6 +317,9 @@ sub set_action {
     my %attributes;
 
     for my $attr ( @{$attrs} ) {
+
+        # Parse out :Foo(bar) into Foo => bar etc (and arrayify)
+
         if ( my ($key, $value) = ($attr =~ /^(.*?)(?:\(\s*(.+)\s*\))?$/) ) {
             if ( defined $value ) {
                 ($value =~ s/^'(.*)'$/$1/) || ($value =~ s/^"(.*)"/$1/);
@@ -371,6 +379,7 @@ sub set_action {
     # Set the method value
     $parent->getNodeValue->actions->{$method} = $action;
 
+    # Pass the action to our dispatch types so they can register it if reqd.
     foreach my $type ( @{ $self->dispatch_types } ) {
         $type->register_action($c, $action);
     }