[Bps-public-commit] r14611 - in Path-Dispatcher/trunk: lib/Path
sartak at bestpractical.com
sartak at bestpractical.com
Tue Jul 29 14:42:31 EDT 2008
Author: sartak
Date: Tue Jul 29 14:42:31 2008
New Revision: 14611
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Log:
r67891 at onn: sartak | 2008-07-29 14:42:22 -0400
Flesh out the dispatch code
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm Tue Jul 29 14:42:31 2008
@@ -7,13 +7,14 @@
sub rule_class { 'Path::Dispatcher::Rule' }
-has rules => (
+has _rules => (
metaclass => 'Collection::Array',
is => 'rw',
isa => 'ArrayRef[Path::Dispatcher::Rule]',
default => sub { [] },
provides => {
- push => '_add_rule',
+ push => '_add_rule',
+ elements => 'rules',
},
);
@@ -33,8 +34,34 @@
sub dispatch {
my $self = shift;
+ my $path = shift;
- return sub {};
+ my @rules;
+
+ for my $rule ($self->rules) {
+ if ($rule->matches($path)) {
+ push @rules, $rule;
+ }
+ }
+
+ return $self->build_runner(
+ path => $path,
+ rules => \@rules,
+ );
+}
+
+sub build_runner {
+ my $self = shift;
+ my %args = @_;
+
+ my $path = $args{path};
+ my $rules = $args{rules};
+
+ return sub {
+ for my $rule (@$rules) {
+ $rule->run($path);
+ }
+ };
}
sub run {
More information about the Bps-public-commit
mailing list