[Bps-public-commit] r15108 - in Path-Dispatcher/trunk: lib/Path/Dispatcher/Rule

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 13 05:09:02 EDT 2008


Author: sartak
Date: Wed Aug 13 05:09:01 2008
New Revision: 15108

Added:
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
Modified:
   Path-Dispatcher/trunk/   (props changed)

Log:
 r69450 at onn:  sartak | 2008-08-13 05:07:46 -0400
 Add some Rule subclasses: CodeRef, Regex, Tokens. Regex will probably be subsumed by Tokens


Added: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm	Wed Aug 13 05:09:01 2008
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Rule::CodeRef;
+use Moose;
+extends 'Path::Dispatcher::Rule';
+
+has matcher => (
+    is       => 'ro',
+    isa      => 'CodeRef',
+    required => 1,
+);
+
+sub _match {
+    my $self = shift;
+    local $_ = shift; # path
+
+    return $self->matcher->($_);
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+

Added: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm	Wed Aug 13 05:09:01 2008
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Rule::Regex;
+use Moose;
+extends 'Path::Dispatcher::Rule';
+
+has regex => (
+    is       => 'ro',
+    isa      => 'RegexpRef',
+    required => 1,
+);
+
+sub _match {
+    my $self = shift;
+    my $path = shift;
+
+    return unless $path =~ $self->regex;
+    return [ map { substr($path, $-[$_], $+[$_] - $-[$_]) } 1 .. $#- ];
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+

Added: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm	Wed Aug 13 05:09:01 2008
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Rule::Tokens;
+use Moose;
+extends 'Path::Dispatcher::Rule';
+
+has tokens => (
+    is       => 'ro',
+    isa      => 'ArrayRef[ArrayRef[Str|RegexpRef]]',
+    required => 1,
+);
+
+sub _match {
+    my $self = shift;
+    my $path = shift;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+



More information about the Bps-public-commit mailing list