[Catalyst-commits] r11743 -
Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst
jnapiorkowski at dev.catalyst.perl.org
jnapiorkowski at dev.catalyst.perl.org
Wed Nov 4 20:28:46 GMT 2009
Author: jnapiorkowski
Date: 2009-11-04 20:28:46 +0000 (Wed, 04 Nov 2009)
New Revision: 11743
Modified:
Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Dispatcher.pm
Log:
properly refactored this time (passes all tests)
Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Dispatcher.pm 2009-11-04 19:53:19 UTC (rev 11742)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Dispatcher.pm 2009-11-04 20:28:46 UTC (rev 11743)
@@ -359,9 +359,9 @@
sub prepare_action {
my ( $self, $c ) = @_;
my $req = $c->req;
+ $req->args( \my @args );
my @path = $self->decompose_path_for_prepare_action($c, $req->path);
- my $args = $self->dispatch_against_paths($c, \@path);
- $req->args(@$args);
+ my $args = $self->dispatch_against_paths($c, \@path, \@args);
s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
for grep { defined } @{$req->captures||[]};
@@ -373,11 +373,17 @@
if ( $c->debug && @$args );
}
+=head2 $self->dispatch_against_paths($c, $path, $capture_args?)
+
+Recursive subroutine to see if we can dispatch to a given $path.
+
+=cut
+
sub dispatch_against_paths {
my ($self, $c, $paths, $args) = (@_, []);
my $path = join '/', @$paths;
$path =~ s#^/+##;
- if($self->match_dispatch_types_to_path($c, $path, @{ $self->_dispatch_types })) {
+ if($self->match_dispatch_types_to_path($c, $path, @{ $self->dispatch_types })) {
return $args; ## all done
} else {
# If not, move the last part path to args
@@ -392,6 +398,12 @@
}
}
+=head2 $self->match_dispatch_types_to_path($c, $path, @dispatch_types)
+
+Does a $path dispatch to any of the given dispatch types? (CHECKED)
+
+=cut
+
sub match_dispatch_types_to_path {
my ($self, $c, $path, $dispatch_type, @dispatch_types) = @_;
if(my $match = $self->match_dispatch_type_to_path($c, $path, $dispatch_type)) {
@@ -403,11 +415,24 @@
}
}
+=head2 $self->match_dispatch_type_to_path($c, $path, $dispatch_type)
+
+Does a given $dispatch_type match a given $path? (CHECKED)
+
+=cut
+
sub match_dispatch_type_to_path {
my ($self, $c, $path, $dispatch_type) = @_;
return $dispatch_type->match($c, $path);
}
-
+
+=head2 $self->decompose_path_for_prepare_action($c, $path)
+
+Given a $path, as from the request object, break it up into an array of parts
+used to determine dispatching. (CHECKED)
+
+=cut
+
sub decompose_path_for_prepare_action {
my ($self, $c, $path) = @_;
my @path = (split(/\//, $path));
@@ -415,7 +440,6 @@
return @path;
}
-
=head2 $self->get_action( $action, $namespace )
returns a named action from a given namespace.
More information about the Catalyst-commits
mailing list