[Bps-public-commit] r15445 - in Path-Dispatcher/trunk: lib/Path
sartak at bestpractical.com
sartak at bestpractical.com
Mon Aug 25 16:14:44 EDT 2008
Author: sartak
Date: Mon Aug 25 16:14:42 2008
New Revision: 15445
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Log:
r70301 at onn: sartak | 2008-08-25 15:55:53 -0400
Break up dispatch into a bunch of specialized methods
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm Mon Aug 25 16:14:42 2008
@@ -69,21 +69,13 @@
my $dispatch = $self->dispatch_class->new;
- STAGE:
for my $stage ($self->stages) {
- RULE:
- for my $rule ($stage->rules) {
- my $result = $rule->match($path)
- or next;
-
- $dispatch->add_match(
- stage => $stage,
- rule => $rule,
- result => $result,
- );
-
- return $dispatch if $stage->match_ends_dispatch;
- }
+ my $stop = $self->dispatch_stage(
+ stage => $stage,
+ dispatch => $dispatch,
+ path => $path,
+ );
+ last if $stop;
}
$dispatch->add_redispatch($self->redispatch($path))
@@ -92,6 +84,38 @@
return $dispatch;
}
+sub dispatch_stage {
+ my $self = shift;
+ my %args = @_;
+
+ my $stage = $args{stage};
+
+ for my $rule ($stage->rules) {
+ my $matched = $self->dispatch_rule(
+ %args,
+ rule => $rule,
+ );
+ return 1 if $matched && $stage->match_ends_dispatch;
+ }
+
+ return 0;
+}
+
+sub dispatch_rule {
+ my $self = shift;
+ my %args = @_;
+
+ my $result = $args{rule}->match($args{path})
+ or return 0;
+
+ $args{dispatch}->add_match(
+ %args,
+ result => $result,
+ );
+
+ return 1;
+}
+
sub can_redispatch { shift->has_super_dispatcher }
sub redispatch {
More information about the Bps-public-commit
mailing list