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

sartak at bestpractical.com sartak at bestpractical.com
Tue Nov 18 19:50:20 EST 2008


Author: sartak
Date: Tue Nov 18 19:50:20 2008
New Revision: 16915

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

Log:
 r75781 at onn:  sartak | 2008-11-18 19:50:15 -0500
 First pass at a Metadata matching rule


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	Tue Nov 18 19:50:20 2008
@@ -65,6 +65,7 @@
 require Path::Dispatcher::Rule::Dispatch;
 require Path::Dispatcher::Rule::Empty;
 require Path::Dispatcher::Rule::Intersection;
+require Path::Dispatcher::Rule::Metadata;
 require Path::Dispatcher::Rule::Regex;
 require Path::Dispatcher::Rule::Tokens;
 require Path::Dispatcher::Rule::Under;

Added: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm	Tue Nov 18 19:50:20 2008
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Rule::Metadata;
+use Moose;
+use MooseX::AttributeHelpers;
+extends 'Path::Dispatcher::Rule';
+
+has match_metadata => (
+    metaclass => 'Collection::Hash',
+    is        => 'rw',
+    isa       => 'HashRef',
+    required  => 1,
+    provides  => {
+        keys => 'metadata_keys',
+        get  => 'metadata',
+    },
+);
+
+sub _match {
+    my $self = shift;
+    my $path = shift;
+
+    my $path_metadata = $path->metadata;
+
+    for my $key ($self->metadata_keys) {
+        return 0 if !exists($path_metadata->{$key});
+
+        $self->_match_metadatum($path_metadata, $self->metadata($key))
+            or return 0;
+    }
+
+    return 1, $path->path;
+}
+
+sub _match_metadatum {
+    my $self     = shift;
+    my $got      = shift;
+    my $expected = shift;
+
+    return $got eq $expected;
+}
+
+1;
+



More information about the Bps-public-commit mailing list